autotel-plugins 0.19.2 → 0.19.4

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.
package/dist/kafka.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SpanLink, Span, Context, SpanContext } from 'autotel';
2
- export { E as CORRELATION_ID_HEADER, C as SEMATTRS_LINKED_TRACE_ID_COUNT, D as SEMATTRS_LINKED_TRACE_ID_HASH, F as SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, w as SEMATTRS_MESSAGING_DESTINATION_NAME, G as SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, H as SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, J as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, I as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, K as SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, y as SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, B as SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, A as SEMATTRS_MESSAGING_KAFKA_OFFSET, z as SEMATTRS_MESSAGING_KAFKA_PARTITION, x as SEMATTRS_MESSAGING_OPERATION, v as SEMATTRS_MESSAGING_SYSTEM } from './constants-DoaoDYT8.cjs';
2
+ export { C as CORRELATION_ID_HEADER, t as SEMATTRS_LINKED_TRACE_ID_COUNT, u as SEMATTRS_LINKED_TRACE_ID_HASH, v as SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, x as SEMATTRS_MESSAGING_DESTINATION_NAME, y as SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, z as SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, A as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, B as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, D as SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, E as SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, F as SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, G as SEMATTRS_MESSAGING_KAFKA_OFFSET, H as SEMATTRS_MESSAGING_KAFKA_PARTITION, K as SEMATTRS_MESSAGING_OPERATION, Q as SEMATTRS_MESSAGING_SYSTEM } from './constants-DKKe2D25.cjs';
3
3
 
