-
Notifications
You must be signed in to change notification settings - Fork 233
Description
Please make sure you have searched for information in the following guides.
- Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
- Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
- Check our Troubleshooting guide: https://github.com/googleapis/google-cloud-node/blob/main/docs/troubleshooting.md
- Check our FAQ: https://github.com/googleapis/google-cloud-node/blob/main/docs/faq.md
- Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
- Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
- Check out handwritten samples for many of our APIs: https://github.com/GoogleCloudPlatform/nodejs-docs-samples
A screenshot that you have tested with "Try this API".
https://github.com/user-attachments/assets/a25724ad-c4f0-4894-b2df-212d5b5e23ff
Above repository has detailed steps to reproduce the issue. Below is the screenshot of output indicating multiple messages having same traceId.
Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.
https://github.com/gaurang101197/pubsub-shared-traceid-repro
A step-by-step description of how to reproduce the issue, based on the linked reproduction.
Please follow README of pubsub-shared-traceid-repro repository to reproduce the issue.
A clear and concise description of what the bug is, and what you expected to happen.
Description
When Pub/Sub telemetry is enabled in subscription clien, disabled in publisher client and OpenTelemetry gRPC auto-instrumentation is active, the StreamingPull client call runs under a single active context and the response stream is bound to that context. As a result, every message emitted from the same stream sees the same context.active() trace and Pub/Sub attaches a span with same context to message.parentSpan.
Root-cause hypothesis
- @opentelemetry/instrumentation-grpc bind same context to all messages of same
StreamingPull
stream. - pubsub subscription client uses active context to create span for subscription event if parentSpan is not populated by publisher client, which lead to same context being used to create parentSpan for all messages of single grpc client.
- Reference- https://github.com/googleapis/nodejs-pubsub/blob/e546f2cbeb165f7d7e6602b39478ebd73f89b31d/src/telemetry-tracing.ts#L425C5-L439C6
- In above block, there is bug -
if(context)
will always br true.
Above case lead to all messages from a single StreamingPull stream share the same active context which make all messages sharing same context in parentSpan
field. And all messages processing spans become child span of grpc.google.pubsub.v1.Subscriber/StreamingPull
grpc span.
What I expected
In case of telemetry is disabled on publisher client and enabled on subscription client, each message should have unique traceId.
Probable Solution - Use root context instead of active context when parentSpan is not found in message. https://github.com/googleapis/nodejs-pubsub/blob/e546f2cbeb165f7d7e6602b39478ebd73f89b31d/src/telemetry-tracing.ts#L425C5-L439C6
if (parent) {
return getTracer().startSpan(
name,
{
kind: SpanKind.CONSUMER,
attributes,
},
parent,
);
} else {
return getTracer().startSpan(name, {
kind: SpanKind.CONSUMER,
attributes,
}, ROOT_CONTEXT);
}
A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **
When tracing is not enabled in publisher client, all messages of streamingPull grpc client shares the same parent span. Which lead to all child span of message getting linked to single trace.