Skip to content

The MessageQueue._publish ends Otel spans more than ones #2110

@0x6368656174

Description

@0x6368656174

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Enable OpenTelemetry by setting enableOpenTelemetryTracing: true in the PubSub constructor
  2. Try to send more than one message at the same time
  3. See messages like Cannot execute the operation on ended Span {traceId: e60f51b12990ebe1359223f4db06b98e, spanId: 01c61e673f5ed52e} and send e60f51b12990ebe1359223f4db06b98e-01c61e673f5ed52e - You can only call end() on a span once. in the console

A clear and concise description of what the bug is, and what you expected to happen.

The OpenTelemetry span could be ended only once. But MessageQueue._publish method could close rpcSpan and message parent spans more than once if it has more than one message to process, because closing spans is implemented in the loop:

messages.forEach(m => {
// We're finished with both the RPC and the whole publish operation,
// so close out all of the related spans.
rpcSpan?.end();
tracing.PubsubEvents.publishEnd(m);
m.parentSpan?.end();

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. **

There are no docs describing OpenTelemetry span.end behaviour. However, you could see that it is forbidden in the Otel source code:
https://github.com/open-telemetry/opentelemetry-js/blob/5333204134f71f42c4612735106f83fa8c691102/packages/opentelemetry-sdk-trace-base/src/Span.ts#L267-L272

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: pubsubIssues related to the googleapis/nodejs-pubsub API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions