Incorrect OpenTelemetry span reported by Prisma #25436
Description
Bug description
While working on our OpenTelemetry instrumentation in debug mode we discovered some weird spans coming from Prisma instrumentation. These spans bypass sampler (they are being reported even when sampling rate is 0) and contain suspicious parentId
of '0000000000000000'
. Here is the span in debug logs from OpenTelemetry:
items to be sent [
Span {
attributes: { 'db.type': 'postgres' },
links: [],
events: [],
_droppedAttributesCount: 0,
_droppedEventsCount: 0,
_droppedLinksCount: 0,
status: { code: 0 },
endTime: [ 1728995578, 143755000 ],
_ended: true,
_duration: [ 0, 8209000 ],
name: 'prisma:engine:connection',
_spanContext: {
traceId: '4c6b47d1a6e5484db6e6706a6aaa0bbb',
spanId: '4e7ed755d9abcf3b',
traceFlags: 1
},
parentSpanId: '0000000000000000',
kind: 0,
_performanceStartTime: 3653.858667,
_performanceOffset: -0.341552734375,
_startTimeProvided: true,
startTime: [ 1728995578, 135546000 ],
resource: Resource {
_attributes: [Object],
asyncAttributesPending: false,
_syncAttributes: [Object],
_asyncAttributesPromise: undefined
},
instrumentationLibrary: { name: 'prisma', version: undefined, schemaUrl: undefined },
_spanLimits: {
attributeValueLengthLimit: Infinity,
attributeCountLimit: 128,
linkCountLimit: 128,
eventCountLimit: 128,
attributePerEventCountLimit: 128,
attributePerLinkCountLimit: 128
},
_attributeValueLengthLimit: Infinity,
_spanProcessor: MultiSpanProcessor { _spanProcessors: [Array] }
}
]
How to reproduce
- Set up OpenTelemetry instrumentation with sampling rate 0 (use only Prisma instrumentation for cleaner logs)
- Enable debug logs
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
- Trigger
prisma:engine:connection
span: I cannot pin point exactly when these spans are being generated but a bunch of DB operations should trigger it
Expected behavior
You should not see any spans being generated when sample rate is 0.
Prisma information
OpenTelemetry config:
const asyncHooksContextManager = new AsyncHooksContextManager();
asyncHooksContextManager.enable();
if (!api.context.setGlobalContextManager(asyncHooksContextManager)) {
throw new Error('Could not set global context manager');
}
const tracerProvider = new NodeTracerProvider({
resource: resource,
sampler: new AlwaysOffSampler(),
});
registerInstrumentations({
tracerProvider: tracerProvider,
instrumentations: [
new PrismaInstrumentation()
],
});
const processor = new BatchSpanProcessor(config.exporter);
tracerProvider.addSpanProcessor(processor);
tracerProvider.register({
contextManager: asyncHooksContextManager,
});
api.trace.setGlobalTracerProvider(tracerProvider);
Environment & setup
- OS: macOS 14.6.1
- Database: PostgreSQL
- Node.js version: v22.9.0
Prisma Version
Environment variables loaded from .env
prisma : 5.20.0
@prisma/client : 5.20.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v22.9.0
Query Engine (Node-API) : libquery-engine 06fc58a368dc7be9fbbbe894adf8d445d208c284 (at ../../node_modules/.pnpm/@prisma+engines@5.20.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli 06fc58a368dc7be9fbbbe894adf8d445d208c284 (at ../../node_modules/.pnpm/@prisma+engines@5.20.0/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 5.20.0-12.06fc58a368dc7be9fbbbe894adf8d445d208c284
Default Engines Hash : 06fc58a368dc7be9fbbbe894adf8d445d208c284
Studio : 0.502.0
Preview Features : tracing