Skip to content

Cannot update the description of sentry spans #5442

Closed
@hachang0a0

Description

@hachang0a0

Problem Statement

Sentry.init({
  dsn: process.env.REACT_APP_SENTRY_DSN,
  environment: process.env.NODE_ENV,
  sampleRate: 0.1,
  //tracesSampleRate: 0.05,
  integrations: [
    new TracingIntegrations.BrowserTracing({
      routingInstrumentation: Sentry.reactRouterV5Instrumentation(history),
      tracingOrigins: [
        REACT_APP_APOLLO_SERVER,
        REACT_APP_SEARCH_API,
        REACT_APP_AUTH_URL,
        REACT_APP_PUBLIC_API,
        /^\//,
      ],
      idleTimeout: 15000,
    }),
  ],
  tracesSampler(samplingContext) {
    console.log('samplingContext: ', samplingContext)
    return 1
  },
  beforeBreadcrumb: (breadcrumb, hint) => {
    const graphQLStringQuery = (hint?.input || [])[1]?.body;
    const graphQLQuery = graphQLStringQuery && JSON.parse(graphQLStringQuery);
    const subUrl =
      graphQLQuery && breadcrumb.data?.url === REACT_APP_APOLLO_SERVER ?
      graphQLQuery.operationName :
      ''

    return {
      ...breadcrumb,
      data: {
        ...breadcrumb.data,
        url: breadcrumb.data?.url + '/' + 'subUrl'
      },
    }
  },
});

For now, I'm using the BrowserTracing instrumentation, it creates a child span for each fetch/xhr request. However, nothing I can do to update the descriptions, URLs of the spans (I'm using apollo client and all the queries' description is the same)

Solution Brainstorm

How about creating a hook to update the spans before adding to the transaction (similar to the beforeBreadcrumb)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions