Skip to content

ref(node): Streamline amqplib instrumentation - #21753

Merged
s1gr1d merged 2 commits into
developfrom
sig/streamline-amqplib
Jun 26, 2026
Merged

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

Conversation

@s1gr1d

@s1gr1ds1gr1d 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 ownerJune 24, 2026 12:58
@s1gr1d
s1gr1d requested review from JPeer264, andreiborza, mydea and nicohrubec and removed request for a teamJune 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.

PathSize% ChangeChange
@sentry/browser27.47 kB--
@sentry/browser - with treeshaking flags25.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 flags74.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/react29.27 kB--
@sentry/react (incl. Tracing)48.28 kB--
@sentry/vue32.63 kB--
@sentry/vue (incl. Tracing)47.84 kB--
@sentry/svelte27.5 kB--
CDN Bundle29.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 - uncompressed88.94 kB--
CDN Bundle (incl. Tracing) - uncompressed145.03 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed93.65 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed149 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.62 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed264.05 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed268 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed277.75 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed281.69 kB--
@sentry/nextjs (client)50.67 kB--
@sentry/sveltekit (client)46.37 kB--
@sentry/core/server76.41 kB--
@sentry/core/browser63.56 kB--
@sentry/node-core61.51 kB--
@sentry/node122.03 kB-0.53%-642 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection)69.95 kB--
@sentry/node/light50.4 kB--
@sentry/node - without tracing73.55 kB--
@sentry/aws-serverless84.74 kB--
@sentry/cloudflare (withSentry) - minified176.01 kB--
@sentry/cloudflare (withSentry)437.76 kB--

View base workflow run

@JPeer264JPeer264 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.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

A lot of the already streamlined integrations are included in this rule - this is probably very much on purpose as the code uses a lot of module-patching and untyped library exports (so it's hard to type).

{
"files": [
"**/integrations/tracing/knex/vendored/**/*.ts",
"**/integrations/tracing/mongo/vendored/**/*.ts",
"**/integrations/tracing/graphql/vendored/**/*.ts",
"**/integrations/tracing/mysql2/vendored/**/*.ts",
"**/integrations/tracing/kafka/vendored/**/*.ts",
"**/integrations/tracing/tedious/vendored/**/*.ts",
"**/integrations/tracing/hapi/vendored/**/*.ts",
"**/integrations/tracing/mongoose/vendored/**/*.ts",
"**/integrations/tracing/amqplib/vendored/**/*.ts",
"**/integrations/tracing/prisma/vendored/**/*.ts",
"**/integrations/tracing/postgres/vendored/**/*.ts",
"**/integrations/tracing/fastify/vendored/**/*.ts",
"**/integrations/tracing/redis/vendored/**/*.ts"
],
"rules": {
"typescript/no-explicit-any": "off",
"no-unsafe-member-access": "off",
"no-this-alias": "off"
}
},

@s1gr1d
s1gr1d merged commit e562f94 into developJun 26, 2026
351 of 354 checks passed
@s1gr1d
s1gr1d deleted the sig/streamline-amqplib branch June 26, 2026 08:28
Sign up for freeto 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

@s1gr1d@JPeer264