Skip to content

ref(node): Streamline amqplib instrumentation#21753

Open
s1gr1d wants to merge 2 commits into
developfrom
sig/streamline-amqplib
Open

ref(node): Streamline amqplib instrumentation#21753
s1gr1d wants to merge 2 commits into
developfrom
sig/streamline-amqplib

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Jun 24, 2026

Copy link
Copy Markdown
Member

Streamlines the amqplib instrumentation:

  • Folds attributes set via hooks (e.g. origin) into the instrumentation.
  • Use startSpan APIs from @sentry/core instead of the OTel tracer.
  • Remove unused code paths e.g. configs, hooks, dual semconv emission.
  • Replace the OTel context-key confirm-channel guard with a synchronous instance flag.
  • Removes the /* eslint-disable */ from the vendored files so they pass the linter.
  • Adds consumer-reject and confirm-channel integration tests to lock down the streamlined paths.

Closes #20723
Linear: https://linear.app/getsentry/issue/JS-2375/streamline-opentelemetryinstrumentation-amqplib

@s1gr1d s1gr1d requested a review from a team as a code owner June 24, 2026 12:58
@s1gr1d s1gr1d requested review from JPeer264, andreiborza, mydea and nicohrubec and removed request for a team June 24, 2026 12:58
Comment on lines +171 to +172
const modifiedOptions = options ?? {};
modifiedOptions.headers = modifiedOptions.headers ?? {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The startPublishSpan function mutates the caller's options object by reference, adding tracing headers. This can cause unexpected side effects when the options object is reused.
Severity: MEDIUM

Suggested Fix

Defensively clone the incoming options object and its headers property to avoid mutating the original object. For example: const modifiedOptions = { ...(options ?? {}), headers: { ...(options?.headers ?? {}) } };.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/node/src/integrations/tracing/amqplib/vendored/utils.ts#L171-L172

Potential issue: The `startPublishSpan` function mutates the `options` object passed by
the caller. When a non-null `options` object is provided, it is assigned by reference to
`modifiedOptions`. Subsequent modifications to `modifiedOptions.headers` to add tracing
information (`sentry-trace`, `baggage`) directly alter the original user-provided
object. This is problematic as the `amqplib` library documentation encourages reusing
the `options` object for multiple publish calls. This undocumented side effect can lead
to unexpected behavior and data pollution in the user's application logic.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.89 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.78 kB - -
CDN Bundle (incl. Tracing, Replay) 85.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.19 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 76.41 kB - -
@sentry/core/browser 63.56 kB - -
@sentry/node-core 61.51 kB - -
@sentry/node 122.03 kB -0.53% -642 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB - -
@sentry/node - without tracing 73.55 kB - -
@sentry/aws-serverless 84.74 kB - -
@sentry/cloudflare (withSentry) - minified 176.01 kB - -
@sentry/cloudflare (withSentry) 437.76 kB - -

View base workflow run

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall just one kinda nit

return module;
}

private patchConnect(moduleExports: any): any {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l/m: There are a lot of any in this code, but linting doesn't fail - we should include this file again by removing it from the oxlintrc base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamline @opentelemetry/instrumentation-amqplib

2 participants