Span.addLink throws when using @vercel/otel due to missing method
Please make sure you have searched for information in the following guides.
- [x] Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
- [x] Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
- [x] Check our Troubleshooting guide: https://github.com/googleapis/google-cloud-node/blob/main/docs/troubleshooting.md
- [x] Check our FAQ: https://github.com/googleapis/google-cloud-node/blob/main/docs/faq.md
- [x] Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
- [x] Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
- [x] 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".
N/A
Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.
https://github.com/nicole0707/otel-addlink-compat-repro
A step-by-step description of how to reproduce the issue, based on the linked reproduction.
- npm install
- npm start
A clear and concise description of what the bug is, and what you expected to happen.
When using @vercel/otel for OpenTelemetry initialization, spans do not support the .addLink() method.
In the PubsubSpans.createPublishRpcSpan() and similar methods, addLink is called unguarded. However, Vercel’s OTEL wrapper currently uses @opentelemetry/[email protected], which does not support addLink() on the span object.
This leads to runtime errors:
TypeError: span.addLink is not a function
Expected behavior:
The library should check whether .addLink is supported before calling it.
This would allow compatibility with OTEL wrappers like @vercel/otel, even if they’re on older SDK versions.
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. **
The OpenTelemetry spec introduced Span.addLink() more recently, and not all implementations support it yet, particularly lightweight wrappers like Vercel’s.
@feywind Could you please take a look when you have a moment? We've unable to upgrade the latest npm package due to the issue that breaks the application.
@nicole0707 Sorry for the delay. I suspect the answer might be "we only support newer official OTel libraries" but I'll ask around.
@feywind Thanks for the context, it makes sense. Still, it probably shouldn't break the app. Would you mind having a quick look at the fix? https://github.com/googleapis/nodejs-pubsub/pull/2061 🙏