Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphqlIntegration does not rename the root span with the operation name in AWS Lambda #15699

Open
3 tasks done
nickygb opened this issue Mar 16, 2025 · 5 comments
Open
3 tasks done
Labels
Package: aws-serverless Issues related to the Sentry AWS Serverless SDK Waiting for: Community

Comments

@nickygb
Copy link

nickygb commented Mar 16, 2025

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/aws-serverless

SDK Version

9.5.0

Framework Version

No response

Link to Sentry event

https://bilderit.sentry.io/traces/trace/dc6845bb99a44bb69609a74dc394258f/?environment=pr1687&node=span-91982ffd2de5504c&node=txn-304389edaa5e4227be7f3f1424d1ac0d&pageEnd&pageStart&project=5263245&source=traces&statsPeriod=1h&table=trace&timestamp=1742149537.396

Reproduction Example/SDK Setup

Sentry.init({
  dsn: 'YOUR_SENTRY_DSN',
  release: 'YOUR_SENTRY_RELEASE',
  environment: 'YOUR_SENTRY_ENVIRONMENT',
  tracesSampleRate: 0.1,
  profilesSampleRate: 0.1,
  maxValueLength: 2000,
  integrations: [
    Sentry.rewriteFramesIntegration({ root: process.cwd() }),
    Sentry.graphqlIntegration({
      ignoreResolveSpans: false,
      useOperationNameForRootSpan: true,
    }),
    Sentry.knexIntegration(),
    Sentry.postgresIntegration(),
    nodeProfilingIntegration(),
  ],
  _experiments: {
    maxSpans: 'YOUR_SENTRY_RELEASE' !== 'prod' ? 10000 : 1000,
  },
});

Steps to Reproduce

I'm using Sentry.graphqlIntegration({ useOperationNameForRootSpan: true }) in an AWS Lambda with Apollo Server. According to the documentation, this should rename the root http.server span with the GraphQL operation name.

// instrumentation.ts

Sentry.init({
  dsn: 'YOUR_SENTRY_DSN',
  release: 'YOUR_SENTRY_RELEASE',
  environment: 'YOUR_SENTRY_ENVIRONMENT',
  tracesSampleRate: 0.1,
  profilesSampleRate: 0.1,
  maxValueLength: 2000,
  integrations: [
    Sentry.rewriteFramesIntegration({ root: process.cwd() }),
    Sentry.graphqlIntegration({
      ignoreResolveSpans: false,
      useOperationNameForRootSpan: true,
    }),
    Sentry.knexIntegration(),
    Sentry.postgresIntegration(),
    nodeProfilingIntegration(),
  ],
  _experiments: {
    maxSpans: 'YOUR_SENTRY_RELEASE' !== 'prod' ? 10000 : 1000,
  },
});

Lambda handler:

import './instrumentation';

export const handleHttp = Sentry.wrapHandler(
  async (event: APIGatewayEvent, context: Context) => {
    const server = await getServer();
    return await server.createHttpHandler({
      cors: {
        origin: '*',
        allowedHeaders: ['sentry-trace', 'baggage'],
        credentials: true,
      },
    })(event, context);
  }
);

The issue is that in AWS Lambda, the root span is not http.server but function.aws.lambda, so graphqlIntegration never renames it.

Expected Result

  • The root span should be http.server and renamed to include the GraphQL operation name (e.g., POST /graphql (query operationName)).

  • The trace should correctly reflect the operation name in the root span, instead of the default lambda function name.

Actual Result

  • There is no op: http.server span, only function.aws.lambda.

  • graphqlIntegration does not rename the root span name with the graphql operation name. The name of the root operation is the name of the Lambda Function.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 16, 2025
@github-actions github-actions bot added the Package: aws-serverless Issues related to the Sentry AWS Serverless SDK label Mar 16, 2025
@andreiborza
Copy link
Member

Hi @nickygb, thanks for filing this.

I'll look into this, but it might take some time to get to it.

@mydea
Copy link
Member

mydea commented Mar 17, 2025

Following up on this, I am not sure if this is working at all 🤔 the graphqlIntegration works based on graphql.execute spans, which I do not see in your tree at all. We do not actually check for the root span type anymore, checking the code (there is just an incorrect leftover comment, as far as I can see).

So your problem has nothing to do with the useOperationNameForRootSpan not working, but with graphql instrumentation not really working.

Could you enable debug: true in your init config and share some logs for a request?

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Mar 17, 2025
@nickygb
Copy link
Author

nickygb commented Mar 17, 2025

Following up on this, I am not sure if this is working at all 🤔 the graphqlIntegration works based on graphql.execute spans, which I do not see in your tree at all. We do not actually check for the root span type anymore, checking the code (there is just an incorrect leftover comment, as far as I can see).

So your problem has nothing to do with the useOperationNameForRootSpan not working, but with graphql instrumentation not really working.

Could you enable debug: true in your init config and share some logs for a request?

Sentry Logger [log]: Flushing client reports based on interval.
Sentry Logger [log]: Flushing outcomes...
Sentry Logger [log]: No outcomes to send
Sentry Logger [log]: [Tracing] Inheriting remote parent's sampled decision for core-service-pr1687-apolloServer: true
Sentry Logger [log]: [Tracing] Starting sampled root span
  op: function.aws.lambda
  name: core-service-pr1687-apolloServer
  ID: 1470cdfdb359b117
  parent ID: 8696a1c137a80095
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for context: true
Sentry Logger [log]: [Tracing] Starting sampled span
  op: graphql
  name: context
  ID: 5e502eaa96995369
  parent ID: 1470cdfdb359b117
  root ID: 1470cdfdb359b117
  root op: function.aws.lambda
  root description: core-service-pr1687-apolloServer
Sentry Logger [warn]: Invalid attribute value set for key: db.system
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for first <my_database>.my_table: true
Sentry Logger [log]: [Tracing] Starting sampled span
  op: < unknown op >
  name: <my_database>.my_table
  ID: 73064d9aa8143491
  parent ID: 1470cdfdb359b117
  root ID: 1470cdfdb359b117
  root op: function.aws.lambda
  root description: core-service-pr1687-apolloServer

Sentry Logger [debug]: @sentry/instrumentation-http http instrumentation for outgoing requests
Sentry Logger [log]: [Tracing] Starting sampled span
  op: < unknown op >
  name: POST
  ID: cfa788ddca703904
  parent ID: 73064d9aa8143491
  root ID: 1470cdfdb359b117
  root op: function.aws.lambda
  root description: core-service-pr1687-apolloServer

Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http https instrumentation outgoingRequest
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http http.ClientRequest return request
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on response()
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on end()
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "POST" with ID cfa788ddca703904
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on request close()
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "my_database.my_table" with ID 73064d9aa8143491
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for graphql.parse: false
Sentry Logger [debug]: Recording is off, propagating context in a non-recording span
Sentry Logger [log]: SpanExporter exported 0 spans, 0 spans are waiting for their parent spans to finish
Sentry Logger [log]: Flushing outcomes...
Sentry Logger [log]: Sending outcomes: [ { reason: 'sample_rate', category: 'transaction', quantity: 1 } ]
Sentry Logger [debug]: @sentry/instrumentation-http http instrumentation for outgoing requests
Sentry Logger [debug]: Instrumentation suppressed, returning Noop Span
Sentry Logger [log]: [Tracing] Not injecting trace data for url because tracing is suppressed.
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http https instrumentation outgoingRequest
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http http.ClientRequest return request

``

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 17, 2025
@mydea
Copy link
Member

mydea commented Mar 18, 2025

Can you also share the logs for startup, including the Sentry.init() stuff? I do not see any graphql spans here, so I would assume this is a general instrumentation problem with apollo server. what package/dependency exactly are you using there?

@andreiborza
Copy link
Member

And is whatever is interacting with graphql bundled into your lambda function? We can't instrument bundled in dependencies.

@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: aws-serverless Issues related to the Sentry AWS Serverless SDK Waiting for: Community
Projects
Status: Waiting for: Community
Development

No branches or pull requests

3 participants