packages/sqlcommenter-trace-context/README.md
W3C Trace Context (traceparent) plugin for Prisma SQL commenter.
This plugin adds the traceparent header from the current trace context to SQL queries as comments, enabling correlation between distributed traces and database queries.
npm install @prisma/sqlcommenter-trace-context
import { traceContext } from '@prisma/sqlcommenter-trace-context'
import { PrismaClient } from './generated/prisma/client'
const prisma = new PrismaClient({
adapter: myDriverAdapter,
comments: [traceContext()],
})
When tracing is enabled and the current span is sampled, queries will include a traceparent comment:
SELECT * FROM users /*traceparent='00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01'*/
The traceContext() plugin:
@prisma/instrumentationtraceparent headertraceparent in the SQL comment if the sampled flag is set (the trace flags end with 01)This means:
@prisma/instrumentation to be configured and enabled for tracingThe traceparent header follows the W3C Trace Context specification:
{version}-{trace-id}-{parent-id}-{trace-flags}
Where:
version: Always 00 for the current spectrace-id: 32 hexadecimal characters representing the trace IDparent-id: 16 hexadecimal characters representing the parent span IDtrace-flags: 2 hexadecimal characters; 01 indicates sampledApache-2.0