Skip to content

feat: add traceContext SQL commenter plugin#28802

Merged
aqrln merged 1 commit intomainfrom
aqrln-wqorwwlqwxwx
Dec 3, 2025
Merged

feat: add traceContext SQL commenter plugin#28802
aqrln merged 1 commit intomainfrom
aqrln-wqorwwlqwxwx

Conversation

@aqrln
Copy link
Copy Markdown
Member

@aqrln aqrln commented Dec 1, 2025

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.

Closes: https://linear.app/prisma-company/issue/TML-899/build-trace-context-plugin

Summary by CodeRabbit

  • New Features

    • Added SQL Commenter Trace Context plugin to include W3C traceparent in sampled queries
    • Added an instrumentation-contract package exposing get/set/clear global tracing helpers
    • Prisma client can opt into query comments via a new comments initialization option
  • Refactor

    • Centralized tracing helper management to use the new contract-based global accessors
  • Tests

    • Added unit and end-to-end tests validating trace-context behavior and global helper integration
  • Chores

    • CI updated to run additional test suites

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 1, 2025

size-limit report 📦

Path Size
packages/client/runtime/index-browser.js 2.23 KB (0%)
packages/client/runtime/index-browser.d.ts 3.28 KB (0%)
packages/cli/build/index.js 2.51 MB (+0.01% 🔺)
packages/client/prisma-client-0.0.0.tgz 10.23 MB (-0.04% 🔽)
packages/cli/prisma-0.0.0.tgz 6.71 MB (+0.01% 🔺)
packages/bundle-size/da-workers-libsql/output.tgz 805.07 KB (-0.07% 🔽)
packages/bundle-size/da-workers-neon/output.tgz 858.75 KB (-0.07% 🔽)
packages/bundle-size/da-workers-pg/output.tgz 851.69 KB (-0.07% 🔽)
packages/bundle-size/da-workers-planetscale/output.tgz 804.45 KB (-0.07% 🔽)
packages/bundle-size/da-workers-d1/output.tgz 787.98 KB (-0.07% 🔽)

@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 011cc8b to 9cde6bc Compare December 1, 2025 21:52
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from 0f90c48 to 00b22fd Compare December 1, 2025 21:56
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 9cde6bc to a1cfbc6 Compare December 1, 2025 21:56
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from 00b22fd to c97117e Compare December 1, 2025 22:30
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch 2 times, most recently from 92afb54 to ae6ba74 Compare December 1, 2025 22:32
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from c97117e to 7ff0e2b Compare December 1, 2025 22:32
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from ae6ba74 to da4346e Compare December 1, 2025 23:13
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from 7ff0e2b to a6dd535 Compare December 1, 2025 23:13
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from da4346e to 0023078 Compare December 2, 2025 07:55
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch 2 times, most recently from 28c3171 to a42141a Compare December 2, 2025 09:47
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 0023078 to 3e0c34f Compare December 2, 2025 09:48
@aqrln aqrln added this to the 7.1.0 milestone Dec 2, 2025
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch 2 times, most recently from 0d39245 to a517780 Compare December 2, 2025 15:12
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from a42141a to 34970da Compare December 2, 2025 15:12
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch 2 times, most recently from 92fafd0 to 57e72a3 Compare December 3, 2025 00:06
@aqrln aqrln marked this pull request as ready for review December 3, 2025 08:55
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 57e72a3 to 8c583e0 Compare December 3, 2025 10:20
@aqrln aqrln force-pushed the aqrln-noumkwownoot branch from 34970da to 023c294 Compare December 3, 2025 10:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 3, 2025

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between d6a6c11 and 4a930ce.

⛔ Files ignored due to path filters (4)
  • packages/client/tests/e2e/sqlcommenter-query-tags/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/client/tests/e2e/sqlcommenter-trace-context/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/client/tests/e2e/sqlcommenter/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (46)
  • .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-query-tags/package.json (1 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)

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds 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

Cohort / File(s) Change Summary
New package: instrumentation-contract
packages/instrumentation-contract/package.json, packages/instrumentation-contract/tsconfig.json, packages/instrumentation-contract/tsconfig.build.json, packages/instrumentation-contract/helpers/build.ts, packages/instrumentation-contract/src/index.ts, packages/instrumentation-contract/src/global.ts, packages/instrumentation-contract/src/types.ts, packages/instrumentation-contract/src/global.test.ts, packages/instrumentation-contract/README.md
Adds @prisma/instrumentation-contract with types/interfaces, getGlobalTracingHelper/setGlobalTracingHelper/clearGlobalTracingHelper, tests, README, and build config; removes prior global augmentation and converts several types to interfaces.
New package: sqlcommenter-trace-context
packages/sqlcommenter-trace-context/package.json, packages/sqlcommenter-trace-context/tsconfig.json, packages/sqlcommenter-trace-context/tsconfig.build.json, packages/sqlcommenter-trace-context/helpers/build.ts, packages/sqlcommenter-trace-context/src/index.ts, packages/sqlcommenter-trace-context/src/index.test.ts, packages/sqlcommenter-trace-context/README.md
Adds @prisma/sqlcommenter-trace-context plugin implementing traceContext() to include W3C traceparent in SQL comments when tracing is enabled and sampled, with unit tests and build setup.
Client runtime updates & tests
packages/client/package.json, packages/client/src/runtime/**, packages/client/tests/e2e/sqlcommenter-trace-context/*, packages/client/tests/functional/**
Switches tracing type imports to @prisma/instrumentation-contract, replaces in-file global tracing logic with contract accessors in tracing helper code, adds e2e test for sqlcommenter trace context, and opts functional tests into traceContext() comments.
Instrumentation package refactor
packages/instrumentation/package.json, packages/instrumentation/src/PrismaInstrumentation.ts, packages/instrumentation/src/ActiveTracingHelper.ts, packages/instrumentation/src/PrismaInstrumentation.test.ts, packages/instrumentation/src/constants.ts, packages/instrumentation/tsconfig.build.json
Replaces direct global key usage with contract accessors (set/get/clear global tracing helper), removes exported global key constants and internal majorVersion, updates tests and devDependency to use the contract package, and excludes tests from build.
Internals cleanup
packages/internals/src/index.ts
Removes re-export of tracing types from internals.
Build and monorepo adjustments
tsconfig.build.bundle.json, .github/workflows/test-template.yml
Adds path aliases for the new packages and CI test steps for instrumentation-contract and sqlcommenter-trace-context.
Tests updated/removed
packages/instrumentation/src/__tests__/PrismaInstrumentation.test.ts (deleted), updated tests under packages/instrumentation/src and packages/instrumentation-contract/src, packages/sqlcommenter-trace-context/src/index.test.ts, packages/client/tests/e2e/...
Removes legacy instrumentation tests, adds new contract/global helper tests and plugin/unit/e2e tests; updates test flows to manage global tracing helper via contract accessors.

Sequence Diagram

sequenceDiagram
    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()
Loading

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature being added: an opt-in SQL commenter plugin for trace context. It aligns with the PR's primary objective of restoring traceparent comment functionality.

Comment @coderabbitai help to get the list of available commands and usage tips.

@aqrln aqrln changed the base branch from aqrln-noumkwownoot to main December 3, 2025 10:21
Copilot AI review requested due to automatic review settings December 3, 2025 10:21
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 8c583e0 to d6a6c11 Compare December 3, 2025 10:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-contract package containing shared types and global helper functions for tracing integration
  • Implemented @prisma/sqlcommenter-trace-context plugin that appends W3C Trace Context traceparent headers to SQL queries when tracing is enabled and sampled
  • Refactored @prisma/instrumentation and @prisma/client to 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 new DynamicTracingHelper instance. 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 DynamicTracingHelper is stateless and the overhead is minimal, this is purely optional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32ac485 and d6a6c11.

⛔ Files ignored due to path filters (4)
  • packages/client/tests/e2e/sqlcommenter-query-tags/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/client/tests/e2e/sqlcommenter-trace-context/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • packages/client/tests/e2e/sqlcommenter/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • pnpm-lock.yaml is 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.ts
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/instrumentation/src/PrismaInstrumentation.test.ts
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/sqlcommenter-trace-context/src/index.test.ts
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/instrumentation-contract/src/global.ts
  • packages/sqlcommenter-trace-context/helpers/build.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/instrumentation-contract/src/types.ts
  • packages/instrumentation-contract/src/global.test.ts
  • packages/instrumentation/src/PrismaInstrumentation.ts
  • packages/instrumentation/src/ActiveTracingHelper.ts
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.ts
  • packages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.ts
  • packages/instrumentation-contract/helpers/build.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/client/src/runtime/core/engines/common/Engine.ts
  • packages/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 PrismaClientOptions in packages/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.json under compilerOptions.paths with 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.ts naming 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.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/sqlcommenter-trace-context/src/index.test.ts
  • packages/instrumentation-contract/src/global.test.ts
packages/*/helpers/build.ts

📄 CodeRabbit inference engine (AGENTS.md)

packages/*/helpers/build.ts: For new packages, add a helpers/build.ts file to configure the build process
Use adapterConfig from helpers/compile/configs.ts for type-only packages to bundle to both CJS and ESM with type declarations

Files:

  • packages/sqlcommenter-trace-context/helpers/build.ts
  • packages/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 EngineConfig interface in packages/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.json
  • packages/sqlcommenter-trace-context/tsconfig.build.json
  • tsconfig.build.bundle.json
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/instrumentation/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/sqlcommenter-trace-context/package.json
  • packages/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.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/package.json
  • packages/sqlcommenter-trace-context/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/sqlcommenter-trace-context/package.json
  • packages/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.json
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/sqlcommenter-trace-context/tsconfig.build.json
  • tsconfig.build.bundle.json
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/instrumentation/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/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.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/package.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/_steps.cts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma
  • tsconfig.build.bundle.json
  • packages/instrumentation/src/PrismaInstrumentation.test.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/instrumentation-contract/tsconfig.build.json
  • .github/workflows/test-template.yml
  • packages/instrumentation/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/sqlcommenter-trace-context/src/index.test.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/client/tests/functional/0-legacy-ports/batch-find-unique/tests.ts
  • packages/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.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/package.json
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/sqlcommenter-trace-context/tsconfig.build.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma
  • tsconfig.build.bundle.json
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/instrumentation/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/sqlcommenter-trace-context/helpers/build.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/sqlcommenter-trace-context/package.json
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/instrumentation-contract/helpers/build.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/client/package.json
  • packages/instrumentation/package.json
  • packages/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.json
  • packages/sqlcommenter-trace-context/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.build.json
  • .github/workflows/test-template.yml
  • packages/instrumentation/tsconfig.build.json
  • packages/instrumentation-contract/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/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.json
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma
  • tsconfig.build.bundle.json
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/instrumentation-contract/src/types.ts
  • packages/instrumentation/src/PrismaInstrumentation.ts
  • packages/instrumentation/src/ActiveTracingHelper.ts
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/instrumentation-contract/helpers/build.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/client/package.json
  • packages/instrumentation/package.json
  • packages/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.json
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma/schema.prisma
  • tsconfig.build.bundle.json
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/instrumentation-contract/src/types.ts
  • packages/instrumentation/src/PrismaInstrumentation.ts
  • packages/instrumentation/src/ActiveTracingHelper.ts
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/instrumentation-contract/helpers/build.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/client/package.json
  • packages/instrumentation/package.json
  • packages/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.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/_steps.cts
  • .github/workflows/test-template.yml
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/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.cts
  • packages/client/tests/e2e/sqlcommenter-trace-context/readme.md
  • packages/instrumentation/src/PrismaInstrumentation.test.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • .github/workflows/test-template.yml
  • packages/client/src/runtime/core/tracing/TracingHelper.test.ts
  • packages/sqlcommenter-trace-context/src/index.test.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/instrumentation-contract/src/global.test.ts
  • packages/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.cts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/instrumentation/tsconfig.build.json
  • packages/sqlcommenter-trace-context/src/index.test.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/client/tests/e2e/sqlcommenter-trace-context/src/index.ts
  • packages/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.cts
  • packages/client/src/runtime/getPrismaClient.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/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.ts
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/instrumentation-contract/src/types.ts
  • packages/instrumentation/src/ActiveTracingHelper.ts
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/client/package.json
  • packages/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.ts
  • tsconfig.build.bundle.json
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/src/runtime/core/engines/common/types/QueryEngine.ts
  • packages/instrumentation-contract/src/types.ts
  • packages/instrumentation/src/PrismaInstrumentation.ts
  • packages/instrumentation/src/ActiveTracingHelper.ts
  • packages/client/src/runtime/core/engines/accelerate/HeaderBuilder.ts
  • packages/client/src/runtime/core/tracing/TracingHelper.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/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.ts
  • packages/client/src/runtime/core/engines/client/RemoteExecutor.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/prisma.config.ts
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/tests/functional/tracing-no-sampling/tests.ts
  • packages/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.json
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/sqlcommenter-trace-context/helpers/build.ts
  • packages/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.json
  • tsconfig.build.bundle.json
  • packages/instrumentation-contract/tsconfig.build.json
  • packages/sqlcommenter-trace-context/helpers/build.ts
  • packages/client/tests/e2e/sqlcommenter-trace-context/tsconfig.json
  • packages/instrumentation-contract/helpers/build.ts
  • packages/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.ts
  • packages/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.ts
  • packages/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.ts
  • packages/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.json and the required companion tsconfig.build.json, following the standard pattern used across the monorepo. The root tsconfig.build.bundle.json has already been updated with the correct resolution path for @prisma/sqlcommenter-trace-context pointing 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 url is appropriate since it's configured via prisma.config.ts in 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 include tsconfig.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.ts files 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 adapterConfig from helpers/compile/configs.ts for 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/api as an external dependency, which isn't easily supported by adapterConfig. The dual-output approach (CJS with types, ESM) provides broad compatibility. The use of satisfies BuildOptions ensures 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.8 peer 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 TracingHelper has been correctly updated from @prisma/internals to @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 environments
packages/client/src/runtime/core/engines/client/RemoteExecutor.ts (1)

5-5: LGTM! Type imports updated to instrumentation-contract.

The import source for EngineTraceEvent and TracingHelper has been correctly updated from @prisma/internals to @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 TracingHelper as a type-only symbol from @prisma/instrumentation-contract
  • Keep assertNever as 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/internals to @prisma/instrumentation-contract correctly 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-contract is appropriate since EngineSpan and EngineTraceEvent are 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 beforeEach and afterEach for 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-contract and @prisma/sqlcommenter-trace-context are properly configured, enabling editor go-to-definition support for the new workspace packages.

Based on coding guidelines, this update to tsconfig.build.bundle.json is 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 ExtendedSpanOptions and TracingHelper as type-only from @prisma/instrumentation-contract
  • Preserves runtime import of logger from @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 the comments option validates that:

  • The new plugin is properly integrated
  • With 0% sampling, no traceparent is 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-contract is 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 beforeEach hook 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 TracingHelper interface and global helper functions align with the described contract and expected usage; just ensure this stays updated if types.ts evolves.

.github/workflows/test-template.yml (1)

935-938: CI wiring for new packages looks consistent.

Adding pnpm run test for instrumentation-contract and sqlcommenter-trace-context in both others and no-docker jobs, with the same if guards 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 zx correctly with executeSteps.

packages/instrumentation-contract/src/index.ts (1)

1-2: Public entrypoint re-exports are appropriate.

Re-exporting ./global and ./types from 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 the EngineConfig.tracingHelper API 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, /tmp Prisma tarballs, OTel deps, and onlyBuiltDependencies: ["better-sqlite3"]) matches the standard setup for client e2e scenarios and should work fine with the new _steps.cts flow.

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) runs prisma.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 isNaN check
  • 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 beforeEach and afterEach hooks 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:

  1. The helper picks up a globally set tracing helper
  2. After clearing, the system falls back to the disabled helper (traceparent ending in 00)

The tests align well with the new @prisma/instrumentation-contract API.

packages/instrumentation/src/PrismaInstrumentation.ts (1)

39-56: LGTM! Clean refactor to centralized global helper API.

The implementation correctly:

  • Uses setGlobalTracingHelper() to register the ActiveTracingHelper when enabling
  • Uses clearGlobalTracingHelper() to remove the helper when disabling
  • Uses getGlobalTracingHelper() !== undefined to check enabled state

This 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: true setting is present in tsconfig.build.regular.json (the base configuration) and properly inherited by packages/instrumentation-contract/tsconfig.json through the configuration chain. The import of package.json on line 1 will work as expected.

packages/sqlcommenter-trace-context/src/index.test.ts (6)

1-16: LGTM! Well-structured mock helper factory.

The createMockTracingHelper factory provides good defaults while allowing targeted overrides for individual tests. The interface implementation is complete and matches the TracingHelper contract from @prisma/instrumentation-contract.


18-27: LGTM! Mock context is minimal and appropriate.

The mock context correctly matches the SqlCommenterContext shape required by the plugin.


29-36: LGTM! Proper test isolation with global state cleanup.

Using both beforeEach and afterEach to 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 traceparent
  • 00 (not sampled) returns empty
  • 03 (sampled bit set in flags with other bits) returns traceparent
  • 02 (other bits set, sampled bit not set) returns empty

This 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 isSampled function 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/enable at 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-contract package, which aligns with the PR objective of introducing a contract-based interface.


37-59: Good refactor to centralize global helper access.

The DynamicTracingHelper now delegates all calls through a single getTracingHelper() accessor that uses getGlobalTracingHelper() ?? 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 with extends.

Converting ExtendedSpanOptions from a type alias to an interface that extends SpanOptions is cleaner and provides better IDE support for interface merging if needed in the future.


35-46: LGTM! Clean interface definition.

The EngineTraceEvent interface properly defines the shape for engine trace events with appropriate type annotations for the attributes record.


48-51: LGTM! Concise interface definition.

EngineTrace cleanly composes EngineSpan[] and EngineTraceEvent[].


53-61: LGTM! Well-defined TracingHelper contract.

The TracingHelper interface 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 PrismaInstrumentationGlobalValue interface correctly uses an optional helper property, allowing for the case where instrumentation is not configured.

@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch 2 times, most recently from e0dc586 to 7277f85 Compare December 3, 2025 10:50
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.
@aqrln aqrln force-pushed the aqrln-wqorwwlqwxwx branch from 7277f85 to 4a930ce Compare December 3, 2025 10:55
@aqrln aqrln merged commit d00dc11 into main Dec 3, 2025
255 of 256 checks passed
@aqrln aqrln deleted the aqrln-wqorwwlqwxwx branch December 3, 2025 11:35
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.

3 participants