@prisma/instrumentation 6.7.0-dev.3 → 6.7.0-dev.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,10 +16,136 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/ActiveTracingHelper.ts
19
21
  var ActiveTracingHelper_exports = {};
20
22
  __export(ActiveTracingHelper_exports, {
21
- ActiveTracingHelper: () => import_chunk_LJTRIVKN.ActiveTracingHelper
23
+ ActiveTracingHelper: () => ActiveTracingHelper
22
24
  });
23
25
  module.exports = __toCommonJS(ActiveTracingHelper_exports);
24
- var import_chunk_LJTRIVKN = require("./chunk-LJTRIVKN.js");
25
- var import_chunk_FTA5RKYX = require("./chunk-FTA5RKYX.js");
26
+ var import_api = require("@opentelemetry/api");
27
+ var showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === "true";
28
+ var nonSampledTraceParent = `00-10-10-00`;
29
+ function engineSpanKindToOtelSpanKind(engineSpanKind) {
30
+ switch (engineSpanKind) {
31
+ case "client":
32
+ return import_api.SpanKind.CLIENT;
33
+ case "internal":
34
+ default:
35
+ return import_api.SpanKind.INTERNAL;
36
+ }
37
+ }
38
+ var ActiveTracingHelper = class {
39
+ traceMiddleware;
40
+ tracerProvider;
41
+ ignoreSpanTypes;
42
+ constructor({ traceMiddleware, tracerProvider, ignoreSpanTypes }) {
43
+ this.traceMiddleware = traceMiddleware;
44
+ this.tracerProvider = tracerProvider;
45
+ this.ignoreSpanTypes = ignoreSpanTypes;
46
+ }
47
+ isEnabled() {
48
+ return true;
49
+ }
50
+ getTraceParent(context) {
51
+ const span = import_api.trace.getSpanContext(context ?? import_api.context.active());
52
+ if (span) {
53
+ return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;
54
+ }
55
+ return nonSampledTraceParent;
56
+ }
57
+ dispatchEngineSpans(spans) {
58
+ const tracer = this.tracerProvider.getTracer("prisma");
59
+ const linkIds = /* @__PURE__ */ new Map();
60
+ const roots = spans.filter((span) => span.parentId === null);
61
+ for (const root of roots) {
62
+ dispatchEngineSpan(tracer, root, spans, linkIds, this.ignoreSpanTypes);
63
+ }
64
+ }
65
+ getActiveContext() {
66
+ return import_api.context.active();
67
+ }
68
+ runInChildSpan(options, callback) {
69
+ if (typeof options === "string") {
70
+ options = { name: options };
71
+ }
72
+ if (options.internal && !showAllTraces) {
73
+ return callback();
74
+ }
75
+ if (options.middleware && !this.traceMiddleware) {
76
+ return callback();
77
+ }
78
+ const tracer = this.tracerProvider.getTracer("prisma");
79
+ const context = options.context ?? this.getActiveContext();
80
+ const name = `prisma:client:${options.name}`;
81
+ if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {
82
+ return callback();
83
+ }
84
+ if (options.active === false) {
85
+ const span = tracer.startSpan(name, options, context);
86
+ return endSpan(span, callback(span, context));
87
+ }
88
+ return tracer.startActiveSpan(name, options, (span) => endSpan(span, callback(span, context)));
89
+ }
90
+ };
91
+ function dispatchEngineSpan(tracer, engineSpan, allSpans, linkIds, ignoreSpanTypes) {
92
+ if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return;
93
+ const spanOptions = {
94
+ attributes: engineSpan.attributes,
95
+ kind: engineSpanKindToOtelSpanKind(engineSpan.kind),
96
+ startTime: engineSpan.startTime
97
+ };
98
+ tracer.startActiveSpan(engineSpan.name, spanOptions, (span) => {
99
+ linkIds.set(engineSpan.id, span.spanContext().spanId);
100
+ if (engineSpan.links) {
101
+ span.addLinks(
102
+ engineSpan.links.flatMap((link) => {
103
+ const linkedId = linkIds.get(link);
104
+ if (!linkedId) {
105
+ return [];
106
+ }
107
+ return {
108
+ context: {
109
+ spanId: linkedId,
110
+ traceId: span.spanContext().traceId,
111
+ traceFlags: span.spanContext().traceFlags
112
+ }
113
+ };
114
+ })
115
+ );
116
+ }
117
+ const children = allSpans.filter((s) => s.parentId === engineSpan.id);
118
+ for (const child of children) {
119
+ dispatchEngineSpan(tracer, child, allSpans, linkIds, ignoreSpanTypes);
120
+ }
121
+ span.end(engineSpan.endTime);
122
+ });
123
+ }
124
+ function endSpan(span, result) {
125
+ if (isPromiseLike(result)) {
126
+ return result.then(
127
+ (value) => {
128
+ span.end();
129
+ return value;
130
+ },
131
+ (reason) => {
132
+ span.end();
133
+ throw reason;
134
+ }
135
+ );
136
+ }
137
+ span.end();
138
+ return result;
139
+ }
140
+ function isPromiseLike(value) {
141
+ return value != null && typeof value["then"] === "function";
142
+ }
143
+ function shouldIgnoreSpan(spanName, ignoreSpanTypes) {
144
+ return ignoreSpanTypes.some(
145
+ (pattern) => typeof pattern === "string" ? pattern === spanName : pattern.test(spanName)
146
+ );
147
+ }
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ ActiveTracingHelper
151
+ });
@@ -1,36 +1,18 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_LJTRIVKN_exports = {};
20
- __export(chunk_LJTRIVKN_exports, {
21
- ActiveTracingHelper: () => ActiveTracingHelper
22
- });
23
- module.exports = __toCommonJS(chunk_LJTRIVKN_exports);
24
- var import_api = require("@opentelemetry/api");
1
+ // src/ActiveTracingHelper.ts
2
+ import {
3
+ context as _context,
4
+ SpanKind,
5
+ trace
6
+ } from "@opentelemetry/api";
25
7
  var showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === "true";
26
8
  var nonSampledTraceParent = `00-10-10-00`;
27
9
  function engineSpanKindToOtelSpanKind(engineSpanKind) {
28
10
  switch (engineSpanKind) {
29
11
  case "client":
30
- return import_api.SpanKind.CLIENT;
12
+ return SpanKind.CLIENT;
31
13
  case "internal":
32
14
  default:
33
- return import_api.SpanKind.INTERNAL;
15
+ return SpanKind.INTERNAL;
34
16
  }
35
17
  }
36
18
  var ActiveTracingHelper = class {
@@ -46,7 +28,7 @@ var ActiveTracingHelper = class {
46
28
  return true;
47
29
  }
48
30
  getTraceParent(context) {
49
- const span = import_api.trace.getSpanContext(context ?? import_api.context.active());
31
+ const span = trace.getSpanContext(context ?? _context.active());
50
32
  if (span) {
51
33
  return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;
52
34
  }
@@ -61,7 +43,7 @@ var ActiveTracingHelper = class {
61
43
  }
62
44
  }
63
45
  getActiveContext() {
64
- return import_api.context.active();
46
+ return _context.active();
65
47
  }
66
48
  runInChildSpan(options, callback) {
67
49
  if (typeof options === "string") {
@@ -143,3 +125,6 @@ function shouldIgnoreSpan(spanName, ignoreSpanTypes) {
143
125
  (pattern) => typeof pattern === "string" ? pattern === spanName : pattern.test(spanName)
144
126
  );
145
127
  }
128
+ export {
129
+ ActiveTracingHelper
130
+ };
@@ -16,12 +16,232 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/PrismaInstrumentation.ts
19
21
  var PrismaInstrumentation_exports = {};
20
22
  __export(PrismaInstrumentation_exports, {
21
- PrismaInstrumentation: () => import_chunk_JJ4ISOH3.PrismaInstrumentation
23
+ PrismaInstrumentation: () => PrismaInstrumentation
22
24
  });
23
25
  module.exports = __toCommonJS(PrismaInstrumentation_exports);
24
- var import_chunk_JJ4ISOH3 = require("./chunk-JJ4ISOH3.js");
25
- var import_chunk_LJTRIVKN = require("./chunk-LJTRIVKN.js");
26
- var import_chunk_H4HWKSI2 = require("./chunk-H4HWKSI2.js");
27
- var import_chunk_FTA5RKYX = require("./chunk-FTA5RKYX.js");
26
+ var import_api2 = require("@opentelemetry/api");
27
+ var import_instrumentation = require("@opentelemetry/instrumentation");
28
+
29
+ // src/ActiveTracingHelper.ts
30
+ var import_api = require("@opentelemetry/api");
31
+ var showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === "true";
32
+ var nonSampledTraceParent = `00-10-10-00`;
33
+ function engineSpanKindToOtelSpanKind(engineSpanKind) {
34
+ switch (engineSpanKind) {
35
+ case "client":
36
+ return import_api.SpanKind.CLIENT;
37
+ case "internal":
38
+ default:
39
+ return import_api.SpanKind.INTERNAL;
40
+ }
41
+ }
42
+ var ActiveTracingHelper = class {
43
+ traceMiddleware;
44
+ tracerProvider;
45
+ ignoreSpanTypes;
46
+ constructor({ traceMiddleware, tracerProvider, ignoreSpanTypes }) {
47
+ this.traceMiddleware = traceMiddleware;
48
+ this.tracerProvider = tracerProvider;
49
+ this.ignoreSpanTypes = ignoreSpanTypes;
50
+ }
51
+ isEnabled() {
52
+ return true;
53
+ }
54
+ getTraceParent(context) {
55
+ const span = import_api.trace.getSpanContext(context ?? import_api.context.active());
56
+ if (span) {
57
+ return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;
58
+ }
59
+ return nonSampledTraceParent;
60
+ }
61
+ dispatchEngineSpans(spans) {
62
+ const tracer = this.tracerProvider.getTracer("prisma");
63
+ const linkIds = /* @__PURE__ */ new Map();
64
+ const roots = spans.filter((span) => span.parentId === null);
65
+ for (const root of roots) {
66
+ dispatchEngineSpan(tracer, root, spans, linkIds, this.ignoreSpanTypes);
67
+ }
68
+ }
69
+ getActiveContext() {
70
+ return import_api.context.active();
71
+ }
72
+ runInChildSpan(options, callback) {
73
+ if (typeof options === "string") {
74
+ options = { name: options };
75
+ }
76
+ if (options.internal && !showAllTraces) {
77
+ return callback();
78
+ }
79
+ if (options.middleware && !this.traceMiddleware) {
80
+ return callback();
81
+ }
82
+ const tracer = this.tracerProvider.getTracer("prisma");
83
+ const context = options.context ?? this.getActiveContext();
84
+ const name = `prisma:client:${options.name}`;
85
+ if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {
86
+ return callback();
87
+ }
88
+ if (options.active === false) {
89
+ const span = tracer.startSpan(name, options, context);
90
+ return endSpan(span, callback(span, context));
91
+ }
92
+ return tracer.startActiveSpan(name, options, (span) => endSpan(span, callback(span, context)));
93
+ }
94
+ };
95
+ function dispatchEngineSpan(tracer, engineSpan, allSpans, linkIds, ignoreSpanTypes) {
96
+ if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return;
97
+ const spanOptions = {
98
+ attributes: engineSpan.attributes,
99
+ kind: engineSpanKindToOtelSpanKind(engineSpan.kind),
100
+ startTime: engineSpan.startTime
101
+ };
102
+ tracer.startActiveSpan(engineSpan.name, spanOptions, (span) => {
103
+ linkIds.set(engineSpan.id, span.spanContext().spanId);
104
+ if (engineSpan.links) {
105
+ span.addLinks(
106
+ engineSpan.links.flatMap((link) => {
107
+ const linkedId = linkIds.get(link);
108
+ if (!linkedId) {
109
+ return [];
110
+ }
111
+ return {
112
+ context: {
113
+ spanId: linkedId,
114
+ traceId: span.spanContext().traceId,
115
+ traceFlags: span.spanContext().traceFlags
116
+ }
117
+ };
118
+ })
119
+ );
120
+ }
121
+ const children = allSpans.filter((s) => s.parentId === engineSpan.id);
122
+ for (const child of children) {
123
+ dispatchEngineSpan(tracer, child, allSpans, linkIds, ignoreSpanTypes);
124
+ }
125
+ span.end(engineSpan.endTime);
126
+ });
127
+ }
128
+ function endSpan(span, result) {
129
+ if (isPromiseLike(result)) {
130
+ return result.then(
131
+ (value) => {
132
+ span.end();
133
+ return value;
134
+ },
135
+ (reason) => {
136
+ span.end();
137
+ throw reason;
138
+ }
139
+ );
140
+ }
141
+ span.end();
142
+ return result;
143
+ }
144
+ function isPromiseLike(value) {
145
+ return value != null && typeof value["then"] === "function";
146
+ }
147
+ function shouldIgnoreSpan(spanName, ignoreSpanTypes) {
148
+ return ignoreSpanTypes.some(
149
+ (pattern) => typeof pattern === "string" ? pattern === spanName : pattern.test(spanName)
150
+ );
151
+ }
152
+
153
+ // package.json
154
+ var package_default = {
155
+ name: "@prisma/instrumentation",
156
+ version: "6.7.0-dev.30",
157
+ description: "OpenTelemetry compliant instrumentation for Prisma Client",
158
+ main: "dist/index.js",
159
+ module: "dist/index.mjs",
160
+ types: "dist/index.d.ts",
161
+ license: "Apache-2.0",
162
+ homepage: "https://www.prisma.io",
163
+ repository: {
164
+ type: "git",
165
+ url: "https://github.com/prisma/prisma.git",
166
+ directory: "packages/instrumentation"
167
+ },
168
+ bugs: "https://github.com/prisma/prisma/issues",
169
+ devDependencies: {
170
+ "@prisma/internals": "workspace:*",
171
+ "@swc/core": "1.11.5",
172
+ "@types/jest": "29.5.14",
173
+ "@types/node": "18.19.76",
174
+ "@opentelemetry/api": "1.9.0",
175
+ jest: "29.7.0",
176
+ "jest-junit": "16.0.0",
177
+ typescript: "5.4.5"
178
+ },
179
+ dependencies: {
180
+ "@opentelemetry/instrumentation": "^0.52.0 || ^0.53.0 || ^0.54.0 || ^0.55.0 || ^0.56.0 || ^0.57.0"
181
+ },
182
+ peerDependencies: {
183
+ "@opentelemetry/api": "^1.8"
184
+ },
185
+ files: [
186
+ "dist"
187
+ ],
188
+ keywords: [
189
+ "prisma",
190
+ "instrumentation",
191
+ "opentelemetry",
192
+ "otel"
193
+ ],
194
+ scripts: {
195
+ dev: "DEV=true tsx helpers/build.ts",
196
+ build: "tsx helpers/build.ts",
197
+ prepublishOnly: "pnpm run build",
198
+ test: "jest"
199
+ },
200
+ sideEffects: false
201
+ };
202
+
203
+ // src/constants.ts
204
+ var VERSION = package_default.version;
205
+ var majorVersion = VERSION.split(".")[0];
206
+ var GLOBAL_INSTRUMENTATION_ACCESSOR_KEY = "PRISMA_INSTRUMENTATION";
207
+ var GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY = `V${majorVersion}_PRISMA_INSTRUMENTATION`;
208
+ var NAME = package_default.name;
209
+ var MODULE_NAME = "@prisma/client";
210
+
211
+ // src/PrismaInstrumentation.ts
212
+ var PrismaInstrumentation = class extends import_instrumentation.InstrumentationBase {
213
+ tracerProvider;
214
+ constructor(config = {}) {
215
+ super(NAME, VERSION, config);
216
+ }
217
+ setTracerProvider(tracerProvider) {
218
+ this.tracerProvider = tracerProvider;
219
+ }
220
+ init() {
221
+ const module2 = new import_instrumentation.InstrumentationNodeModuleDefinition(MODULE_NAME, [VERSION]);
222
+ return [module2];
223
+ }
224
+ enable() {
225
+ const config = this._config;
226
+ const globalValue = {
227
+ helper: new ActiveTracingHelper({
228
+ traceMiddleware: config.middleware ?? false,
229
+ tracerProvider: this.tracerProvider ?? import_api2.trace.getTracerProvider(),
230
+ ignoreSpanTypes: config.ignoreSpanTypes ?? []
231
+ })
232
+ };
233
+ global[GLOBAL_INSTRUMENTATION_ACCESSOR_KEY] = globalValue;
234
+ global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY] = globalValue;
235
+ }
236
+ disable() {
237
+ delete global[GLOBAL_INSTRUMENTATION_ACCESSOR_KEY];
238
+ delete global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY];
239
+ }
240
+ isEnabled() {
241
+ return Boolean(global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY]);
242
+ }
243
+ };
244
+ // Annotate the CommonJS export names for ESM import in node:
245
+ 0 && (module.exports = {
246
+ PrismaInstrumentation
247
+ });
@@ -0,0 +1,229 @@
1
+ // src/PrismaInstrumentation.ts
2
+ import { trace as trace2 } from "@opentelemetry/api";
3
+ import {
4
+ InstrumentationBase,
5
+ InstrumentationNodeModuleDefinition
6
+ } from "@opentelemetry/instrumentation";
7
+
8
+ // src/ActiveTracingHelper.ts
9
+ import {
10
+ context as _context,
11
+ SpanKind,
12
+ trace
13
+ } from "@opentelemetry/api";
14
+ var showAllTraces = process.env.PRISMA_SHOW_ALL_TRACES === "true";
15
+ var nonSampledTraceParent = `00-10-10-00`;
16
+ function engineSpanKindToOtelSpanKind(engineSpanKind) {
17
+ switch (engineSpanKind) {
18
+ case "client":
19
+ return SpanKind.CLIENT;
20
+ case "internal":
21
+ default:
22
+ return SpanKind.INTERNAL;
23
+ }
24
+ }
25
+ var ActiveTracingHelper = class {
26
+ traceMiddleware;
27
+ tracerProvider;
28
+ ignoreSpanTypes;
29
+ constructor({ traceMiddleware, tracerProvider, ignoreSpanTypes }) {
30
+ this.traceMiddleware = traceMiddleware;
31
+ this.tracerProvider = tracerProvider;
32
+ this.ignoreSpanTypes = ignoreSpanTypes;
33
+ }
34
+ isEnabled() {
35
+ return true;
36
+ }
37
+ getTraceParent(context) {
38
+ const span = trace.getSpanContext(context ?? _context.active());
39
+ if (span) {
40
+ return `00-${span.traceId}-${span.spanId}-0${span.traceFlags}`;
41
+ }
42
+ return nonSampledTraceParent;
43
+ }
44
+ dispatchEngineSpans(spans) {
45
+ const tracer = this.tracerProvider.getTracer("prisma");
46
+ const linkIds = /* @__PURE__ */ new Map();
47
+ const roots = spans.filter((span) => span.parentId === null);
48
+ for (const root of roots) {
49
+ dispatchEngineSpan(tracer, root, spans, linkIds, this.ignoreSpanTypes);
50
+ }
51
+ }
52
+ getActiveContext() {
53
+ return _context.active();
54
+ }
55
+ runInChildSpan(options, callback) {
56
+ if (typeof options === "string") {
57
+ options = { name: options };
58
+ }
59
+ if (options.internal && !showAllTraces) {
60
+ return callback();
61
+ }
62
+ if (options.middleware && !this.traceMiddleware) {
63
+ return callback();
64
+ }
65
+ const tracer = this.tracerProvider.getTracer("prisma");
66
+ const context = options.context ?? this.getActiveContext();
67
+ const name = `prisma:client:${options.name}`;
68
+ if (shouldIgnoreSpan(name, this.ignoreSpanTypes)) {
69
+ return callback();
70
+ }
71
+ if (options.active === false) {
72
+ const span = tracer.startSpan(name, options, context);
73
+ return endSpan(span, callback(span, context));
74
+ }
75
+ return tracer.startActiveSpan(name, options, (span) => endSpan(span, callback(span, context)));
76
+ }
77
+ };
78
+ function dispatchEngineSpan(tracer, engineSpan, allSpans, linkIds, ignoreSpanTypes) {
79
+ if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return;
80
+ const spanOptions = {
81
+ attributes: engineSpan.attributes,
82
+ kind: engineSpanKindToOtelSpanKind(engineSpan.kind),
83
+ startTime: engineSpan.startTime
84
+ };
85
+ tracer.startActiveSpan(engineSpan.name, spanOptions, (span) => {
86
+ linkIds.set(engineSpan.id, span.spanContext().spanId);
87
+ if (engineSpan.links) {
88
+ span.addLinks(
89
+ engineSpan.links.flatMap((link) => {
90
+ const linkedId = linkIds.get(link);
91
+ if (!linkedId) {
92
+ return [];
93
+ }
94
+ return {
95
+ context: {
96
+ spanId: linkedId,
97
+ traceId: span.spanContext().traceId,
98
+ traceFlags: span.spanContext().traceFlags
99
+ }
100
+ };
101
+ })
102
+ );
103
+ }
104
+ const children = allSpans.filter((s) => s.parentId === engineSpan.id);
105
+ for (const child of children) {
106
+ dispatchEngineSpan(tracer, child, allSpans, linkIds, ignoreSpanTypes);
107
+ }
108
+ span.end(engineSpan.endTime);
109
+ });
110
+ }
111
+ function endSpan(span, result) {
112
+ if (isPromiseLike(result)) {
113
+ return result.then(
114
+ (value) => {
115
+ span.end();
116
+ return value;
117
+ },
118
+ (reason) => {
119
+ span.end();
120
+ throw reason;
121
+ }
122
+ );
123
+ }
124
+ span.end();
125
+ return result;
126
+ }
127
+ function isPromiseLike(value) {
128
+ return value != null && typeof value["then"] === "function";
129
+ }
130
+ function shouldIgnoreSpan(spanName, ignoreSpanTypes) {
131
+ return ignoreSpanTypes.some(
132
+ (pattern) => typeof pattern === "string" ? pattern === spanName : pattern.test(spanName)
133
+ );
134
+ }
135
+
136
+ // package.json
137
+ var package_default = {
138
+ name: "@prisma/instrumentation",
139
+ version: "6.7.0-dev.30",
140
+ description: "OpenTelemetry compliant instrumentation for Prisma Client",
141
+ main: "dist/index.js",
142
+ module: "dist/index.mjs",
143
+ types: "dist/index.d.ts",
144
+ license: "Apache-2.0",
145
+ homepage: "https://www.prisma.io",
146
+ repository: {
147
+ type: "git",
148
+ url: "https://github.com/prisma/prisma.git",
149
+ directory: "packages/instrumentation"
150
+ },
151
+ bugs: "https://github.com/prisma/prisma/issues",
152
+ devDependencies: {
153
+ "@prisma/internals": "workspace:*",
154
+ "@swc/core": "1.11.5",
155
+ "@types/jest": "29.5.14",
156
+ "@types/node": "18.19.76",
157
+ "@opentelemetry/api": "1.9.0",
158
+ jest: "29.7.0",
159
+ "jest-junit": "16.0.0",
160
+ typescript: "5.4.5"
161
+ },
162
+ dependencies: {
163
+ "@opentelemetry/instrumentation": "^0.52.0 || ^0.53.0 || ^0.54.0 || ^0.55.0 || ^0.56.0 || ^0.57.0"
164
+ },
165
+ peerDependencies: {
166
+ "@opentelemetry/api": "^1.8"
167
+ },
168
+ files: [
169
+ "dist"
170
+ ],
171
+ keywords: [
172
+ "prisma",
173
+ "instrumentation",
174
+ "opentelemetry",
175
+ "otel"
176
+ ],
177
+ scripts: {
178
+ dev: "DEV=true tsx helpers/build.ts",
179
+ build: "tsx helpers/build.ts",
180
+ prepublishOnly: "pnpm run build",
181
+ test: "jest"
182
+ },
183
+ sideEffects: false
184
+ };
185
+
186
+ // src/constants.ts
187
+ var VERSION = package_default.version;
188
+ var majorVersion = VERSION.split(".")[0];
189
+ var GLOBAL_INSTRUMENTATION_ACCESSOR_KEY = "PRISMA_INSTRUMENTATION";
190
+ var GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY = `V${majorVersion}_PRISMA_INSTRUMENTATION`;
191
+ var NAME = package_default.name;
192
+ var MODULE_NAME = "@prisma/client";
193
+
194
+ // src/PrismaInstrumentation.ts
195
+ var PrismaInstrumentation = class extends InstrumentationBase {
196
+ tracerProvider;
197
+ constructor(config = {}) {
198
+ super(NAME, VERSION, config);
199
+ }
200
+ setTracerProvider(tracerProvider) {
201
+ this.tracerProvider = tracerProvider;
202
+ }
203
+ init() {
204
+ const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, [VERSION]);
205
+ return [module];
206
+ }
207
+ enable() {
208
+ const config = this._config;
209
+ const globalValue = {
210
+ helper: new ActiveTracingHelper({
211
+ traceMiddleware: config.middleware ?? false,
212
+ tracerProvider: this.tracerProvider ?? trace2.getTracerProvider(),
213
+ ignoreSpanTypes: config.ignoreSpanTypes ?? []
214
+ })
215
+ };
216
+ global[GLOBAL_INSTRUMENTATION_ACCESSOR_KEY] = globalValue;
217
+ global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY] = globalValue;
218
+ }
219
+ disable() {
220
+ delete global[GLOBAL_INSTRUMENTATION_ACCESSOR_KEY];
221
+ delete global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY];
222
+ }
223
+ isEnabled() {
224
+ return Boolean(global[GLOBAL_VERSIONED_INSTRUMENTATION_ACCESSOR_KEY]);
225
+ }
226
+ };
227
+ export {
228
+ PrismaInstrumentation
229
+ };