feat: add traceContext SQL commenter plugin#28802
Conversation
size-limit report 📦
|
011cc8b to
9cde6bc
Compare
0f90c48 to
00b22fd
Compare
9cde6bc to
a1cfbc6
Compare
00b22fd to
c97117e
Compare
92afb54 to
ae6ba74
Compare
c97117e to
7ff0e2b
Compare
ae6ba74 to
da4346e
Compare
7ff0e2b to
a6dd535
Compare
da4346e to
0023078
Compare
28c3171 to
a42141a
Compare
0023078 to
3e0c34f
Compare
0d39245 to
a517780
Compare
a42141a to
34970da
Compare
92fafd0 to
57e72a3
Compare
57e72a3 to
8c583e0
Compare
34970da to
023c294
Compare
|
Warning Rate limit exceeded@aqrln has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 39 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (46)
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a new instrumentation-contract package exposing global tracing helper accessors and types, introduces a sqlcommenter-trace-context plugin that conditionally appends W3C traceparent to SQL comments, updates client and instrumentation code to use the contract, adds tests, build configs, and CI steps for the new packages. Changes
Sequence DiagramsequenceDiagram
actor App as Application
participant PrismaInst as PrismaInstrumentation
participant Global as instrumentation-contract\n(Global Accessors)
participant Plugin as sqlcommenter-trace-context
participant DB as Database/SQL
App->>PrismaInst: enable()
PrismaInst->>Global: setGlobalTracingHelper(helper)
App->>DB: execute query
DB->>Plugin: buildComments()
Plugin->>Global: getGlobalTracingHelper()
Global-->>Plugin: TracingHelper | undefined
alt Tracing enabled & sampled
Plugin->>Plugin: getTraceParent()
Plugin-->>DB: add SQL comment with traceparent
else Tracing enabled & not sampled
Plugin->>Plugin: getTraceParent()
Plugin-->>DB: no traceparent comment
else Tracing disabled
Plugin-->>DB: no traceparent comment
end
App->>PrismaInst: disable()
PrismaInst->>Global: clearGlobalTracingHelper()
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Comment |
8c583e0 to
d6a6c11
Compare
There was a problem hiding this comment.
Pull request overview
This PR restores the traceparent SQL comment functionality that was removed in Prisma 7, making it opt-in through a new SQL commenter plugin system. The implementation includes creating a new instrumentation contract package to decouple type definitions from implementation, allowing the trace context plugin and other packages to access tracing functionality without circular dependencies.
Key Changes
- Created
@prisma/instrumentation-contractpackage containing shared types and global helper functions for tracing integration - Implemented
@prisma/sqlcommenter-trace-contextplugin that appends W3C Trace Contexttraceparentheaders to SQL queries when tracing is enabled and sampled - Refactored
@prisma/instrumentationand@prisma/clientto use the new contract package for type definitions
Reviewed changes
Copilot reviewed 45 out of 49 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/instrumentation-contract/* |
New package providing shared TracingHelper interface and global helper access functions |
packages/sqlcommenter-trace-context/* |
New plugin package that adds traceparent comments to SQL queries based on sampling state |
packages/instrumentation/src/PrismaInstrumentation.ts |
Refactored to use contract package for setting/clearing global tracing helpers |
packages/client/src/runtime/core/tracing/TracingHelper.ts |
Simplified to use getGlobalTracingHelper() from contract package |
packages/client/tests/e2e/sqlcommenter-trace-context/* |
Comprehensive E2E tests verifying traceparent behavior with different sampling configurations |
packages/client/tests/functional/tracing-no-sampling/tests.ts |
Updated to use traceContext plugin and verify no traceparent with 0% sampling |
packages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.ts |
Removed traceparent stripping logic as it's now opt-in |
.github/workflows/test-template.yml |
Added test jobs for new packages |
Various package.json, tsconfig.json, pnpm-lock.yaml |
Configuration updates for new dependencies |
Files not reviewed (4)
- packages/client/tests/e2e/sqlcommenter-query-tags/pnpm-lock.yaml: Language not supported
- packages/client/tests/e2e/sqlcommenter-trace-context/pnpm-lock.yaml: Language not supported
- packages/client/tests/e2e/sqlcommenter/pnpm-lock.yaml: Language not supported
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/client/src/runtime/core/tracing/TracingHelper.ts (1)
61-63: Consider if a singleton pattern would be more appropriate.Each call to
getTracingHelper()creates a newDynamicTracingHelperinstance. While this is functionally correct (since the class holds no state), it does create unnecessary allocations if called frequently.If this becomes a hot path, consider using a singleton:
+const dynamicTracingHelper = new DynamicTracingHelper() + export function getTracingHelper(): TracingHelper { - return new DynamicTracingHelper() + return dynamicTracingHelper }However, since
DynamicTracingHelperis stateless and the overhead is minimal, this is purely optional.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (4)
packages/client/tests/e2e/sqlcommenter-query-tags/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlpackages/client/tests/e2e/sqlcommenter-trace-context/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlpackages/client/tests/e2e/sqlcommenter/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (45)
.github/workflows/test-template.yml(3 hunks)packages/client/package.json(1 hunks)packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts(1 hunks)packages/client/src/runtime/core/engines/client/ClientEngine.ts(1 hunks)packages/client/src/runtime/core/engines/client/RemoteExecutor.ts(1 hunks)packages/client/src/runtime/core/engines/common/Engine.ts(1 hunks)packages/client/src/runtime/core/engines/common/types/QueryEngine.ts(1 hunks)packages/client/src/runtime/core/tracing/TracingHelper.test.ts(3 hunks)packages/client/src/runtime/core/tracing/TracingHelper.ts(2 hunks)packages/client/src/runtime/getPrismaClient.ts(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/_steps.cts(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/package.json(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/readme.md(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts(1 hunks)packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json(1 hunks)packages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.ts(1 hunks)packages/client/tests/functional/tracing-no-sampling/tests.ts(2 hunks)packages/instrumentation-contract/README.md(1 hunks)packages/instrumentation-contract/helpers/build.ts(1 hunks)packages/instrumentation-contract/package.json(1 hunks)packages/instrumentation-contract/src/global.test.ts(1 hunks)packages/instrumentation-contract/src/global.ts(1 hunks)packages/instrumentation-contract/src/index.ts(1 hunks)packages/instrumentation-contract/src/types.ts(4 hunks)packages/instrumentation-contract/tsconfig.build.json(1 hunks)packages/instrumentation-contract/tsconfig.json(1 hunks)packages/instrumentation/package.json(1 hunks)packages/instrumentation/src/ActiveTracingHelper.ts(1 hunks)packages/instrumentation/src/PrismaInstrumentation.test.ts(1 hunks)packages/instrumentation/src/PrismaInstrumentation.ts(2 hunks)packages/instrumentation/src/__tests__/PrismaInstrumentation.test.ts(0 hunks)packages/instrumentation/src/constants.ts(0 hunks)packages/instrumentation/tsconfig.build.json(1 hunks)packages/internals/src/index.ts(0 hunks)packages/sqlcommenter-trace-context/README.md(1 hunks)packages/sqlcommenter-trace-context/helpers/build.ts(1 hunks)packages/sqlcommenter-trace-context/package.json(1 hunks)packages/sqlcommenter-trace-context/src/index.test.ts(1 hunks)packages/sqlcommenter-trace-context/src/index.ts(1 hunks)packages/sqlcommenter-trace-context/tsconfig.build.json(1 hunks)packages/sqlcommenter-trace-context/tsconfig.json(1 hunks)packages/sqlcommenter/README.md(1 hunks)tsconfig.build.bundle.json(2 hunks)
💤 Files with no reviewable changes (3)
- packages/internals/src/index.ts
- packages/instrumentation/src/tests/PrismaInstrumentation.test.ts
- packages/instrumentation/src/constants.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript for new code in the Prisma monorepo
Files:
packages/instrumentation-contract/src/index.tspackages/client/src/runtime/getPrismaClient.tspackages/instrumentation/src/PrismaInstrumentation.test.tspackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/sqlcommenter-trace-context/src/index.test.tspackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/instrumentation-contract/src/global.tspackages/sqlcommenter-trace-context/helpers/build.tspackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/instrumentation-contract/src/types.tspackages/instrumentation-contract/src/global.test.tspackages/instrumentation/src/PrismaInstrumentation.tspackages/instrumentation/src/ActiveTracingHelper.tspackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/client/src/runtime/core/tracing/TracingHelper.tspackages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.tspackages/instrumentation-contract/helpers/build.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/src/runtime/core/engines/common/Engine.tspackages/sqlcommenter-trace-context/src/index.ts
packages/client/src/runtime/getPrismaClient.ts
📄 CodeRabbit inference engine (AGENTS.md)
In PrismaClient constructor options, add runtime types to
PrismaClientOptionsinpackages/client/src/runtime/getPrismaClient.ts
Files:
packages/client/src/runtime/getPrismaClient.ts
tsconfig.build.bundle.json
📄 CodeRabbit inference engine (AGENTS.md)
Update
tsconfig.build.bundle.jsonundercompilerOptions.pathswith resolution paths for new workspace packages to enable go-to-definition in editors
Files:
tsconfig.build.bundle.json
**/*.test.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.test.ts: Place test files alongside source files with.test.tsnaming convention, which are excluded from build output via esbuild config
Inline snapshots should be kept concise unless the exact message matters
Files:
packages/instrumentation/src/PrismaInstrumentation.test.tspackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/sqlcommenter-trace-context/src/index.test.tspackages/instrumentation-contract/src/global.test.ts
packages/*/helpers/build.ts
📄 CodeRabbit inference engine (AGENTS.md)
packages/*/helpers/build.ts: For new packages, add ahelpers/build.tsfile to configure the build process
UseadapterConfigfromhelpers/compile/configs.tsfor type-only packages to bundle to both CJS and ESM with type declarations
Files:
packages/sqlcommenter-trace-context/helpers/build.tspackages/instrumentation-contract/helpers/build.ts
packages/client/src/runtime/core/engines/common/Engine.ts
📄 CodeRabbit inference engine (AGENTS.md)
In PrismaClient constructor options, update engine config in
EngineConfiginterface inpackages/client/src/runtime/core/engines/common/Engine.ts
Files:
packages/client/src/runtime/core/engines/common/Engine.ts
🧠 Learnings (21)
📓 Common learnings
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client/src/runtime/getPrismaClient.ts : In PrismaClient constructor options, add runtime types to `PrismaClientOptions` in `packages/client/src/runtime/getPrismaClient.ts`
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client-generator-js/src/TSClient/PrismaClient.ts : In PrismaClient constructor options, update generated types in `packages/client-generator-js/src/TSClient/PrismaClient.ts` (`buildClientOptions` method)
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client/src/runtime/core/engines/common/Engine.ts : In PrismaClient constructor options, update engine config in `EngineConfig` interface in `packages/client/src/runtime/core/engines/common/Engine.ts`
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts : In PrismaClient constructor options, update generated types in `packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts` (`buildClientOptions` function)
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to tsconfig.build.bundle.json : Update `tsconfig.build.bundle.json` under `compilerOptions.paths` with resolution paths for new workspace packages to enable go-to-definition in editors
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/sqlcommenter-trace-context/tsconfig.build.jsontsconfig.build.bundle.jsonpackages/instrumentation-contract/tsconfig.build.jsonpackages/instrumentation/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/sqlcommenter-trace-context/package.jsonpackages/instrumentation-contract/helpers/build.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/{package.json,tsconfig.json,tsconfig.build.json} : For new packages, create `package.json`, `tsconfig.json`, and `tsconfig.build.json` configuration files
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/sqlcommenter-trace-context/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/sqlcommenter-trace-context/package.jsonpackages/instrumentation-contract/package.json
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to **/*.ts : Use TypeScript for new code in the Prisma monorepo
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/client/src/runtime/getPrismaClient.tspackages/sqlcommenter-trace-context/tsconfig.build.jsontsconfig.build.bundle.jsonpackages/instrumentation-contract/tsconfig.build.jsonpackages/instrumentation/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/migrate/src/__tests__/fixtures/**/*.config.ts : CLI test fixtures should provide `prisma.config.ts` per schema variant (e.g., `invalid-url.config.ts` next to `prisma/invalid-url.prisma`)
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/_steps.ctspackages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prismatsconfig.build.bundle.jsonpackages/instrumentation/src/PrismaInstrumentation.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/instrumentation-contract/tsconfig.build.json.github/workflows/test-template.ymlpackages/instrumentation/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/sqlcommenter-trace-context/src/index.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.tspackages/client/tests/functional/tracing-no-sampling/tests.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client-generator-{js,ts}/src/**/*.ts : Use `prisma/ts-builders` for generating TypeScript type declarations
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/client/src/runtime/getPrismaClient.tspackages/sqlcommenter-trace-context/tsconfig.build.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prismatsconfig.build.bundle.jsonpackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/instrumentation-contract/tsconfig.build.jsonpackages/instrumentation/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/sqlcommenter-trace-context/helpers/build.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/sqlcommenter-trace-context/package.jsonpackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/instrumentation-contract/helpers/build.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/package.jsonpackages/instrumentation/package.jsonpackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to **/*.test.ts : Place test files alongside source files with `.test.ts` naming convention, which are excluded from build output via esbuild config
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.jsonpackages/sqlcommenter-trace-context/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.build.json.github/workflows/test-template.ymlpackages/instrumentation/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/instrumentation-contract/helpers/build.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts : In PrismaClient constructor options, update generated types in `packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts` (`buildClientOptions` function)
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/client/src/runtime/getPrismaClient.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prismatsconfig.build.bundle.jsonpackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/instrumentation-contract/src/types.tspackages/instrumentation/src/PrismaInstrumentation.tspackages/instrumentation/src/ActiveTracingHelper.tspackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/instrumentation-contract/helpers/build.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/package.jsonpackages/instrumentation/package.jsonpackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client-generator-js/src/TSClient/PrismaClient.ts : In PrismaClient constructor options, update generated types in `packages/client-generator-js/src/TSClient/PrismaClient.ts` (`buildClientOptions` method)
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/client/src/runtime/getPrismaClient.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prismatsconfig.build.bundle.jsonpackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/instrumentation-contract/src/types.tspackages/instrumentation/src/PrismaInstrumentation.tspackages/instrumentation/src/ActiveTracingHelper.tspackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/instrumentation-contract/helpers/build.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/package.jsonpackages/instrumentation/package.jsonpackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Run client e2e suites with `pnpm --filter prisma/client test:e2e --verbose --runInBand` after fresh `pnpm build`
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/package.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/_steps.cts.github/workflows/test-template.ymlpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/client/tests/functional/tracing-no-sampling/tests.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/migrate/src/__tests__/**/*.test.ts : Use `ctx.setDatasource()` test helper to override config.datasource for connection-specific test scenarios
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/_steps.ctspackages/client/tests/e2e/sqlcommenter-trace-context/readme.mdpackages/instrumentation/src/PrismaInstrumentation.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts.github/workflows/test-template.ymlpackages/client/src/runtime/core/tracing/TracingHelper.test.tspackages/sqlcommenter-trace-context/src/index.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/instrumentation-contract/src/global.test.tspackages/client/tests/functional/tracing-no-sampling/tests.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/migrate/src/__tests__/**/*.test.ts : In CLI test fixtures, use `ctx.setConfigFile('<name>')` to override the config used for the next CLI invocation
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/_steps.ctspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/instrumentation/tsconfig.build.jsonpackages/sqlcommenter-trace-context/src/index.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/client/tests/e2e/sqlcommenter-trace-context/src/index.tspackages/instrumentation-contract/src/global.test.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Run client functional tests via `pnpm --filter prisma/client test:functional` with typechecking or `pnpm --filter prisma/client test:functional:code` for code only
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/_steps.ctspackages/client/src/runtime/getPrismaClient.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/tests/functional/tracing-no-sampling/tests.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client/src/runtime/getPrismaClient.ts : In PrismaClient constructor options, add runtime types to `PrismaClientOptions` in `packages/client/src/runtime/getPrismaClient.ts`
Applied to files:
packages/client/src/runtime/getPrismaClient.tspackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/instrumentation-contract/src/types.tspackages/instrumentation/src/ActiveTracingHelper.tspackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/package.jsonpackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client/src/runtime/core/engines/common/Engine.ts : In PrismaClient constructor options, update engine config in `EngineConfig` interface in `packages/client/src/runtime/core/engines/common/Engine.ts`
Applied to files:
packages/client/src/runtime/getPrismaClient.tstsconfig.build.bundle.jsonpackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/src/runtime/core/engines/common/types/QueryEngine.tspackages/instrumentation-contract/src/types.tspackages/instrumentation/src/PrismaInstrumentation.tspackages/instrumentation/src/ActiveTracingHelper.tspackages/client/src/runtime/core/engines/accelerate/HeaderBuilder.tspackages/client/src/runtime/core/tracing/TracingHelper.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/client/src/runtime/utils/validatePrismaClientOptions.ts : In PrismaClient constructor options, add validation to `packages/client/src/runtime/utils/validatePrismaClientOptions.ts` by updating the `knownProperties` array and `validators` object
Applied to files:
packages/client/src/runtime/getPrismaClient.tspackages/client/src/runtime/core/engines/client/RemoteExecutor.tspackages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/client/ClientEngine.tspackages/client/tests/functional/tracing-no-sampling/tests.tspackages/client/package.json
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/*/helpers/build.ts : For new packages, add a `helpers/build.ts` file to configure the build process
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.build.jsonpackages/instrumentation-contract/tsconfig.build.jsonpackages/sqlcommenter-trace-context/helpers/build.tspackages/instrumentation-contract/helpers/build.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to packages/*/helpers/build.ts : Use `adapterConfig` from `helpers/compile/configs.ts` for type-only packages to bundle to both CJS and ESM with type declarations
Applied to files:
packages/sqlcommenter-trace-context/tsconfig.build.jsontsconfig.build.bundle.jsonpackages/instrumentation-contract/tsconfig.build.jsonpackages/sqlcommenter-trace-context/helpers/build.tspackages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.jsonpackages/instrumentation-contract/helpers/build.tspackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Use Jest for legacy unit tests and Vitest for new test coverage in the CLI
Applied to files:
packages/instrumentation/src/PrismaInstrumentation.test.tspackages/instrumentation-contract/src/global.test.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Commands and tests should read connection settings from `PrismaConfigInternal.datasource` rather than CLI flags or environment loading
Applied to files:
packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.tspackages/client/src/runtime/core/engines/common/Engine.ts
📚 Learning: 2025-12-03T09:46:36.079Z
Learnt from: CR
Repo: prisma/prisma PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-03T09:46:36.079Z
Learning: Applies to **/*.test.ts : Inline snapshots should be kept concise unless the exact message matters
Applied to files:
packages/sqlcommenter-trace-context/src/index.test.tspackages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
🧬 Code graph analysis (10)
packages/instrumentation/src/PrismaInstrumentation.test.ts (2)
packages/instrumentation-contract/src/global.ts (2)
clearGlobalTracingHelper(53-56)getGlobalTracingHelper(21-34)packages/instrumentation/src/PrismaInstrumentation.ts (1)
PrismaInstrumentation(22-57)
packages/client/src/runtime/core/tracing/TracingHelper.test.ts (2)
packages/instrumentation-contract/src/global.ts (2)
clearGlobalTracingHelper(53-56)setGlobalTracingHelper(40-47)packages/client/src/runtime/core/tracing/TracingHelper.ts (2)
getTracingHelper(56-58)getTracingHelper(61-63)
packages/sqlcommenter-trace-context/src/index.test.ts (3)
packages/instrumentation-contract/src/types.ts (1)
TracingHelper(53-61)packages/instrumentation-contract/src/global.ts (2)
clearGlobalTracingHelper(53-56)setGlobalTracingHelper(40-47)packages/sqlcommenter-trace-context/src/index.ts (1)
traceContext(56-74)
packages/instrumentation-contract/src/global.ts (1)
packages/instrumentation-contract/src/types.ts (2)
PrismaInstrumentationGlobalValue(63-65)TracingHelper(53-61)
packages/sqlcommenter-trace-context/helpers/build.ts (1)
helpers/compile/configs.ts (1)
adapterConfig(37-37)
packages/instrumentation-contract/src/global.test.ts (2)
packages/instrumentation-contract/src/types.ts (1)
TracingHelper(53-61)packages/instrumentation-contract/src/global.ts (3)
clearGlobalTracingHelper(53-56)getGlobalTracingHelper(21-34)setGlobalTracingHelper(40-47)
packages/instrumentation/src/PrismaInstrumentation.ts (2)
packages/instrumentation-contract/src/global.ts (3)
setGlobalTracingHelper(40-47)clearGlobalTracingHelper(53-56)getGlobalTracingHelper(21-34)packages/instrumentation/src/ActiveTracingHelper.ts (1)
ActiveTracingHelper(43-106)
packages/instrumentation-contract/helpers/build.ts (1)
helpers/compile/build.ts (1)
BuildOptions(21-26)
packages/client/tests/functional/tracing-no-sampling/tests.ts (1)
packages/sqlcommenter-trace-context/src/index.ts (1)
traceContext(56-74)
packages/sqlcommenter-trace-context/src/index.ts (1)
packages/instrumentation-contract/src/global.ts (1)
getGlobalTracingHelper(21-34)
🔇 Additional comments (57)
packages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.ts (1)
73-73: LGTM! Simplified query processing aligns with opt-in traceparent approach.The removal of traceparent comment stripping is correct since queries no longer include these comments by default. This simplifies the test and aligns with the PR's objective of making trace context opt-in via the new SQL commenter plugin.
packages/sqlcommenter-trace-context/tsconfig.json (1)
1-4: No action required—all TypeScript configuration files are properly in place and configured.This package includes both
tsconfig.jsonand the required companiontsconfig.build.json, following the standard pattern used across the monorepo. The roottsconfig.build.bundle.jsonhas already been updated with the correct resolution path for@prisma/sqlcommenter-trace-contextpointing to./packages/sqlcommenter-trace-context/src. The configuration is complete and correct.Likely an incorrect or invalid review comment.
packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma (1)
1-14: LGTM!The schema is well-structured for e2e testing purposes. The SQLite datasource without an inline
urlis appropriate since it's configured viaprisma.config.tsin the same directory.packages/instrumentation-contract/tsconfig.json (1)
1-4: LGTM!Standard tsconfig for a new package, correctly extending the root configuration. Based on learnings, this satisfies the requirement for new packages to include
tsconfig.json.packages/sqlcommenter-trace-context/tsconfig.build.json (1)
1-8: LGTM!Build configuration follows the monorepo conventions: extends the regular build config, outputs to
dist, and properly excludes test files. Based on learnings, this satisfies the requirement for new packages to includetsconfig.build.json.packages/instrumentation/tsconfig.build.json (1)
6-7: LGTM!Adding the test exclusion pattern aligns this package with the monorepo convention and ensures
.test.tsfiles are not included in the build output.packages/instrumentation-contract/tsconfig.build.json (1)
1-8: LGTM!Build configuration follows monorepo conventions correctly. Based on learnings, this satisfies the requirement for new packages to include
tsconfig.build.json.packages/sqlcommenter-trace-context/helpers/build.ts (1)
1-4: LGTM!Build script correctly uses
adapterConfigfromhelpers/compile/configs.tsfor bundling to both CJS and ESM with type declarations. As per coding guidelines, this is the recommended approach for packages like this.packages/instrumentation-contract/helpers/build.ts (1)
1-14: LGTM!The custom build configuration is appropriate here since the package needs
@opentelemetry/apias an external dependency, which isn't easily supported byadapterConfig. The dual-output approach (CJS with types, ESM) provides broad compatibility. The use ofsatisfies BuildOptionsensures type safety.packages/instrumentation-contract/package.json (2)
3-3: Verify version before publishing.The package version is set to
0.0.0. Ensure this is updated to an appropriate version number before publishing to npm.
39-44: Peer dependency range is appropriate.The package only imports basic types (
Context,Span,SpanOptions) from@opentelemetry/api, all of which have been stable since 1.8. The 1.9.0 version used in devDependencies introduces features like the synchronous Gauge instrument and post-creation span links, neither of which are used here. The^1.8peer dependency range is correct and does not need to be updated.packages/sqlcommenter-trace-context/package.json (1)
3-3: Verify version before publishing.The package version is set to
0.0.0. Ensure this is updated to an appropriate version number before publishing to npm.packages/sqlcommenter-trace-context/README.md (1)
1-68: LGTM! Clear and comprehensive documentation.The README provides excellent documentation for the plugin, including:
- Clear installation and usage instructions
- Helpful examples showing SQL output
- Detailed explanation of when the traceparent is added
- W3C Trace Context specification reference
- Requirements and licensing information
packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts (1)
3-3: LGTM! Type import updated to instrumentation-contract.The import source for
TracingHelperhas been correctly updated from@prisma/internalsto@prisma/instrumentation-contract. This is a type-only import with no runtime behavior changes, aligning with the PR's refactoring to centralize tracing types.packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json (1)
1-9: LGTM! Appropriate TypeScript configuration for e2e tests.The tsconfig correctly:
- Extends the base configuration
- Excludes the test steps file (
_steps.cts) from compilation- Uses modern module resolution (
NodeNext) suitable for Node.js environmentspackages/client/src/runtime/core/engines/client/RemoteExecutor.ts (1)
5-5: LGTM! Type imports updated to instrumentation-contract.The import source for
EngineTraceEventandTracingHelperhas been correctly updated from@prisma/internalsto@prisma/instrumentation-contract. This is a type-only import with no runtime behavior changes, consistent with the broader refactoring in this PR.packages/client/src/runtime/core/engines/client/ClientEngine.ts (1)
20-21: LGTM! Type and runtime imports correctly separated.The changes correctly:
- Import
TracingHelperas a type-only symbol from@prisma/instrumentation-contract- Keep
assertNeveras a runtime import from@prisma/internals(used at line 435)This separation aligns with the PR's refactoring to centralize tracing types while maintaining runtime dependencies where needed.
packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts (1)
1-7: LGTM! Appropriate test configuration.The Prisma config correctly sets up a SQLite database for e2e tests, which is suitable for testing without requiring external database infrastructure. The configuration structure follows the expected pattern for Prisma config files.
packages/instrumentation/package.json (1)
30-30: LGTM! Dependency update aligns with new contract package.The devDependency change from
@prisma/internalsto@prisma/instrumentation-contractcorrectly reflects the refactoring to use the new contract package for tracing types.packages/client/src/runtime/core/engines/common/types/QueryEngine.ts (1)
2-2: LGTM! Type-only import correctly sources types from contract package.The migration to type-only imports from
@prisma/instrumentation-contractis appropriate sinceEngineSpanandEngineTraceEventare only used in type positions within this file.packages/instrumentation-contract/src/global.test.ts (1)
1-89: LGTM! Comprehensive test coverage for global tracing helper API.The test suite thoroughly validates all aspects of the global tracing helper management:
- Initial undefined state
- Set and retrieve operations
- Helper replacement
- Cleanup operations
- Safe handling of no-op scenarios
The use of
beforeEachandafterEachfor cleanup ensures test isolation.tsconfig.build.bundle.json (1)
28-28: LGTM! Path aliases correctly configured for new packages.The path mappings for
@prisma/instrumentation-contractand@prisma/sqlcommenter-trace-contextare properly configured, enabling editor go-to-definition support for the new workspace packages.Based on coding guidelines, this update to
tsconfig.build.bundle.jsonis required for new workspace packages.Also applies to: 38-38
packages/client/src/runtime/getPrismaClient.ts (1)
6-7: LGTM! Type-only imports correctly separated from runtime imports.The refactoring appropriately:
- Imports
ExtendedSpanOptionsandTracingHelperas type-only from@prisma/instrumentation-contract- Preserves runtime import of
loggerfrom@prisma/internals(used at Line 402)This separation ensures no unnecessary runtime dependencies while maintaining type information.
packages/client/tests/functional/tracing-no-sampling/tests.ts (1)
13-13: LGTM! Test correctly validates opt-in trace context behavior.The addition of
traceContext()in thecommentsoption validates that:
- The new plugin is properly integrated
- With 0% sampling, no
traceparentis added to queries (as verified by the test assertions)- The opt-in nature of the feature is preserved
The test setup correctly exercises the new SQL commenter trace context functionality.
Also applies to: 64-67
packages/instrumentation/src/ActiveTracingHelper.ts (1)
12-18: LGTM! Type-only imports correctly source from contract package.The migration to type-only imports from
@prisma/instrumentation-contractis appropriate, as all imported types (EngineSpan,EngineSpanKind,ExtendedSpanOptions,SpanCallback,TracingHelper) are used only in type positions and interface implementations.packages/instrumentation/src/PrismaInstrumentation.test.ts (1)
1-41: LGTM! Comprehensive test coverage for instrumentation lifecycle.The test suite effectively validates:
- Initial state (no global helper)
- Automatic enabling behavior (with helpful comment about upstream dependency)
- Explicit enable/disable operations
- Correct
isEnabled()state tracking- Integration with global tracing helper API from the contract package
The
beforeEachhook ensures proper test isolation by clearing the global state.packages/instrumentation-contract/README.md (1)
1-113: README matches the tracing contract; keep it in sync with types.The documented
TracingHelperinterface and global helper functions align with the described contract and expected usage; just ensure this stays updated iftypes.tsevolves..github/workflows/test-template.yml (1)
935-938: CI wiring for new packages looks consistent.Adding
pnpm run testforinstrumentation-contractandsqlcommenter-trace-contextin bothothersandno-dockerjobs, with the sameifguards and patterns as neighboring steps, is consistent and should give good coverage across platforms.Also applies to: 963-966, 1331-1335, 1341-1345
packages/client/tests/e2e/sqlcommenter-trace-context/_steps.cts (1)
1-20: E2E step orchestration is sound and idiomatic.The setup/test/finish flow matches existing client e2e patterns (install → generate → db push → run scenario → typecheck) and uses
zxcorrectly withexecuteSteps.packages/instrumentation-contract/src/index.ts (1)
1-2: Public entrypoint re-exports are appropriate.Re-exporting
./globaland./typesfrom the package root gives consumers a single import path without leaking internals; looks good.packages/client/src/runtime/core/engines/common/Engine.ts (1)
4-4: TracingHelper import migration to instrumentation-contract looks correct.Switching to
import type { TracingHelper } from '@prisma/instrumentation-contract'keeps theEngineConfig.tracingHelperAPI surface unchanged while aligning with the new shared tracing contract and avoiding extra runtime deps from this file.packages/client/tests/e2e/sqlcommenter-trace-context/package.json (1)
1-29: E2E test package manifest is consistent with existing patterns.The manifest (private package,
/tmpPrisma tarballs, OTel deps, andonlyBuiltDependencies: ["better-sqlite3"]) matches the standard setup for client e2e scenarios and should work fine with the new_steps.ctsflow.packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts (3)
81-131: Test 2 executes query outside of an active span, unlike Test 1.In Test 1 (lines 55-60), the query runs inside
tracer.startActiveSpan(), but Test 2 (line 117) runsprisma.user.findMany()directly without an active span. This means Test 2 tests a different scenario than expected - it's testing "no active span context" rather than "active span with 0% sampling".If the intent is to verify that unsampled spans don't produce traceparent comments, the query should also run within an active span:
- await prisma.user.findMany() + const tracer = tracerProvider.getTracer('test') + await tracer.startActiveSpan('test-operation', async (span) => { + await prisma.user.findMany() + span.end() + })However, if the current behavior is intentional (testing that without an active sampled span no traceparent is added), consider updating the test description to clarify this.
19-79: LGTM! Test 1 correctly validates traceparent presence with sampling.The test properly:
- Sets up OpenTelemetry with 100% sampling
- Registers Prisma instrumentation
- Captures queries via event listener
- Validates the traceparent format matches W3C spec with sampled flag
01- Performs cleanup of instrumentation and tracing globals
133-161: LGTM! Test 3 validates behavior without tracing configuration.The test correctly verifies that when no tracing infrastructure is configured, the
traceContext()plugin does not inject traceparent comments.packages/sqlcommenter-trace-context/src/index.ts (2)
12-30: LGTM! Robust traceparent parsing with proper validation.The
isSampled()function correctly:
- Validates the 4-part W3C traceparent structure
- Checks trace-flags length (2 hex chars)
- Handles invalid hex parsing with
isNaNcheck- Uses bitwise AND to check the sampled flag (0x01)
56-74: LGTM! Plugin implementation follows expected patterns.The plugin correctly:
- Retrieves the global tracing helper lazily on each invocation
- Returns empty object when tracing is disabled
- Only includes traceparent when the span is sampled
- Integrates cleanly with the SqlCommenterPlugin interface
The defensive checks at lines 61-63 and 68-70 ensure graceful degradation when tracing isn't configured or active.
packages/client/src/runtime/core/tracing/TracingHelper.test.ts (2)
16-22: LGTM! Good test isolation with lifecycle hooks.Adding
beforeEachandafterEachhooks to clear the global tracing helper ensures proper test isolation and prevents state leakage between tests.
34-61: LGTM! Tests properly validate global helper lifecycle.The updated tests correctly verify:
- The helper picks up a globally set tracing helper
- After clearing, the system falls back to the disabled helper (traceparent ending in
00)The tests align well with the new
@prisma/instrumentation-contractAPI.packages/instrumentation/src/PrismaInstrumentation.ts (1)
39-56: LGTM! Clean refactor to centralized global helper API.The implementation correctly:
- Uses
setGlobalTracingHelper()to register theActiveTracingHelperwhen enabling- Uses
clearGlobalTracingHelper()to remove the helper when disabling- Uses
getGlobalTracingHelper() !== undefinedto check enabled stateThis centralizes the global state management in
@prisma/instrumentation-contract, improving maintainability and consistency across packages.packages/instrumentation-contract/src/global.ts (4)
21-34: LGTM! Proper version isolation with backwards compatibility.The
getGlobalTracingHelper()function correctly:
- Prioritizes the versioned global key for major version isolation
- Falls back to the unversioned global for backwards compatibility with older versions
- Uses optional chaining for safe property access
The TODO comment appropriately flags this for potential simplification in v8.
40-47: LGTM! Dual-write strategy ensures compatibility.Setting both versioned and unversioned globals ensures that:
- New clients using versioned keys can find the helper
- Older clients using the unversioned key remain functional
This is the correct approach for a compatibility transition period.
53-56: LGTM! Complete cleanup of global state.Deleting both global keys ensures no stale references remain after disabling instrumentation.
1-7: JSON module import is correctly configured.The
resolveJsonModule: truesetting is present intsconfig.build.regular.json(the base configuration) and properly inherited bypackages/instrumentation-contract/tsconfig.jsonthrough the configuration chain. The import ofpackage.jsonon line 1 will work as expected.packages/sqlcommenter-trace-context/src/index.test.ts (6)
1-16: LGTM! Well-structured mock helper factory.The
createMockTracingHelperfactory provides good defaults while allowing targeted overrides for individual tests. The interface implementation is complete and matches theTracingHelpercontract from@prisma/instrumentation-contract.
18-27: LGTM! Mock context is minimal and appropriate.The mock context correctly matches the
SqlCommenterContextshape required by the plugin.
29-36: LGTM! Proper test isolation with global state cleanup.Using both
beforeEachandafterEachto clear the global tracing helper ensures tests don't leak state to each other.
63-123: Good coverage of W3C trace-context sampled flag variations.The tests correctly verify:
01(sampled) returns traceparent00(not sampled) returns empty03(sampled bit set in flags with other bits) returns traceparent02(other bits set, sampled bit not set) returns emptyThis aligns with the W3C Trace Context specification where the sampled flag is the lowest bit (0x01).
125-182: Comprehensive edge case coverage for malformed traceparents.Good defensive testing for:
- Wrong number of parts
- Invalid hex characters in flags
- Wrong flag length
- Placeholder traceparent
This ensures the
isSampledfunction gracefully handles invalid input.
192-213: Good test for dynamic tracing state evaluation.This test verifies that the plugin correctly re-evaluates tracing state on each invocation rather than capturing it at plugin creation time. This is important for the use case where tracing can be toggled via
PrismaInstrumentation::disable/enableat runtime.packages/client/src/runtime/core/tracing/TracingHelper.ts (2)
2-8: LGTM! Clean import consolidation.All tracing types and the global helper accessor are now imported from the centralized
@prisma/instrumentation-contractpackage, which aligns with the PR objective of introducing a contract-based interface.
37-59: Good refactor to centralize global helper access.The
DynamicTracingHelpernow delegates all calls through a singlegetTracingHelper()accessor that usesgetGlobalTracingHelper() ?? disabledTracingHelper. This pattern ensures consistent fallback behavior and makes the code easier to reason about.One minor observation: each method call now goes through an extra function call to
getTracingHelper(), but this is negligible overhead and provides cleaner separation of concerns.packages/instrumentation-contract/src/types.ts (5)
5-14: LGTM! Good conversion to interface withextends.Converting
ExtendedSpanOptionsfrom a type alias to an interface that extendsSpanOptionsis cleaner and provides better IDE support for interface merging if needed in the future.
35-46: LGTM! Clean interface definition.The
EngineTraceEventinterface properly defines the shape for engine trace events with appropriate type annotations for theattributesrecord.
48-51: LGTM! Concise interface definition.
EngineTracecleanly composesEngineSpan[]andEngineTraceEvent[].
53-61: LGTM! Well-defined TracingHelper contract.The
TracingHelperinterface provides a clear contract for tracing implementations with methods for checking enabled state, getting trace context, dispatching spans, and running code in child spans.
63-65: LGTM! Clean interface for global value.The
PrismaInstrumentationGlobalValueinterface correctly uses an optionalhelperproperty, allowing for the case where instrumentation is not configured.
e0dc586 to
7277f85
Compare
This restores the functionality lost in Prisma 7 / QC. Previously QE would always append the `traceparent` comments to the SQL queries when tracing was enabled, adding unnecessary overhead and prepared statement hit misses (on MySQL; we solved the problem for PostgreSQL back then by using `tokio_postgres`'s `query_typed`). Conversely, `QueryInterpreter` in QC architecture doesn't implement `traceparent` support at all, so users relying on that functionality have reduced observability. This PR makes use of the new SQL commenter plugin system to add an opt-in mechanism for appending `traceparent` comments to SQL queries only for those users who want it.
7277f85 to
4a930ce
Compare
This restores the functionality lost in Prisma 7 / QC.
Previously QE would always append the
traceparentcomments to the SQL queries when tracing was enabled, adding unnecessary overhead and prepared statement hit misses (on MySQL; we solved the problem for PostgreSQL back then by usingtokio_postgres'squery_typed).Conversely,
QueryInterpreterin QC architecture doesn't implementtraceparentsupport at all, so users relying on that functionality have reduced observability.This PR makes use of the new SQL commenter plugin system to add an opt-in mechanism for appending
traceparentcomments to SQL queries only for those users who want it.Closes: https://linear.app/prisma-company/issue/TML-899/build-trace-context-plugin
Summary by CodeRabbit
New Features
Refactor
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.