Skip to content

Apollo client support #3519

Open
Open
@deleonjuan

Description

@deleonjuan

Hey, I'm trying to use traces in a React application using RUM, the problem is that I'm NOT using normal http request with axios or similar, I'm using apollo client, and I take controll over the headers that are being sent.
The problem is that datadogRum cannot add the dd headers automatically, so I want to know if there is a way I can get the spanId and traceId in other way to add them with the rest of my headers

const backendHeadersLink = new ApolloLink((operation, forward) => {
  operation.setContext(({ headers = {} }) => ({
    headers: {
      ...headers,
      ...datadDogHeaders //<- I need to include the hedaers here
      'X-Platform': 'foo',
      'apollographql-client-name': 'bar',
      'apollographql-client-version': process.env.REACT_APP_VERSION,
    },
  }))

  return forward(operation)
})


const backendLink = ApolloLink.from([
  ...
  backendHeadersLink,
  ...
])

const apolloClient = new ApolloClient({
  link: ApolloLink.split(
    (operation) => operation.getContext().clientName === 'client',
    backendLink
  ),
  cache: new InMemoryCache(),
})

how can I do that???

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions