ref(node): Streamline mongodb instrumentation#21619
Conversation
size-limit report 📦
|
8c0b859 to
d79e1cd
Compare
Streamlines the vendored `mongodb` instrumentation to use Sentry's span APIs instead of the OpenTelemetry tracing APIs, following the redis/pg/mongoose precedent. - Replace `tracer.startSpan` with `startInactiveSpan`, the `trace.getSpan(context.active())` + `requireParentSpan` guard with a `getActiveSpan()` check, `SpanStatusCode.ERROR` with `SPAN_STATUS_ERROR`, and the `context.with(...)`/`context.bind(...)` propagation with `withActiveSpan` (result-handler re-activation and the pool `checkOut` rebind). Drop `recordException` and the `_diag` logger. - Drop the OTel connection-usage metrics: the SDK wires up no `MeterProvider`, so `this.meter` is the no-op meter and every `add` was dead. Also removes the session and connect patches that existed only to feed those metrics (they create no spans, so span output is unchanged). - Drop the `SemconvStability` dual-emission and keep the OLD semconv attributes only (the STABLE path was env-gated behind `OTEL_SEMCONV_STABILITY_OPT_IN` and never enabled by the SDK). - Remove config the SDK never passes (`responseHook`, the configurable `dbStatementSerializer`, `requireParentSpan`); move the always-on statement serializer into the vendored code and bake the `auto.db.otel.mongo` origin into the span attributes instead of an `index.ts` responseHook. - Drop the blanket eslint-disable, type the module, and split the helpers (`utils.ts`) and wrap factories (`patches.ts`) out of the class to keep each vendored file within `max-lines`. Removes the config-passing `Mongo` unit test (its serializer logic is covered end-to-end by the integration suite) and extends the real suite with an error path: a server-rejected query asserts `status: 'internal_error'` with the origin and `db.statement` preserved.
d79e1cd to
d0846c8
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d0846c8. Configure here.
| if (span) { | ||
| if (error instanceof Error) { | ||
| span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message }); | ||
| } |
There was a problem hiding this comment.
Error span status uses raw message
Medium Severity
On failed commands, patchEnd sets span status with message: error.message. Exported span status uses that message verbatim via getStatusMessage, so it may not be the canonical internal_error value the new integration test asserts for failed finds.
Reviewed by Cursor Bugbot for commit d0846c8. Configure here.
| v4PatchConnectionPool, | ||
| v4UnpatchConnectionPool, | ||
| ), | ||
| new InstrumentationNodeModuleFile( |
There was a problem hiding this comment.
q: Is there a specific reason why this is not needed anymore?


Streamlines the vendored
mongodbinstrumentation to use Sentry's span APIs instead of the OpenTelemetry tracing APIs.