4
4
  /**
5
5
  * Kafka plugin types - Processing spans, batch lineage, and correlation
package/dist/kafka.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SpanLink, Span, Context, SpanContext } from 'autotel';
2
- export { E as CORRELATION_ID_HEADER, C as SEMATTRS_LINKED_TRACE_ID_COUNT, D as SEMATTRS_LINKED_TRACE_ID_HASH, F as SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, w as SEMATTRS_MESSAGING_DESTINATION_NAME, G as SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, H as SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, J as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, I as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, K as SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, y as SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, B as SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, A as SEMATTRS_MESSAGING_KAFKA_OFFSET, z as SEMATTRS_MESSAGING_KAFKA_PARTITION, x as SEMATTRS_MESSAGING_OPERATION, v as SEMATTRS_MESSAGING_SYSTEM } from './constants-DoaoDYT8.js';
2
+ export { C as CORRELATION_ID_HEADER, t as SEMATTRS_LINKED_TRACE_ID_COUNT, u as SEMATTRS_LINKED_TRACE_ID_HASH, v as SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, x as SEMATTRS_MESSAGING_DESTINATION_NAME, y as SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, z as SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, A as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, B as SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, D as SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, E as SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, F as SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, G as SEMATTRS_MESSAGING_KAFKA_OFFSET, H as SEMATTRS_MESSAGING_KAFKA_PARTITION, K as SEMATTRS_MESSAGING_OPERATION, Q as SEMATTRS_MESSAGING_SYSTEM } from './constants-DKKe2D25.js';
3
3
 
4
4
  /**
5
5
  * Kafka plugin types - Processing spans, batch lineage, and correlation
@@ -1,5 +1,5 @@
1
1
  import { SpanLink, Span, Context } from 'autotel';
2
- export { E as CORRELATION_ID_HEADER, C as SEMATTRS_LINKED_TRACE_ID_COUNT, D as SEMATTRS_LINKED_TRACE_ID_HASH, O as SEMATTRS_MESSAGING_CONSUMER_ID, w as SEMATTRS_MESSAGING_DESTINATION_NAME, N as SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, M as SEMATTRS_MESSAGING_MESSAGE_ID, L as SEMATTRS_MESSAGING_OPERATION_NAME, R as SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, Q as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, P as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, T as SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, v as SEMATTRS_MESSAGING_SYSTEM } from './constants-DoaoDYT8.cjs';
2
+ export { C as CORRELATION_ID_HEADER, t as SEMATTRS_LINKED_TRACE_ID_COUNT, u as SEMATTRS_LINKED_TRACE_ID_HASH, w as SEMATTRS_MESSAGING_CONSUMER_ID, x as SEMATTRS_MESSAGING_DESTINATION_NAME, I as SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, J as SEMATTRS_MESSAGING_MESSAGE_ID, L as SEMATTRS_MESSAGING_OPERATION_NAME, M as SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, N as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, O as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, P as SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, Q as SEMATTRS_MESSAGING_SYSTEM } from './constants-DKKe2D25.cjs';
3
3
 
4
4
  /**
5
5
  * RabbitMQ plugin types - Processing spans, ack tracking, and correlation
@@ -1,5 +1,5 @@
1
1
  import { SpanLink, Span, Context } from 'autotel';
2
- export { E as CORRELATION_ID_HEADER, C as SEMATTRS_LINKED_TRACE_ID_COUNT, D as SEMATTRS_LINKED_TRACE_ID_HASH, O as SEMATTRS_MESSAGING_CONSUMER_ID, w as SEMATTRS_MESSAGING_DESTINATION_NAME, N as SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, M as SEMATTRS_MESSAGING_MESSAGE_ID, L as SEMATTRS_MESSAGING_OPERATION_NAME, R as SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, Q as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, P as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, T as SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, v as SEMATTRS_MESSAGING_SYSTEM } from './constants-DoaoDYT8.js';
2
+ export { C as CORRELATION_ID_HEADER, t as SEMATTRS_LINKED_TRACE_ID_COUNT, u as SEMATTRS_LINKED_TRACE_ID_HASH, w as SEMATTRS_MESSAGING_CONSUMER_ID, x as SEMATTRS_MESSAGING_DESTINATION_NAME, I as SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, J as SEMATTRS_MESSAGING_MESSAGE_ID, L as SEMATTRS_MESSAGING_OPERATION_NAME, M as SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, N as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, O as SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, P as SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, Q as SEMATTRS_MESSAGING_SYSTEM } from './constants-DKKe2D25.js';
3
3
 
4
4
  /**
5
5
  * RabbitMQ plugin types - Processing spans, ack tracking, and correlation
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "autotel-plugins",
3
- "version": "0.19.2",
4
- "description": "OpenTelemetry instrumentation for libraries without official support (Drizzle ORM, Mongoose, BigQuery)",
3
+ "version": "0.19.4",
4
+ "description": "OpenTelemetry instrumentation for libraries without official support (BigQuery)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -12,16 +12,6 @@
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
14
  },
15
- "./drizzle": {
16
- "types": "./dist/drizzle.d.ts",
17
- "import": "./dist/drizzle.js",
18
- "require": "./dist/drizzle.cjs"
19
- },
20
- "./mongoose": {
21
- "types": "./dist/mongoose.d.ts",
22
- "import": "./dist/mongoose.js",
23
- "require": "./dist/mongoose.cjs"
24
- },
25
15
  "./bigquery": {
26
16
  "types": "./dist/bigquery.d.ts",
27
17
  "import": "./dist/bigquery.js",
@@ -48,10 +38,6 @@
48
38
  "otel",
49
39
  "instrumentation",
50
40
  "plugins",
51
- "drizzle",
52
- "drizzle-orm",
53
- "mongoose",
54
- "mongodb",
55
41
  "bigquery",
56
42
  "google-cloud",
57
43
  "gcp",
@@ -74,22 +60,14 @@
74
60
  "@opentelemetry/api": "^1.9.0",
75
61
  "@opentelemetry/instrumentation": "^0.213.0",
76
62
  "@opentelemetry/semantic-conventions": "^1.40.0",
77
- "autotel": "2.25.2"
63
+ "autotel": "2.25.4"
78
64
  },
79
65
  "peerDependencies": {
80
66
  "@google-cloud/bigquery": ">=8.1.1",
81
67
  "@opentelemetry/instrumentation-amqplib": ">=0.60.0",
82
- "@opentelemetry/instrumentation-kafkajs": ">=0.22.0",
83
- "drizzle-orm": ">=0.45.1",
84
- "mongoose": ">=9.3.1"
68
+ "@opentelemetry/instrumentation-kafkajs": ">=0.22.0"
85
69
  },
86
70
  "peerDependenciesMeta": {
87
- "drizzle-orm": {
88
- "optional": true
89
- },
90
- "mongoose": {
91
- "optional": true
92
- },
93
71
  "@google-cloud/bigquery": {
94
72
  "optional": true
95
73
  },
@@ -104,11 +82,9 @@
104
82
  "@arethetypeswrong/cli": "^0.18.2",
105
83
  "@google-cloud/bigquery": "^8.1.1",
106
84
  "@opentelemetry/core": "^2.6.0",
107
- "mongoose": "^9.3.1",
108
85
  "@types/node": "^25.5.0",
109
86
  "@typescript-eslint/eslint-plugin": "^8.57.1",
110
87
  "@typescript-eslint/parser": "^8.57.1",
111
- "drizzle-orm": "^0.45.1",
112
88
  "eslint-config-prettier": "^10.1.8",
113
89
  "eslint-plugin-unicorn": "^63.0.0",
114
90
  "tsup": "^8.5.1",
package/src/index.ts CHANGED
@@ -5,8 +5,6 @@
5
5
  * OR where the official support is fundamentally broken.
6
6
  *
7
7
  * Currently supported:
8
- * - Drizzle ORM (no official instrumentation available)
9
- * - Mongoose (official package broken in ESM+tsx - see mongoose/index.ts for details)
10
8
  * - BigQuery (no official instrumentation available)
11
9
  * - Kafka (composition layer for use with @opentelemetry/instrumentation-kafkajs):
12
10
  * - Processing span wrapper with context mode control (inherit/link/none)
@@ -15,8 +13,8 @@
15
13
  *
16
14
  * Philosophy:
17
15
  * Only include plugins for libraries that either:
18
- * 1. Have NO official instrumentation (e.g., Drizzle ORM)
19
- * 2. Have BROKEN official instrumentation (e.g., Mongoose in ESM+tsx)
16
+ * 1. Have NO official instrumentation (e.g., BigQuery)
17
+ * 2. Have BROKEN official instrumentation
20
18
  * 3. Add SIGNIFICANT value beyond official packages (e.g., Kafka processing spans)
21
19
  *
22
20
  * For databases/ORMs with working official instrumentation, use those directly with the --import pattern:
@@ -28,24 +26,6 @@
28
26
  *
29
27
  * See: https://github.com/open-telemetry/opentelemetry-js-contrib
30
28
  *
31
- * @example
32
- * ```typescript
33
- * // Drizzle manual instrumentation
34
- * import { instrumentDrizzleClient } from 'autotel-plugins/drizzle';
35
- * import { drizzle } from 'drizzle-orm/node-postgres';
36
- *
37
- * const db = instrumentDrizzleClient(drizzle(pool));
38
- * ```
39
- *
40
- * @example
41
- * ```typescript
42
- * // Mongoose runtime patching (works in ESM+tsx)
43
- * import mongoose from 'mongoose';
44
- * import { instrumentMongoose } from 'autotel-plugins/mongoose';
45
- *
46
- * instrumentMongoose(mongoose, { dbName: 'myapp' });
47
- * ```
48
- *
49
29
  * @packageDocumentation
50
30
  */
51
31
 
@@ -75,20 +55,6 @@ export {
75
55
  SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS,
76
56
  } from './common/constants';
77
57
 
78
- // Re-export Drizzle plugin
79
- export {
80
- instrumentDrizzle,
81
- instrumentDrizzleClient,
82
- type InstrumentDrizzleConfig,
83
- } from './drizzle';
84
-
85
- // Re-export Mongoose plugin
86
- export {
87
- instrumentMongoose,
88
- MongooseInstrumentation,
89
- type MongooseInstrumentationConfig,
90
- } from './mongoose';
91
-
92
58
  // Re-export BigQuery plugin
93
59
  export {
94
60
  instrumentBigQuery,
package/dist/drizzle.cjs DELETED
@@ -1,469 +0,0 @@
1
- 'use strict';
2
-
3
- var api = require('@opentelemetry/api');
4
- var traceHelpers = require('autotel/trace-helpers');
5
-
6
- // src/drizzle/index.ts
7
-
8
- // src/common/constants.ts
9
- var SEMATTRS_DB_SYSTEM = "db.system";
10
- var SEMATTRS_DB_OPERATION = "db.operation";
11
- var SEMATTRS_DB_STATEMENT = "db.statement";
12
- var SEMATTRS_DB_NAME = "db.name";
13
- var SEMATTRS_NET_PEER_NAME = "net.peer.name";
14
- var SEMATTRS_NET_PEER_PORT = "net.peer.port";
15
- var DEFAULT_TRACER_NAME = "autotel-plugins/drizzle";
16
- var DEFAULT_DB_SYSTEM = "postgresql";
17
- var INSTRUMENTED_FLAG = "__autotelDrizzleInstrumented";
18
- function extractQueryText(queryArg) {
19
- if (typeof queryArg === "string") {
20
- return queryArg;
21
- }
22
- if (queryArg && typeof queryArg === "object") {
23
- if (typeof queryArg.sql === "string") {
24
- return queryArg.sql;
25
- }
26
- if (typeof queryArg.text === "string") {
27
- return queryArg.text;
28
- }
29
- if (typeof queryArg.queryChunks === "object") {
30
- const drizzleQuery = queryArg;
31
- if (typeof drizzleQuery.sql === "string") {
32
- return drizzleQuery.sql;
33
- }
34
- }
35
- }
36
- return void 0;
37
- }
38
- function sanitizeQueryText(queryText, maxLength) {
39
- if (queryText.length <= maxLength) {
40
- return queryText;
41
- }
42
- return `${queryText.slice(0, Math.max(0, maxLength))}...`;
43
- }
44
- function extractOperation(queryText) {
45
- const trimmed = queryText.trimStart();
46
- const match = /^(?<op>\w+)/u.exec(trimmed);
47
- return match?.groups?.op?.toUpperCase();
48
- }
49
- function instrumentDrizzle(client, config) {
50
- if (!client) {
51
- return client;
52
- }
53
- const hasQuery = typeof client.query === "function";
54
- const hasExecute = typeof client.execute === "function";
55
- if (!hasQuery && !hasExecute) {
56
- return client;
57
- }
58
- if (client[INSTRUMENTED_FLAG]) {
59
- return client;
60
- }
61
- const {
62
- tracerName = DEFAULT_TRACER_NAME,
63
- dbSystem = DEFAULT_DB_SYSTEM,
64
- dbName,
65
- captureQueryText = true,
66
- maxQueryTextLength = 1e3,
67
- peerName,
68
- peerPort
69
- } = config ?? {};
70
- const tracer = api.trace.getTracer(tracerName);
71
- const originalMethod = hasQuery ? client.query : client.execute;
72
- if (!originalMethod) {
73
- return client;
74
- }
75
- const instrumentedMethod = function instrumented(...incomingArgs) {
76
- const args = [...incomingArgs];
77
- let callback;
78
- if (typeof args.at(-1) === "function") {
79
- callback = args.pop();
80
- }
81
- const queryText = extractQueryText(args[0]);
82
- const operation = queryText ? extractOperation(queryText) : void 0;
83
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
84
- const span = tracer.startSpan(spanName, { kind: api.SpanKind.CLIENT });
85
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
86
- if (operation) {
87
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
88
- }
89
- if (dbName) {
90
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
91
- }
92
- if (captureQueryText && queryText !== void 0) {
93
- const sanitized = sanitizeQueryText(queryText, maxQueryTextLength);
94
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
95
- }
96
- if (peerName) {
97
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
98
- }
99
- if (peerPort) {
100
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
101
- }
102
- if (callback) {
103
- return traceHelpers.runWithSpan(span, () => {
104
- const wrappedCallback = (err, result) => {
105
- traceHelpers.finalizeSpan(span, err);
106
- if (callback) {
107
- callback(err, result);
108
- }
109
- };
110
- try {
111
- return Reflect.apply(originalMethod, this, [
112
- ...args,
113
- wrappedCallback
114
- ]);
115
- } catch (error) {
116
- traceHelpers.finalizeSpan(span, error);
117
- throw error;
118
- }
119
- });
120
- }
121
- return traceHelpers.runWithSpan(span, () => {
122
- try {
123
- const result = originalMethod.apply(this, args);
124
- return Promise.resolve(result).then((value) => {
125
- traceHelpers.finalizeSpan(span);
126
- return value;
127
- }).catch((error) => {
128
- traceHelpers.finalizeSpan(span, error);
129
- throw error;
130
- });
131
- } catch (error) {
132
- traceHelpers.finalizeSpan(span, error);
133
- throw error;
134
- }
135
- });
136
- };
137
- client[INSTRUMENTED_FLAG] = true;
138
- if (hasQuery) {
139
- client.query = instrumentedMethod;
140
- } else {
141
- client.execute = instrumentedMethod;
142
- }
143
- return client;
144
- }
145
- function instrumentDrizzleClient(db, config) {
146
- if (!db) {
147
- return db;
148
- }
149
- if (db[INSTRUMENTED_FLAG]) {
150
- return db;
151
- }
152
- const {
153
- tracerName = DEFAULT_TRACER_NAME,
154
- dbSystem = DEFAULT_DB_SYSTEM,
155
- dbName,
156
- captureQueryText = true,
157
- maxQueryTextLength = 1e3,
158
- peerName,
159
- peerPort
160
- } = config ?? {};
161
- const tracer = api.trace.getTracer(tracerName);
162
- let instrumented = false;
163
- if (db.session && !instrumented) {
164
- const session = db.session;
165
- if (typeof session.prepareQuery === "function" && !session[INSTRUMENTED_FLAG]) {
166
- const originalPrepareQuery = session.prepareQuery;
167
- session.prepareQuery = function(...args) {
168
- const prepared = originalPrepareQuery.apply(this, args);
169
- if (prepared && typeof prepared.execute === "function") {
170
- const originalPreparedExecute = prepared.execute;
171
- prepared.execute = function(...executeArgs) {
172
- const queryObj = args[0];
173
- const queryText = queryObj?.sql || queryObj?.queryString || extractQueryText(queryObj);
174
- const operation = queryText ? extractOperation(queryText) : void 0;
175
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
176
- const span = tracer.startSpan(spanName, { kind: api.SpanKind.CLIENT });
177
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
178
- if (operation) {
179
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
180
- }
181
- if (dbName) {
182
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
183
- }
184
- if (captureQueryText && queryText !== void 0) {
185
- const sanitized = sanitizeQueryText(
186
- queryText,
187
- maxQueryTextLength
188
- );
189
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
190
- }
191
- if (peerName) {
192
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
193
- }
194
- if (peerPort) {
195
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
196
- }
197
- return traceHelpers.runWithSpan(span, () => {
198
- try {
199
- const result = originalPreparedExecute.apply(this, executeArgs);
200
- return Promise.resolve(result).then((value) => {
201
- traceHelpers.finalizeSpan(span);
202
- return value;
203
- }).catch((error) => {
204
- traceHelpers.finalizeSpan(span, error);
205
- throw error;
206
- });
207
- } catch (error) {
208
- traceHelpers.finalizeSpan(span, error);
209
- throw error;
210
- }
211
- });
212
- };
213
- }
214
- return prepared;
215
- };
216
- session[INSTRUMENTED_FLAG] = true;
217
- instrumented = true;
218
- }
219
- if (typeof session.query === "function" && !session[INSTRUMENTED_FLAG + "_query"]) {
220
- const originalQuery = session.query;
221
- session.query = function(queryString, params) {
222
- const operation = queryString ? extractOperation(queryString) : void 0;
223
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
224
- const span = tracer.startSpan(spanName, { kind: api.SpanKind.CLIENT });
225
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
226
- if (operation) {
227
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
228
- }
229
- if (dbName) {
230
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
231
- }
232
- if (captureQueryText && queryString !== void 0) {
233
- const sanitized = sanitizeQueryText(queryString, maxQueryTextLength);
234
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
235
- }
236
- if (peerName) {
237
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
238
- }
239
- if (peerPort) {
240
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
241
- }
242
- return traceHelpers.runWithSpan(span, () => {
243
- try {
244
- const result = Reflect.apply(originalQuery, this, [
245
- queryString,
246
- params
247
- ]);
248
- return Promise.resolve(result).then((value) => {
249
- traceHelpers.finalizeSpan(span);
250
- return value;
251
- }).catch((error) => {
252
- traceHelpers.finalizeSpan(span, error);
253
- throw error;
254
- });
255
- } catch (error) {
256
- traceHelpers.finalizeSpan(span, error);
257
- throw error;
258
- }
259
- });
260
- };
261
- session[INSTRUMENTED_FLAG + "_query"] = true;
262
- instrumented = true;
263
- }
264
- if (typeof session.transaction === "function" && !session[INSTRUMENTED_FLAG + "_transaction"]) {
265
- const originalTransaction = session.transaction;
266
- session.transaction = function(transactionCallback, ...restArgs) {
267
- const wrappedCallback = async function(tx) {
268
- if (tx && (tx.session || tx._?.session || tx)) {
269
- const txSession = tx.session || tx._?.session || tx;
270
- if (typeof tx.execute === "function" && !tx[INSTRUMENTED_FLAG + "_execute"]) {
271
- const originalTxExecute = tx.execute;
272
- tx.execute = function(...executeArgs) {
273
- const queryText = extractQueryText(executeArgs[0]);
274
- const operation = queryText ? extractOperation(queryText) : void 0;
275
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
276
- const span = tracer.startSpan(spanName, {
277
- kind: api.SpanKind.CLIENT
278
- });
279
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
280
- span.setAttribute("db.transaction", true);
281
- if (operation) {
282
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
283
- }
284
- if (dbName) {
285
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
286
- }
287
- if (captureQueryText && queryText !== void 0) {
288
- const sanitized = sanitizeQueryText(
289
- queryText,
290
- maxQueryTextLength
291
- );
292
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
293
- }
294
- if (peerName) {
295
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
296
- }
297
- if (peerPort) {
298
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
299
- }
300
- return traceHelpers.runWithSpan(span, () => {
301
- try {
302
- const result = originalTxExecute.apply(this, executeArgs);
303
- return Promise.resolve(result).then((value) => {
304
- traceHelpers.finalizeSpan(span);
305
- return value;
306
- }).catch((error) => {
307
- traceHelpers.finalizeSpan(span, error);
308
- throw error;
309
- });
310
- } catch (error) {
311
- traceHelpers.finalizeSpan(span, error);
312
- throw error;
313
- }
314
- });
315
- };
316
- tx[INSTRUMENTED_FLAG + "_execute"] = true;
317
- }
318
- if (typeof txSession.prepareQuery === "function" && !txSession[INSTRUMENTED_FLAG + "_tx"]) {
319
- const originalTxPrepareQuery = txSession.prepareQuery;
320
- txSession.prepareQuery = function(...prepareArgs) {
321
- const prepared = originalTxPrepareQuery.apply(
322
- this,
323
- prepareArgs
324
- );
325
- if (prepared && typeof prepared.execute === "function") {
326
- const originalPreparedExecute = prepared.execute;
327
- prepared.execute = function(...executeArgs) {
328
- const queryObj = prepareArgs[0];
329
- const queryText = queryObj?.sql || queryObj?.queryString || extractQueryText(queryObj);
330
- const operation = queryText ? extractOperation(queryText) : void 0;
331
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
332
- const span = tracer.startSpan(spanName, {
333
- kind: api.SpanKind.CLIENT
334
- });
335
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
336
- span.setAttribute("db.transaction", true);
337
- if (operation) {
338
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
339
- }
340
- if (dbName) {
341
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
342
- }
343
- if (captureQueryText && queryText !== void 0) {
344
- const sanitized = sanitizeQueryText(
345
- queryText,
346
- maxQueryTextLength
347
- );
348
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
349
- }
350
- if (peerName) {
351
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
352
- }
353
- if (peerPort) {
354
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
355
- }
356
- return traceHelpers.runWithSpan(span, () => {
357
- try {
358
- const result = originalPreparedExecute.apply(
359
- this,
360
- executeArgs
361
- );
362
- return Promise.resolve(result).then((value) => {
363
- traceHelpers.finalizeSpan(span);
364
- return value;
365
- }).catch((error) => {
366
- traceHelpers.finalizeSpan(span, error);
367
- throw error;
368
- });
369
- } catch (error) {
370
- traceHelpers.finalizeSpan(span, error);
371
- throw error;
372
- }
373
- });
374
- };
375
- }
376
- return prepared;
377
- };
378
- txSession[INSTRUMENTED_FLAG + "_tx"] = true;
379
- }
380
- }
381
- return transactionCallback(tx);
382
- };
383
- return Reflect.apply(originalTransaction, this, [
384
- wrappedCallback,
385
- ...restArgs
386
- ]);
387
- };
388
- session[INSTRUMENTED_FLAG + "_transaction"] = true;
389
- instrumented = true;
390
- }
391
- }
392
- if (db.$client && !instrumented) {
393
- const client = db.$client;
394
- if (typeof client.query === "function" || typeof client.execute === "function") {
395
- instrumentDrizzle(client, config);
396
- instrumented = true;
397
- }
398
- }
399
- if (db._ && db._.session && typeof db._.session.execute === "function" && !instrumented) {
400
- const session = db._.session;
401
- if (session[INSTRUMENTED_FLAG]) {
402
- return db;
403
- }
404
- const {
405
- tracerName: tracerName2 = DEFAULT_TRACER_NAME,
406
- dbSystem: dbSystem2 = DEFAULT_DB_SYSTEM,
407
- dbName: dbName2,
408
- captureQueryText: captureQueryText2 = true,
409
- maxQueryTextLength: maxQueryTextLength2 = 1e3,
410
- peerName: peerName2,
411
- peerPort: peerPort2
412
- } = config ?? {};
413
- const tracer2 = api.trace.getTracer(tracerName2);
414
- const originalExecute = session.execute;
415
- if (!originalExecute) {
416
- return db;
417
- }
418
- const instrumentedExecute = function instrumented2(...args) {
419
- const queryText = extractQueryText(args[0]);
420
- const operation = queryText ? extractOperation(queryText) : void 0;
421
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
422
- const span = tracer2.startSpan(spanName, { kind: api.SpanKind.CLIENT });
423
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem2);
424
- if (operation) {
425
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
426
- }
427
- if (dbName2) {
428
- span.setAttribute(SEMATTRS_DB_NAME, dbName2);
429
- }
430
- if (captureQueryText2 && queryText !== void 0) {
431
- const sanitized = sanitizeQueryText(queryText, maxQueryTextLength2);
432
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
433
- }
434
- if (peerName2) {
435
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName2);
436
- }
437
- if (peerPort2) {
438
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort2);
439
- }
440
- return traceHelpers.runWithSpan(span, () => {
441
- try {
442
- const result = originalExecute.apply(this, args);
443
- return Promise.resolve(result).then((value) => {
444
- traceHelpers.finalizeSpan(span);
445
- return value;
446
- }).catch((error) => {
447
- traceHelpers.finalizeSpan(span, error);
448
- throw error;
449
- });
450
- } catch (error) {
451
- traceHelpers.finalizeSpan(span, error);
452
- throw error;
453
- }
454
- });
455
- };
456
- session[INSTRUMENTED_FLAG] = true;
457
- session.execute = instrumentedExecute;
458
- instrumented = true;
459
- }
460
- if (instrumented) {
461
- db[INSTRUMENTED_FLAG] = true;
462
- }
463
- return db;
464
- }
465
-
466
- exports.instrumentDrizzle = instrumentDrizzle;
467
- exports.instrumentDrizzleClient = instrumentDrizzleClient;
468
- //# sourceMappingURL=drizzle.cjs.map
469
- //# sourceMappingURL=drizzle.cjs.map