Skip to content

ref(node): Streamline mongoose instrumentation#21481

Open
logaretm wants to merge 7 commits into
developfrom
awad/js-2389-streamline-opentelemetryinstrumentation-mongoose
Open

ref(node): Streamline mongoose instrumentation#21481
logaretm wants to merge 7 commits into
developfrom
awad/js-2389-streamline-opentelemetryinstrumentation-mongoose

Conversation

@logaretm

@logaretm logaretm commented Jun 11, 2026

Copy link
Copy Markdown
Member

Streamlines the vendored mongoose instrumentation to use Sentry's span APIs instead of the OpenTelemetry tracing API, and removes the code paths that are dead in Sentry's context.

I also ported OTel's own integration tests of mongoose and added my own assertions to it.

I didn't fix the older semantic attributes as I believe that would be a breaking change right now.

Fixes #20737

logaretm added 7 commits June 11, 2026 15:29
Replace the OpenTelemetry tracing APIs in the vendored mongoose
instrumentation with Sentry primitives (startInactiveSpan, getActiveSpan,
span.setStatus) and bake the span origin in directly. Also drops the
config paths that are dead in Sentry's context (dbStatementSerializer,
requireParentSpan, suppressInternalInstrumentation) and the
SemconvStability dual-emission machinery, keeping only the OLD attribute
set. The OpenTelemetry instrumentation base/module-patching layer is kept.
With the OTel responseHook/dbStatementSerializer paths removed, the only
config the SDK uses is the base InstrumentationConfig. Collapse
MongooseInstrumentationConfig to that and drop the now-unused
SerializerPayload, DbStatementSerializer, ResponseInfo and
MongooseResponseCustomAttributesFunction types.
Remove ATTR_DB_STATEMENT (fed the removed dbStatementSerializer path) and
DB_SYSTEM_NAME_VALUE_MONGODB (only used by the dropped stable-semconv
branch). The remaining constants are the OLD attribute set the
instrumentation still emits.
Port the upstream OTel mongoose test coverage as unit tests that drive a
fake mongoose module through MongooseInstrumentation and assert the
produced Sentry spans. Covers save, query exec, aggregate, insertMany,
bulkWrite, document update methods (v8.21+), remove (v5/v6), error
status, parent-span linking and unpatch.
Type the vendored instrumentation's `module` parameter (MongooseModule /
MongooseModuleExports) instead of `any`, so the patch/unpatch logic is
checked against the mongoose shape. Adjust lint config accordingly.
…ion suite

Exercise more mongoose operations against the real mongodb-memory-server
so the live suite asserts span output (name, OLD attributes, op, origin)
for aggregate, insertMany and bulkWrite in addition to save/findOne.
@logaretm logaretm force-pushed the awad/js-2389-streamline-opentelemetryinstrumentation-mongoose branch from b56fa12 to f5972de Compare June 11, 2026 20:17
@linear-code

linear-code Bot commented Jun 11, 2026

Copy link
Copy Markdown

JS-2389

Comment thread .oxlintrc.base.json
Comment on lines +164 to +166
"typescript/no-explicit-any": "off",
"no-unsafe-member-access": "off",
"no-this-alias": "off"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are very common in instrumentations, so I wanted to remove the blanket eslint-disable we have and instead target the problematic rules.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.39 kB - -
@sentry/browser - with treeshaking flags 25.82 kB - -
@sentry/browser (incl. Tracing) 45.68 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.92 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.48 kB - -
@sentry/browser (incl. Tracing, Replay) 84.9 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.51 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.6 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.28 kB - -
@sentry/browser (incl. Feedback) 44.55 kB - -
@sentry/browser (incl. sendFeedback) 32.19 kB - -
@sentry/browser (incl. FeedbackAsync) 37.3 kB - -
@sentry/browser (incl. Metrics) 28.46 kB - -
@sentry/browser (incl. Logs) 28.69 kB - -
@sentry/browser (incl. Metrics & Logs) 29.39 kB - -
@sentry/react 29.18 kB - -
@sentry/react (incl. Tracing) 47.98 kB - -
@sentry/vue 32.4 kB - -
@sentry/vue (incl. Tracing) 47.57 kB - -
@sentry/svelte 27.41 kB - -
CDN Bundle 29.78 kB - -
CDN Bundle (incl. Tracing) 48.16 kB - -
CDN Bundle (incl. Logs, Metrics) 31.32 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.48 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.61 kB - -
CDN Bundle (incl. Tracing, Replay) 85.51 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.6 kB - -
CDN Bundle - uncompressed 88.46 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.67 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.17 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.65 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 217.99 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.54 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.24 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.19 kB - -
@sentry/nextjs (client) 50.43 kB - -
@sentry/sveltekit (client) 46.1 kB - -
@sentry/core/server 76.05 kB - -
@sentry/core/browser 63.19 kB - -
@sentry/node-core 61.72 kB -0.01% -3 B 🔽
@sentry/node 129.93 kB -0.43% -560 B 🔽
@sentry/node - without tracing 74.11 kB - -
@sentry/aws-serverless 86.29 kB - -
@sentry/cloudflare (withSentry) - minified 173.69 kB - -
@sentry/cloudflare (withSentry) 433.85 kB - -

View base workflow run

@logaretm logaretm marked this pull request as ready for review June 11, 2026 20:57
@logaretm logaretm requested a review from a team as a code owner June 11, 2026 20:57
@logaretm logaretm requested review from JPeer264 and andreiborza and removed request for a team June 11, 2026 20:57
attributes,
parentSpan,
);
const span = self._startSpan(this._model.collection, this._model?.modelName, 'aggregate', parentSpan);

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.

can we possibly rewrite this to use startSpan(..., () => callback) or a similar thing? Using our active span wrapper has some benefits as that has built in error handling etc 🤔

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-mongoose

2 participants