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/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { trace, SpanKind, metrics } from '@opentelemetry/api';
2
- import { runWithSpan, finalizeSpan, getActiveSpan } from 'autotel/trace-helpers';
3
- import { otelTrace, propagation, ROOT_CONTEXT, context, SpanKind as SpanKind$1, SpanStatusCode } from 'autotel';
1
+ import { otelTrace, propagation, ROOT_CONTEXT, context, SpanKind, SpanStatusCode } from 'autotel';
2
+ import { runWithSpan, finalizeSpan } from 'autotel/trace-helpers';
3
+ import { metrics } from '@opentelemetry/api';
4
4
 
5
5
  // src/common/constants.ts
6
6
  var SEMATTRS_DB_SYSTEM = "db.system";
@@ -13,7 +13,6 @@ var SEMATTRS_DB_COLLECTION_NAME = "db.collection.name";
13
13
  var SEMATTRS_DB_OPERATION_NAME = "db.operation.name";
14
14
  var SEMATTRS_DB_QUERY_TEXT = "db.query.text";
15
15
  var SEMATTRS_DB_QUERY_SUMMARY = "db.query.summary";
16
- var SEMATTRS_DB_MONGODB_COLLECTION = "db.mongodb.collection";
17
16
  var SEMATTRS_NET_PEER_NAME = "net.peer.name";
18
17
  var SEMATTRS_NET_PEER_PORT = "net.peer.port";
19
18
  var SEMATTRS_MESSAGING_SYSTEM = "messaging.system";
@@ -50,847 +49,9 @@ var SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET = "messaging.kafka.batch.last_off
50
49
  var SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED = "messaging.kafka.batch.messages_processed";
51
50
  var SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED = "messaging.kafka.batch.messages_failed";
52
51
  var SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS = "messaging.kafka.batch.processing_time_ms";
53
- var DEFAULT_TRACER_NAME = "autotel-plugins/drizzle";
54
- var DEFAULT_DB_SYSTEM = "postgresql";
55
- var INSTRUMENTED_FLAG = "__autotelDrizzleInstrumented";
56
- function extractQueryText(queryArg) {
57
- if (typeof queryArg === "string") {
58
- return queryArg;
59
- }
60
- if (queryArg && typeof queryArg === "object") {
61
- if (typeof queryArg.sql === "string") {
62
- return queryArg.sql;
63
- }
64
- if (typeof queryArg.text === "string") {
65
- return queryArg.text;
66
- }
67
- if (typeof queryArg.queryChunks === "object") {
68
- const drizzleQuery = queryArg;
69
- if (typeof drizzleQuery.sql === "string") {
70
- return drizzleQuery.sql;
71
- }
72
- }
73
- }
74
- return void 0;
75
- }
76
- function sanitizeQueryText(queryText, maxLength) {
77
- if (queryText.length <= maxLength) {
78
- return queryText;
79
- }
80
- return `${queryText.slice(0, Math.max(0, maxLength))}...`;
81
- }
82
- function extractOperation(queryText) {
83
- const trimmed = queryText.trimStart();
84
- const match = /^(?<op>\w+)/u.exec(trimmed);
85
- return match?.groups?.op?.toUpperCase();
86
- }
87
- function instrumentDrizzle(client, config) {
88
- if (!client) {
89
- return client;
90
- }
91
- const hasQuery = typeof client.query === "function";
92
- const hasExecute = typeof client.execute === "function";
93
- if (!hasQuery && !hasExecute) {
94
- return client;
95
- }
96
- if (client[INSTRUMENTED_FLAG]) {
97
- return client;
98
- }
99
- const {
100
- tracerName = DEFAULT_TRACER_NAME,
101
- dbSystem = DEFAULT_DB_SYSTEM,
102
- dbName,
103
- captureQueryText = true,
104
- maxQueryTextLength = 1e3,
105
- peerName,
106
- peerPort
107
- } = config ?? {};
108
- const tracer = trace.getTracer(tracerName);
109
- const originalMethod = hasQuery ? client.query : client.execute;
110
- if (!originalMethod) {
111
- return client;
112
- }
113
- const instrumentedMethod = function instrumented(...incomingArgs) {
114
- const args = [...incomingArgs];
115
- let callback;
116
- if (typeof args.at(-1) === "function") {
117
- callback = args.pop();
118
- }
119
- const queryText = extractQueryText(args[0]);
120
- const operation = queryText ? extractOperation(queryText) : void 0;
121
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
122
- const span = tracer.startSpan(spanName, { kind: SpanKind.CLIENT });
123
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
124
- if (operation) {
125
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
126
- }
127
- if (dbName) {
128
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
129
- }
130
- if (captureQueryText && queryText !== void 0) {
131
- const sanitized = sanitizeQueryText(queryText, maxQueryTextLength);
132
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
133
- }
134
- if (peerName) {
135
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
136
- }
137
- if (peerPort) {
138
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
139
- }
140
- if (callback) {
141
- return runWithSpan(span, () => {
142
- const wrappedCallback = (err, result) => {
143
- finalizeSpan(span, err);
144
- if (callback) {
145
- callback(err, result);
146
- }
147
- };
148
- try {
149
- return Reflect.apply(originalMethod, this, [
150
- ...args,
151
- wrappedCallback
152
- ]);
153
- } catch (error) {
154
- finalizeSpan(span, error);
155
- throw error;
156
- }
157
- });
158
- }
159
- return runWithSpan(span, () => {
160
- try {
161
- const result = originalMethod.apply(this, args);
162
- return Promise.resolve(result).then((value) => {
163
- finalizeSpan(span);
164
- return value;
165
- }).catch((error) => {
166
- finalizeSpan(span, error);
167
- throw error;
168
- });
169
- } catch (error) {
170
- finalizeSpan(span, error);
171
- throw error;
172
- }
173
- });
174
- };
175
- client[INSTRUMENTED_FLAG] = true;
176
- if (hasQuery) {
177
- client.query = instrumentedMethod;
178
- } else {
179
- client.execute = instrumentedMethod;
180
- }
181
- return client;
182
- }
183
- function instrumentDrizzleClient(db, config) {
184
- if (!db) {
185
- return db;
186
- }
187
- if (db[INSTRUMENTED_FLAG]) {
188
- return db;
189
- }
190
- const {
191
- tracerName = DEFAULT_TRACER_NAME,
192
- dbSystem = DEFAULT_DB_SYSTEM,
193
- dbName,
194
- captureQueryText = true,
195
- maxQueryTextLength = 1e3,
196
- peerName,
197
- peerPort
198
- } = config ?? {};
199
- const tracer = trace.getTracer(tracerName);
200
- let instrumented = false;
201
- if (db.session && !instrumented) {
202
- const session = db.session;
203
- if (typeof session.prepareQuery === "function" && !session[INSTRUMENTED_FLAG]) {
204
- const originalPrepareQuery = session.prepareQuery;
205
- session.prepareQuery = function(...args) {
206
- const prepared = originalPrepareQuery.apply(this, args);
207
- if (prepared && typeof prepared.execute === "function") {
208
- const originalPreparedExecute = prepared.execute;
209
- prepared.execute = function(...executeArgs) {
210
- const queryObj = args[0];
211
- const queryText = queryObj?.sql || queryObj?.queryString || extractQueryText(queryObj);
212
- const operation = queryText ? extractOperation(queryText) : void 0;
213
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
214
- const span = tracer.startSpan(spanName, { kind: SpanKind.CLIENT });
215
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
216
- if (operation) {
217
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
218
- }
219
- if (dbName) {
220
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
221
- }
222
- if (captureQueryText && queryText !== void 0) {
223
- const sanitized = sanitizeQueryText(
224
- queryText,
225
- maxQueryTextLength
226
- );
227
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
228
- }
229
- if (peerName) {
230
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
231
- }
232
- if (peerPort) {
233
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
234
- }
235
- return runWithSpan(span, () => {
236
- try {
237
- const result = originalPreparedExecute.apply(this, executeArgs);
238
- return Promise.resolve(result).then((value) => {
239
- finalizeSpan(span);
240
- return value;
241
- }).catch((error) => {
242
- finalizeSpan(span, error);
243
- throw error;
244
- });
245
- } catch (error) {
246
- finalizeSpan(span, error);
247
- throw error;
248
- }
249
- });
250
- };
251
- }
252
- return prepared;
253
- };
254
- session[INSTRUMENTED_FLAG] = true;
255
- instrumented = true;
256
- }
257
- if (typeof session.query === "function" && !session[INSTRUMENTED_FLAG + "_query"]) {
258
- const originalQuery = session.query;
259
- session.query = function(queryString, params) {
260
- const operation = queryString ? extractOperation(queryString) : void 0;
261
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
262
- const span = tracer.startSpan(spanName, { kind: SpanKind.CLIENT });
263
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
264
- if (operation) {
265
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
266
- }
267
- if (dbName) {
268
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
269
- }
270
- if (captureQueryText && queryString !== void 0) {
271
- const sanitized = sanitizeQueryText(queryString, maxQueryTextLength);
272
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
273
- }
274
- if (peerName) {
275
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
276
- }
277
- if (peerPort) {
278
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
279
- }
280
- return runWithSpan(span, () => {
281
- try {
282
- const result = Reflect.apply(originalQuery, this, [
283
- queryString,
284
- params
285
- ]);
286
- return Promise.resolve(result).then((value) => {
287
- finalizeSpan(span);
288
- return value;
289
- }).catch((error) => {
290
- finalizeSpan(span, error);
291
- throw error;
292
- });
293
- } catch (error) {
294
- finalizeSpan(span, error);
295
- throw error;
296
- }
297
- });
298
- };
299
- session[INSTRUMENTED_FLAG + "_query"] = true;
300
- instrumented = true;
301
- }
302
- if (typeof session.transaction === "function" && !session[INSTRUMENTED_FLAG + "_transaction"]) {
303
- const originalTransaction = session.transaction;
304
- session.transaction = function(transactionCallback, ...restArgs) {
305
- const wrappedCallback = async function(tx) {
306
- if (tx && (tx.session || tx._?.session || tx)) {
307
- const txSession = tx.session || tx._?.session || tx;
308
- if (typeof tx.execute === "function" && !tx[INSTRUMENTED_FLAG + "_execute"]) {
309
- const originalTxExecute = tx.execute;
310
- tx.execute = function(...executeArgs) {
311
- const queryText = extractQueryText(executeArgs[0]);
312
- const operation = queryText ? extractOperation(queryText) : void 0;
313
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
314
- const span = tracer.startSpan(spanName, {
315
- kind: SpanKind.CLIENT
316
- });
317
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
318
- span.setAttribute("db.transaction", true);
319
- if (operation) {
320
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
321
- }
322
- if (dbName) {
323
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
324
- }
325
- if (captureQueryText && queryText !== void 0) {
326
- const sanitized = sanitizeQueryText(
327
- queryText,
328
- maxQueryTextLength
329
- );
330
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
331
- }
332
- if (peerName) {
333
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
334
- }
335
- if (peerPort) {
336
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
337
- }
338
- return runWithSpan(span, () => {
339
- try {
340
- const result = originalTxExecute.apply(this, executeArgs);
341
- return Promise.resolve(result).then((value) => {
342
- finalizeSpan(span);
343
- return value;
344
- }).catch((error) => {
345
- finalizeSpan(span, error);
346
- throw error;
347
- });
348
- } catch (error) {
349
- finalizeSpan(span, error);
350
- throw error;
351
- }
352
- });
353
- };
354
- tx[INSTRUMENTED_FLAG + "_execute"] = true;
355
- }
356
- if (typeof txSession.prepareQuery === "function" && !txSession[INSTRUMENTED_FLAG + "_tx"]) {
357
- const originalTxPrepareQuery = txSession.prepareQuery;
358
- txSession.prepareQuery = function(...prepareArgs) {
359
- const prepared = originalTxPrepareQuery.apply(
360
- this,
361
- prepareArgs
362
- );
363
- if (prepared && typeof prepared.execute === "function") {
364
- const originalPreparedExecute = prepared.execute;
365
- prepared.execute = function(...executeArgs) {
366
- const queryObj = prepareArgs[0];
367
- const queryText = queryObj?.sql || queryObj?.queryString || extractQueryText(queryObj);
368
- const operation = queryText ? extractOperation(queryText) : void 0;
369
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
370
- const span = tracer.startSpan(spanName, {
371
- kind: SpanKind.CLIENT
372
- });
373
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem);
374
- span.setAttribute("db.transaction", true);
375
- if (operation) {
376
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
377
- }
378
- if (dbName) {
379
- span.setAttribute(SEMATTRS_DB_NAME, dbName);
380
- }
381
- if (captureQueryText && queryText !== void 0) {
382
- const sanitized = sanitizeQueryText(
383
- queryText,
384
- maxQueryTextLength
385
- );
386
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
387
- }
388
- if (peerName) {
389
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName);
390
- }
391
- if (peerPort) {
392
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort);
393
- }
394
- return runWithSpan(span, () => {
395
- try {
396
- const result = originalPreparedExecute.apply(
397
- this,
398
- executeArgs
399
- );
400
- return Promise.resolve(result).then((value) => {
401
- finalizeSpan(span);
402
- return value;
403
- }).catch((error) => {
404
- finalizeSpan(span, error);
405
- throw error;
406
- });
407
- } catch (error) {
408
- finalizeSpan(span, error);
409
- throw error;
410
- }
411
- });
412
- };
413
- }
414
- return prepared;
415
- };
416
- txSession[INSTRUMENTED_FLAG + "_tx"] = true;
417
- }
418
- }
419
- return transactionCallback(tx);
420
- };
421
- return Reflect.apply(originalTransaction, this, [
422
- wrappedCallback,
423
- ...restArgs
424
- ]);
425
- };
426
- session[INSTRUMENTED_FLAG + "_transaction"] = true;
427
- instrumented = true;
428
- }
429
- }
430
- if (db.$client && !instrumented) {
431
- const client = db.$client;
432
- if (typeof client.query === "function" || typeof client.execute === "function") {
433
- instrumentDrizzle(client, config);
434
- instrumented = true;
435
- }
436
- }
437
- if (db._ && db._.session && typeof db._.session.execute === "function" && !instrumented) {
438
- const session = db._.session;
439
- if (session[INSTRUMENTED_FLAG]) {
440
- return db;
441
- }
442
- const {
443
- tracerName: tracerName2 = DEFAULT_TRACER_NAME,
444
- dbSystem: dbSystem2 = DEFAULT_DB_SYSTEM,
445
- dbName: dbName2,
446
- captureQueryText: captureQueryText2 = true,
447
- maxQueryTextLength: maxQueryTextLength2 = 1e3,
448
- peerName: peerName2,
449
- peerPort: peerPort2
450
- } = config ?? {};
451
- const tracer2 = trace.getTracer(tracerName2);
452
- const originalExecute = session.execute;
453
- if (!originalExecute) {
454
- return db;
455
- }
456
- const instrumentedExecute = function instrumented2(...args) {
457
- const queryText = extractQueryText(args[0]);
458
- const operation = queryText ? extractOperation(queryText) : void 0;
459
- const spanName = operation ? `drizzle.${operation.toLowerCase()}` : "drizzle.query";
460
- const span = tracer2.startSpan(spanName, { kind: SpanKind.CLIENT });
461
- span.setAttribute(SEMATTRS_DB_SYSTEM, dbSystem2);
462
- if (operation) {
463
- span.setAttribute(SEMATTRS_DB_OPERATION, operation);
464
- }
465
- if (dbName2) {
466
- span.setAttribute(SEMATTRS_DB_NAME, dbName2);
467
- }
468
- if (captureQueryText2 && queryText !== void 0) {
469
- const sanitized = sanitizeQueryText(queryText, maxQueryTextLength2);
470
- span.setAttribute(SEMATTRS_DB_STATEMENT, sanitized);
471
- }
472
- if (peerName2) {
473
- span.setAttribute(SEMATTRS_NET_PEER_NAME, peerName2);
474
- }
475
- if (peerPort2) {
476
- span.setAttribute(SEMATTRS_NET_PEER_PORT, peerPort2);
477
- }
478
- return runWithSpan(span, () => {
479
- try {
480
- const result = originalExecute.apply(this, args);
481
- return Promise.resolve(result).then((value) => {
482
- finalizeSpan(span);
483
- return value;
484
- }).catch((error) => {
485
- finalizeSpan(span, error);
486
- throw error;
487
- });
488
- } catch (error) {
489
- finalizeSpan(span, error);
490
- throw error;
491
- }
492
- });
493
- };
494
- session[INSTRUMENTED_FLAG] = true;
495
- session.execute = instrumentedExecute;
496
- instrumented = true;
497
- }
498
- if (instrumented) {
499
- db[INSTRUMENTED_FLAG] = true;
500
- }
501
- return db;
502
- }
503
- var DEFAULT_TRACER_NAME2 = "autotel-plugins/mongoose";
504
- var DEFAULT_DB_SYSTEM2 = "mongoose";
505
- var INSTRUMENTED_FLAG2 = "__autotelMongooseInstrumented";
506
- var WRAPPED_HOOK_FLAG = "__autotelWrappedHook";
507
- var _STORED_PARENT_SPAN = /* @__PURE__ */ Symbol("stored-parent-span");
508
- function createSpan(tracer, operation, modelName, collectionName, config) {
509
- const spanName = collectionName ? `mongoose.${collectionName}.${operation}` : modelName ? `mongoose.${modelName}.${operation}` : `mongoose.${operation}`;
510
- const attributes = {
511
- [SEMATTRS_DB_SYSTEM]: DEFAULT_DB_SYSTEM2,
512
- [SEMATTRS_DB_OPERATION]: operation
513
- };
514
- if (collectionName && config.captureCollectionName) {
515
- attributes[SEMATTRS_DB_MONGODB_COLLECTION] = collectionName;
516
- }
517
- if (config.dbName) {
518
- attributes[SEMATTRS_DB_NAME] = config.dbName;
519
- }
520
- if (config.peerName) {
521
- attributes[SEMATTRS_NET_PEER_NAME] = config.peerName;
522
- }
523
- if (config.peerPort) {
524
- attributes[SEMATTRS_NET_PEER_PORT] = config.peerPort;
525
- }
526
- return tracer.startSpan(spanName, { kind: SpanKind$1.CLIENT, attributes });
527
- }
528
- function wrapQueryMethod(target, methodName, operation, getCollectionName, getModelName, tracer, config) {
529
- const original = target[methodName];
530
- if (typeof original !== "function") {
531
- return;
532
- }
533
- target[methodName] = function instrumented(...args) {
534
- const collectionName = getCollectionName(this);
535
- const modelName = getModelName(this);
536
- const span = createSpan(
537
- tracer,
538
- operation,
539
- modelName,
540
- collectionName,
541
- config
542
- );
543
- return runWithSpan(span, () => {
544
- try {
545
- const result = original.apply(this, args);
546
- if (result && typeof result.exec === "function") {
547
- const originalExec = result.exec.bind(result);
548
- result.exec = function wrappedExec() {
549
- try {
550
- const execPromise = originalExec();
551
- return Promise.resolve(execPromise).then((value) => {
552
- finalizeSpan(span);
553
- return value;
554
- }).catch((error) => {
555
- finalizeSpan(
556
- span,
557
- error instanceof Error ? error : new Error(String(error))
558
- );
559
- throw error;
560
- });
561
- } catch (error) {
562
- finalizeSpan(
563
- span,
564
- error instanceof Error ? error : new Error(String(error))
565
- );
566
- throw error;
567
- }
568
- };
569
- return result;
570
- }
571
- if (result && typeof result.then === "function") {
572
- return Promise.resolve(result).then((value) => {
573
- finalizeSpan(span);
574
- return value;
575
- }).catch((error) => {
576
- finalizeSpan(
577
- span,
578
- error instanceof Error ? error : new Error(String(error))
579
- );
580
- throw error;
581
- });
582
- }
583
- finalizeSpan(span);
584
- return result;
585
- } catch (error) {
586
- finalizeSpan(
587
- span,
588
- error instanceof Error ? error : new Error(String(error))
589
- );
590
- throw error;
591
- }
592
- });
593
- };
594
- }
595
- function wrapChainableMethod(target, methodName) {
596
- const original = target[methodName];
597
- if (typeof original !== "function") {
598
- return;
599
- }
600
- target[methodName] = function captureContext(...args) {
601
- const currentSpan = getActiveSpan();
602
- const result = original.apply(this, args);
603
- if (result && typeof result.exec === "function") {
604
- result[_STORED_PARENT_SPAN] = currentSpan;
605
- }
606
- return result;
607
- };
608
- }
609
- function patchSchemaHooks(Schema, tracer, config) {
610
- if (!Schema?.prototype) {
611
- return;
612
- }
613
- const HOOK_FLAG = "__autotelHookInstrumented";
614
- if (Schema.prototype[HOOK_FLAG]) {
615
- return;
616
- }
617
- const originalPre = Schema.prototype.pre;
618
- if (typeof originalPre === "function") {
619
- Schema.prototype.pre = function(hookName, ...args) {
620
- const handler = typeof args[0] === "function" ? args[0] : typeof args[1] === "function" ? args[1] : null;
621
- if (handler && !isMongooseInternalHook(handler)) {
622
- const wrapped = wrapHookHandler(
623
- handler,
624
- hookName,
625
- "pre",
626
- tracer,
627
- config
628
- );
629
- if (typeof args[0] === "function") {
630
- args[0] = wrapped;
631
- } else if (typeof args[1] === "function") {
632
- args[1] = wrapped;
633
- }
634
- }
635
- return Reflect.apply(originalPre, this, [hookName, ...args]);
636
- };
637
- }
638
- const originalPost = Schema.prototype.post;
639
- if (typeof originalPost === "function") {
640
- Schema.prototype.post = function(hookName, ...args) {
641
- const handler = typeof args[0] === "function" ? args[0] : typeof args[1] === "function" ? args[1] : null;
642
- if (handler && !isMongooseInternalHook(handler)) {
643
- const wrapped = wrapHookHandler(
644
- handler,
645
- hookName,
646
- "post",
647
- tracer,
648
- config
649
- );
650
- if (typeof args[0] === "function") {
651
- args[0] = wrapped;
652
- } else if (typeof args[1] === "function") {
653
- args[1] = wrapped;
654
- }
655
- }
656
- return Reflect.apply(originalPost, this, [hookName, ...args]);
657
- };
658
- }
659
- Schema.prototype[HOOK_FLAG] = true;
660
- }
661
- function isMongooseInternalHook(handler) {
662
- if (typeof handler !== "function") {
663
- return false;
664
- }
665
- const funcName = handler.name || "";
666
- if (funcName.startsWith("_") || funcName.startsWith("$")) {
667
- return true;
668
- }
669
- const mongooseInternalNamePatterns = [
670
- "shardingPlugin",
671
- "mongooseInternalHook",
672
- "noop",
673
- "wrapped",
674
- "bound "
675
- ];
676
- if (mongooseInternalNamePatterns.some((pattern) => funcName.includes(pattern))) {
677
- return true;
678
- }
679
- try {
680
- const source = handler.toString();
681
- const mongooseInternalSourcePatterns = [
682
- "this.$__",
683
- // Mongoose internal document methods
684
- "this.$isValid",
685
- // Mongoose validation
686
- "this.$locals",
687
- // Mongoose local properties
688
- "_this.$__",
689
- // Mongoose internal with closure
690
- "schema.s.hooks",
691
- // Mongoose hooks system
692
- "kareem"
693
- // Mongoose's hooks library
694
- ];
695
- if (mongooseInternalSourcePatterns.some((pattern) => source.includes(pattern))) {
696
- return true;
697
- }
698
- } catch {
699
- }
700
- return false;
701
- }
702
- function wrapHookHandler(handler, hookName, hookType, tracer, config) {
703
- if (typeof handler !== "function") {
704
- return handler;
705
- }
706
- if (handler[WRAPPED_HOOK_FLAG]) {
707
- return handler;
708
- }
709
- const wrappedHook = function wrappedHook2(...args) {
710
- let modelName;
711
- let collectionName;
712
- try {
713
- if (this.constructor?.modelName) {
714
- modelName = this.constructor.modelName;
715
- collectionName = this.constructor.collection?.collectionName || modelName;
716
- } else if (this.model?.modelName) {
717
- modelName = this.model.modelName;
718
- collectionName = this.model.collection?.collectionName || modelName;
719
- }
720
- } catch {
721
- }
722
- const spanName = collectionName ? `mongoose.${collectionName}.${hookType}.${hookName}` : `mongoose.hook.${hookType}.${hookName}`;
723
- const span = tracer.startSpan(spanName, { kind: SpanKind$1.INTERNAL });
724
- span.setAttribute("hook.type", hookType);
725
- span.setAttribute("hook.operation", hookName);
726
- if (modelName) {
727
- span.setAttribute("hook.model", modelName);
728
- }
729
- if (collectionName && config.captureCollectionName) {
730
- span.setAttribute(SEMATTRS_DB_MONGODB_COLLECTION, collectionName);
731
- }
732
- span.setAttribute(SEMATTRS_DB_SYSTEM, DEFAULT_DB_SYSTEM2);
733
- if (config.dbName) {
734
- span.setAttribute(SEMATTRS_DB_NAME, config.dbName);
735
- }
736
- return runWithSpan(span, () => {
737
- try {
738
- const result = handler.apply(this, args);
739
- if (result && typeof result.then === "function") {
740
- return Promise.resolve(result).then((value) => {
741
- finalizeSpan(span);
742
- return value;
743
- }).catch((error) => {
744
- finalizeSpan(
745
- span,
746
- error instanceof Error ? error : new Error(String(error))
747
- );
748
- throw error;
749
- });
750
- }
751
- finalizeSpan(span);
752
- return result;
753
- } catch (error) {
754
- finalizeSpan(
755
- span,
756
- error instanceof Error ? error : new Error(String(error))
757
- );
758
- throw error;
759
- }
760
- });
761
- };
762
- wrappedHook[WRAPPED_HOOK_FLAG] = true;
763
- return wrappedHook;
764
- }
765
- function instrumentMongoose(mongoose, config) {
766
- if (!mongoose?.Model) {
767
- return mongoose;
768
- }
769
- const m = mongoose;
770
- if (m[INSTRUMENTED_FLAG2]) {
771
- return mongoose;
772
- }
773
- const finalConfig = {
774
- dbName: config?.dbName || "",
775
- peerName: config?.peerName || "",
776
- peerPort: config?.peerPort || 27017,
777
- tracerName: config?.tracerName || DEFAULT_TRACER_NAME2,
778
- captureCollectionName: config?.captureCollectionName ?? true,
779
- instrumentHooks: config?.instrumentHooks ?? false
780
- };
781
- const tracer = otelTrace.getTracer(finalConfig.tracerName);
782
- if (m.Schema && finalConfig.instrumentHooks) {
783
- patchSchemaHooks(m.Schema, tracer, finalConfig);
784
- }
785
- const getModelCollectionName = (model) => {
786
- try {
787
- return model.collection?.collectionName || model.modelName;
788
- } catch {
789
- return;
790
- }
791
- };
792
- const queryMethods = [
793
- { method: "find", operation: "find" },
794
- { method: "findOne", operation: "findOne" },
795
- { method: "findById", operation: "findById" },
796
- { method: "findOneAndUpdate", operation: "findOneAndUpdate" },
797
- { method: "findOneAndDelete", operation: "findOneAndDelete" },
798
- { method: "findOneAndReplace", operation: "findOneAndReplace" },
799
- { method: "deleteOne", operation: "deleteOne" },
800
- { method: "deleteMany", operation: "deleteMany" },
801
- { method: "updateOne", operation: "updateOne" },
802
- { method: "updateMany", operation: "updateMany" },
803
- { method: "countDocuments", operation: "countDocuments" },
804
- { method: "estimatedDocumentCount", operation: "estimatedDocumentCount" }
805
- ];
806
- for (const { method, operation } of queryMethods) {
807
- wrapQueryMethod(
808
- m.Model,
809
- method,
810
- operation,
811
- getModelCollectionName,
812
- (model) => model.modelName,
813
- tracer,
814
- finalConfig
815
- );
816
- if (m.Query?.prototype?.[method]) {
817
- wrapChainableMethod(m.Query.prototype, method);
818
- }
819
- }
820
- const instanceMethods = ["save", "deleteOne"];
821
- for (const method of instanceMethods) {
822
- if (m.Model.prototype[method]) {
823
- wrapQueryMethod(
824
- m.Model.prototype,
825
- method,
826
- method,
827
- (doc) => {
828
- try {
829
- return doc.constructor?.collection?.collectionName || doc.constructor?.modelName;
830
- } catch {
831
- return;
832
- }
833
- },
834
- (doc) => {
835
- try {
836
- return doc.constructor?.modelName;
837
- } catch {
838
- return;
839
- }
840
- },
841
- tracer,
842
- finalConfig
843
- );
844
- }
845
- }
846
- const staticMethods = ["create", "insertMany", "aggregate", "bulkWrite"];
847
- for (const method of staticMethods) {
848
- if (m.Model[method]) {
849
- wrapQueryMethod(
850
- m.Model,
851
- method,
852
- method,
853
- (model) => {
854
- try {
855
- return model.collection?.collectionName;
856
- } catch {
857
- return;
858
- }
859
- },
860
- (model) => model.modelName,
861
- tracer,
862
- finalConfig
863
- );
864
- }
865
- }
866
- const chainableMethods = [
867
- "populate",
868
- "select",
869
- "lean",
870
- "where",
871
- "sort",
872
- "limit",
873
- "skip"
874
- ];
875
- for (const method of chainableMethods) {
876
- if (m.Query?.prototype?.[method]) {
877
- wrapChainableMethod(m.Query.prototype, method);
878
- }
879
- }
880
- m[INSTRUMENTED_FLAG2] = true;
881
- return mongoose;
882
- }
883
- var MongooseInstrumentation = class {
884
- constructor(config) {
885
- this.config = config;
886
- }
887
- enable(mongoose) {
888
- instrumentMongoose(mongoose, this.config);
889
- }
890
- };
891
- var DEFAULT_TRACER_NAME3 = "autotel-plugins/bigquery";
52
+ var DEFAULT_TRACER_NAME = "autotel-plugins/bigquery";
892
53
  var DEFAULT_DB_SYSTEM_NAME = "gcp.bigquery";
893
- var INSTRUMENTED_FLAG3 = "__autotelBigQueryInstrumented";
54
+ var INSTRUMENTED_FLAG = "__autotelBigQueryInstrumented";
894
55
  var PROTOTYPE_INSTRUMENTED_FLAG = "__autotelBigQueryPrototypeInstrumented";
895
56
  var CONFIG_STORAGE_KEY = "__autotelBigQueryConfig";
896
57
  var TRACER_STORAGE_KEY = "__autotelBigQueryTracer";
@@ -1004,7 +165,7 @@ function extractTableReference(obj) {
1004
165
  return {};
1005
166
  }
1006
167
  }
1007
- function createSpan2(tracer, operationName, target, projectId, config = {}) {
168
+ function createSpan(tracer, operationName, target, projectId, config = {}) {
1008
169
  const spanName = target ? `${operationName} ${target}` : operationName;
1009
170
  const attributes = {
1010
171
  [SEMATTRS_DB_SYSTEM_NAME]: DEFAULT_DB_SYSTEM_NAME,
@@ -1016,7 +177,7 @@ function createSpan2(tracer, operationName, target, projectId, config = {}) {
1016
177
  if (config.location) {
1017
178
  attributes[SEMATTRS_GCP_BIGQUERY_JOB_LOCATION] = config.location;
1018
179
  }
1019
- return tracer.startSpan(spanName, { kind: SpanKind$1.CLIENT, attributes });
180
+ return tracer.startSpan(spanName, { kind: SpanKind.CLIENT, attributes });
1020
181
  }
1021
182
  function instrumentQueryMethod(BigQuery) {
1022
183
  const originalQuery = BigQuery.prototype.query;
@@ -1034,7 +195,7 @@ function instrumentQueryMethod(BigQuery) {
1034
195
  const location = extractLocation(this, options);
1035
196
  const operation = queryText ? extractOperationType(queryText) : "QUERY";
1036
197
  const summary = queryText ? createQuerySummary(queryText) : "QUERY";
1037
- const span = createSpan2(
198
+ const span = createSpan(
1038
199
  tracer,
1039
200
  operation || "QUERY",
1040
201
  summary,
@@ -1146,7 +307,7 @@ function instrumentCreateQueryJob(BigQuery) {
1146
307
  const location = extractLocation(this, options);
1147
308
  const operation = queryText ? extractOperationType(queryText) : "QUERY";
1148
309
  const summary = queryText ? createQuerySummary(queryText) : "QUERY";
1149
- const span = createSpan2(
310
+ const span = createSpan(
1150
311
  tracer,
1151
312
  `${operation || "QUERY"}_JOB`,
1152
313
  summary,
@@ -1232,7 +393,7 @@ function instrumentTableInsert(Table) {
1232
393
  options
1233
394
  );
1234
395
  const target = tableRef.tableId ? tableRef.datasetId ? `${tableRef.datasetId}.${tableRef.tableId}` : tableRef.tableId : void 0;
1235
- const span = createSpan2(tracer, "INSERT", target, projectId, config);
396
+ const span = createSpan(tracer, "INSERT", target, projectId, config);
1236
397
  if (location) {
1237
398
  span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
1238
399
  }
@@ -1291,7 +452,7 @@ function instrumentTableGetRows(Table) {
1291
452
  options
1292
453
  );
1293
454
  const target = tableRef.tableId ? tableRef.datasetId ? `${tableRef.datasetId}.${tableRef.tableId}` : tableRef.tableId : void 0;
1294
- const span = createSpan2(tracer, "SELECT", target, projectId, config);
455
+ const span = createSpan(tracer, "SELECT", target, projectId, config);
1295
456
  if (location) {
1296
457
  span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
1297
458
  }
@@ -1348,7 +509,7 @@ function instrumentTableCreateLoadJob(Table) {
1348
509
  metadata
1349
510
  );
1350
511
  const target = tableRef.tableId ? tableRef.datasetId ? `${tableRef.datasetId}.${tableRef.tableId}` : tableRef.tableId : void 0;
1351
- const span = createSpan2(tracer, "LOAD", target, projectId, config);
512
+ const span = createSpan(tracer, "LOAD", target, projectId, config);
1352
513
  if (location) {
1353
514
  span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
1354
515
  }
@@ -1405,7 +566,7 @@ function instrumentTableCreateCopyJob(Table) {
1405
566
  metadata
1406
567
  );
1407
568
  const source = sourceRef.tableId ? sourceRef.datasetId ? `${sourceRef.datasetId}.${sourceRef.tableId}` : sourceRef.tableId : "unknown";
1408
- const span = createSpan2(tracer, "COPY", source, projectId, config);
569
+ const span = createSpan(tracer, "COPY", source, projectId, config);
1409
570
  if (location) {
1410
571
  span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
1411
572
  }
@@ -1460,7 +621,7 @@ function instrumentTableCreateExtractJob(Table) {
1460
621
  metadata
1461
622
  );
1462
623
  const source = sourceRef.tableId ? sourceRef.datasetId ? `${sourceRef.datasetId}.${sourceRef.tableId}` : sourceRef.tableId : "unknown";
1463
- const span = createSpan2(tracer, "EXTRACT", source, projectId, config);
624
+ const span = createSpan(tracer, "EXTRACT", source, projectId, config);
1464
625
  if (location) {
1465
626
  span.setAttribute(SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, location);
1466
627
  }
@@ -1523,7 +684,7 @@ function instrumentJobGetQueryResults(Job) {
1523
684
  const jobId = this.id || this.metadata?.jobReference?.jobId;
1524
685
  const projectId = this.parent?.projectId || this.projectId;
1525
686
  const location = this.location || options?.location;
1526
- const span = createSpan2(
687
+ const span = createSpan(
1527
688
  tracer,
1528
689
  "GET_QUERY_RESULTS",
1529
690
  void 0,
@@ -1579,7 +740,7 @@ function instrumentDatasetCreate(Dataset) {
1579
740
  const datasetId = this.id;
1580
741
  const projectId = extractProjectId(this.parent);
1581
742
  const location = extractLocation(this.parent, options);
1582
- const span = createSpan2(
743
+ const span = createSpan(
1583
744
  tracer,
1584
745
  "CREATE_DATASET",
1585
746
  datasetId,
@@ -1628,7 +789,7 @@ function instrumentDatasetDelete(Dataset) {
1628
789
  }
1629
790
  const datasetId = this.id;
1630
791
  const projectId = extractProjectId(this.parent);
1631
- const span = createSpan2(
792
+ const span = createSpan(
1632
793
  tracer,
1633
794
  "DELETE_DATASET",
1634
795
  datasetId,
@@ -1675,7 +836,7 @@ function instrumentBigQueryCreateDataset(BigQuery) {
1675
836
  const datasetId = id;
1676
837
  const projectId = extractProjectId(this);
1677
838
  const location = extractLocation(this, options);
1678
- const span = createSpan2(
839
+ const span = createSpan(
1679
840
  tracer,
1680
841
  "CREATE_DATASET",
1681
842
  datasetId,
@@ -1739,7 +900,7 @@ function instrumentTableCreate(Table) {
1739
900
  const tableRef = extractTableReference(this);
1740
901
  const projectId = extractProjectId(this.dataset?.parent || this.parent);
1741
902
  const target = tableRef.tableId ? tableRef.datasetId ? `${tableRef.datasetId}.${tableRef.tableId}` : tableRef.tableId : void 0;
1742
- const span = createSpan2(tracer, "CREATE_TABLE", target, projectId, config);
903
+ const span = createSpan(tracer, "CREATE_TABLE", target, projectId, config);
1743
904
  if (tableRef.datasetId) {
1744
905
  span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
1745
906
  }
@@ -1783,7 +944,7 @@ function instrumentTableDelete(Table) {
1783
944
  const tableRef = extractTableReference(this);
1784
945
  const projectId = extractProjectId(this.dataset?.parent || this.parent);
1785
946
  const target = tableRef.tableId ? tableRef.datasetId ? `${tableRef.datasetId}.${tableRef.tableId}` : tableRef.tableId : void 0;
1786
- const span = createSpan2(tracer, "DELETE_TABLE", target, projectId, config);
947
+ const span = createSpan(tracer, "DELETE_TABLE", target, projectId, config);
1787
948
  if (tableRef.datasetId) {
1788
949
  span.setAttribute(SEMATTRS_DB_NAMESPACE, tableRef.datasetId);
1789
950
  }
@@ -1818,13 +979,13 @@ function instrumentBigQuery(bigquery, config) {
1818
979
  return bigquery;
1819
980
  }
1820
981
  const bq = bigquery;
1821
- if (bq[INSTRUMENTED_FLAG3]) {
982
+ if (bq[INSTRUMENTED_FLAG]) {
1822
983
  return bigquery;
1823
984
  }
1824
985
  const finalConfig = {
1825
986
  projectId: config?.projectId || "",
1826
987
  location: config?.location || "",
1827
- tracerName: config?.tracerName || DEFAULT_TRACER_NAME3,
988
+ tracerName: config?.tracerName || DEFAULT_TRACER_NAME,
1828
989
  captureQueryText: config?.captureQueryText || "summary",
1829
990
  maxQueryTextLength: config?.maxQueryTextLength || 1e3,
1830
991
  includeQueryHash: config?.includeQueryHash ?? true,
@@ -1878,7 +1039,7 @@ function instrumentBigQuery(bigquery, config) {
1878
1039
  }
1879
1040
  BigQuery[PROTOTYPE_INSTRUMENTED_FLAG] = true;
1880
1041
  }
1881
- bq[INSTRUMENTED_FLAG3] = true;
1042
+ bq[INSTRUMENTED_FLAG] = true;
1882
1043
  return bigquery;
1883
1044
  }
1884
1045
  var BigQueryInstrumentation = class {
@@ -1959,7 +1120,7 @@ function injectTraceHeaders(base = {}, options = {}) {
1959
1120
  }
1960
1121
  return carrier;
1961
1122
  }
1962
- var DEFAULT_TRACER_NAME4 = "autotel-plugins/kafka";
1123
+ var DEFAULT_TRACER_NAME2 = "autotel-plugins/kafka";
1963
1124
  function isValidSpanContext(spanContext) {
1964
1125
  return !!(spanContext && spanContext.traceId && spanContext.spanId && otelTrace.isSpanContextValid(spanContext));
1965
1126
  }
@@ -1975,7 +1136,7 @@ async function withProcessingSpan(descriptor, fn) {
1975
1136
  offset,
1976
1137
  key
1977
1138
  } = descriptor;
1978
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME4);
1139
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME2);
1979
1140
  const normalizedHeaders = normalizeHeaders(headers);
1980
1141
  const extractedCtx = extractTraceContext(normalizedHeaders);
1981
1142
  const extractedSpanContext = otelTrace.getSpanContext(extractedCtx);
@@ -1987,7 +1148,7 @@ async function withProcessingSpan(descriptor, fn) {
1987
1148
  const span = tracer.startSpan(
1988
1149
  name,
1989
1150
  {
1990
- kind: SpanKind$1.CONSUMER,
1151
+ kind: SpanKind.CONSUMER,
1991
1152
  links: spanLinks
1992
1153
  },
1993
1154
  parentContext
@@ -2079,12 +1240,12 @@ function setMessagingAttributes(span, attrs) {
2079
1240
  span.setAttribute(SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, key);
2080
1241
  }
2081
1242
  }
2082
- var DEFAULT_TRACER_NAME5 = "autotel-plugins/kafka";
1243
+ var DEFAULT_TRACER_NAME3 = "autotel-plugins/kafka";
2083
1244
  async function withProducerSpan(descriptor, fn) {
2084
1245
  const { name, topic, messageKey, system = "kafka" } = descriptor;
2085
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME5);
1246
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME3);
2086
1247
  const span = tracer.startSpan(name, {
2087
- kind: SpanKind$1.PRODUCER
1248
+ kind: SpanKind.PRODUCER
2088
1249
  });
2089
1250
  span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, system);
2090
1251
  span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, topic);
@@ -2193,10 +1354,10 @@ async function extractBatchLineageAsync(items, options = {}) {
2193
1354
  ...includeTraceIds && { trace_ids: traceIds }
2194
1355
  };
2195
1356
  }
2196
- var DEFAULT_TRACER_NAME6 = "autotel-plugins/kafka";
1357
+ var DEFAULT_TRACER_NAME4 = "autotel-plugins/kafka";
2197
1358
  function withBatchConsumer(config, handler) {
2198
1359
  const { name, consumerGroup, perMessageSpans = "none", onProgress } = config;
2199
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME6);
1360
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME4);
2200
1361
  return async (payload) => {
2201
1362
  const { batch } = payload;
2202
1363
  const startTime = Date.now();
@@ -2204,7 +1365,7 @@ function withBatchConsumer(config, handler) {
2204
1365
  let failed = 0;
2205
1366
  let skipped = 0;
2206
1367
  const batchSpan = tracer.startSpan(name, {
2207
- kind: SpanKind$1.CONSUMER
1368
+ kind: SpanKind.CONSUMER
2208
1369
  });
2209
1370
  setBatchAttributes(batchSpan, {
2210
1371
  topic: batch.topic,
@@ -2343,7 +1504,7 @@ function createWrappedPayload(original, perMessageSpans, tracer, parentContext,
2343
1504
  const span = tracer.startSpan(
2344
1505
  `${original.batch.topic}.${original.batch.partition}.${message.offset}`,
2345
1506
  {
2346
- kind: SpanKind$1.CONSUMER
1507
+ kind: SpanKind.CONSUMER
2347
1508
  },
2348
1509
  parentCtx
2349
1510
  );
@@ -2406,13 +1567,13 @@ function createWrappedPayload(original, perMessageSpans, tracer, parentContext,
2406
1567
  };
2407
1568
  }
2408
1569
  function createMessageErrorSpan(name, message, error, topic, partition) {
2409
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME6);
1570
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME4);
2410
1571
  const normalizedHeaders = normalizeHeaders(message.headers);
2411
1572
  const extractedCtx = extractTraceContext(normalizedHeaders);
2412
1573
  const span = tracer.startSpan(
2413
1574
  `${name}.error`,
2414
1575
  {
2415
- kind: SpanKind$1.CONSUMER
1576
+ kind: SpanKind.CONSUMER
2416
1577
  },
2417
1578
  extractedCtx
2418
1579
  );
@@ -2429,10 +1590,10 @@ function createMessageErrorSpan(name, message, error, topic, partition) {
2429
1590
  span.recordException(error);
2430
1591
  span.end();
2431
1592
  }
2432
- var DEFAULT_TRACER_NAME7 = "autotel-plugins/kafka";
1593
+ var DEFAULT_TRACER_NAME5 = "autotel-plugins/kafka";
2433
1594
  function createStreamProcessor(config) {
2434
1595
  const { name } = config;
2435
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME7);
1596
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME5);
2436
1597
  return {
2437
1598
  async run(message, callback) {
2438
1599
  const normalizedHeaders = normalizeHeaders(message.headers);
@@ -2441,7 +1602,7 @@ function createStreamProcessor(config) {
2441
1602
  const processorSpan = tracer.startSpan(
2442
1603
  name,
2443
1604
  {
2444
- kind: SpanKind$1.CONSUMER
1605
+ kind: SpanKind.CONSUMER
2445
1606
  },
2446
1607
  inputSpanContext && otelTrace.isSpanContextValid(inputSpanContext) ? extractedCtx : void 0
2447
1608
  );
@@ -2454,7 +1615,7 @@ function createStreamProcessor(config) {
2454
1615
  async stage(stageName, fn) {
2455
1616
  return context.with(processorContext, async () => {
2456
1617
  const stageSpan = tracer.startSpan(`${name}.${stageName}`, {
2457
- kind: SpanKind$1.INTERNAL
1618
+ kind: SpanKind.INTERNAL
2458
1619
  });
2459
1620
  stageSpan.setAttribute("stream.stage", stageName);
2460
1621
  const stageContext = otelTrace.setSpan(context.active(), stageSpan);
@@ -2484,7 +1645,7 @@ function createStreamProcessor(config) {
2484
1645
  links.push({ context: inputSpanContext });
2485
1646
  }
2486
1647
  const produceSpan = tracer.startSpan(`${name}.produce`, {
2487
- kind: SpanKind$1.PRODUCER,
1648
+ kind: SpanKind.PRODUCER,
2488
1649
  links
2489
1650
  });
2490
1651
  produceSpan.setAttribute(SEMATTRS_MESSAGING_SYSTEM, "kafka");
@@ -2702,7 +1863,7 @@ var ConsumerMetrics = class {
2702
1863
  }
2703
1864
  }
2704
1865
  };
2705
- var DEFAULT_TRACER_NAME8 = "autotel-plugins/kafka";
1866
+ var DEFAULT_TRACER_NAME6 = "autotel-plugins/kafka";
2706
1867
  var REBALANCE_EVENTS = [
2707
1868
  "consumer.group_join",
2708
1869
  "consumer.rebalancing",
@@ -2722,7 +1883,7 @@ function instrumentConsumerEvents(consumer, config = {}) {
2722
1883
  traceHeartbeats = false,
2723
1884
  lifecycleSpan
2724
1885
  } = config;
2725
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME8);
1886
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME6);
2726
1887
  const listeners = [];
2727
1888
  const addListener = (event, listener) => {
2728
1889
  consumer.on(event, listener);
@@ -2778,7 +1939,7 @@ function instrumentConsumerEvents(consumer, config = {}) {
2778
1939
  }
2779
1940
  function createEventSpan(tracer, eventName, payload) {
2780
1941
  const span = tracer.startSpan(`kafka.consumer.${eventName}`, {
2781
- kind: SpanKind$1.INTERNAL
1942
+ kind: SpanKind.INTERNAL
2782
1943
  });
2783
1944
  const attributes = extractEventAttributes(payload);
2784
1945
  for (const [key, value] of Object.entries(attributes)) {
@@ -2789,7 +1950,7 @@ function createEventSpan(tracer, eventName, payload) {
2789
1950
  }
2790
1951
  function createErrorSpan(tracer, eventName, payload) {
2791
1952
  const span = tracer.startSpan(`kafka.consumer.${eventName}`, {
2792
- kind: SpanKind$1.INTERNAL
1953
+ kind: SpanKind.INTERNAL
2793
1954
  });
2794
1955
  const attributes = extractEventAttributes(payload);
2795
1956
  for (const [key, value] of Object.entries(attributes)) {
@@ -2925,7 +2086,7 @@ function injectTraceHeaders2(base = {}, options = {}) {
2925
2086
  }
2926
2087
  return carrier;
2927
2088
  }
2928
- var DEFAULT_TRACER_NAME9 = "autotel-plugins/rabbitmq";
2089
+ var DEFAULT_TRACER_NAME7 = "autotel-plugins/rabbitmq";
2929
2090
  function isValidSpanContext3(spanContext) {
2930
2091
  return !!(spanContext && spanContext.traceId && spanContext.spanId && otelTrace.isSpanContextValid(spanContext));
2931
2092
  }
@@ -2950,7 +2111,7 @@ async function withConsumeSpan(descriptor, fn) {
2950
2111
  deferSpanEnd = false,
2951
2112
  ackTimeoutMs
2952
2113
  } = descriptor;
2953
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME9);
2114
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME7);
2954
2115
  const normalizedHeaders = normalizeHeaders2(headers);
2955
2116
  const extractedCtx = extractTraceContext2(normalizedHeaders);
2956
2117
  const extractedSpanContext = otelTrace.getSpanContext(extractedCtx);
@@ -2962,7 +2123,7 @@ async function withConsumeSpan(descriptor, fn) {
2962
2123
  const span = tracer.startSpan(
2963
2124
  name,
2964
2125
  {
2965
- kind: SpanKind$1.CONSUMER,
2126
+ kind: SpanKind.CONSUMER,
2966
2127
  links: spanLinks
2967
2128
  },
2968
2129
  parentContext
@@ -3124,7 +2285,7 @@ function setMessagingAttributes2(span, attrs) {
3124
2285
  span.setAttribute(SEMATTRS_MESSAGING_CONSUMER_ID, consumerTag);
3125
2286
  }
3126
2287
  }
3127
- var DEFAULT_TRACER_NAME10 = "autotel-plugins/rabbitmq";
2288
+ var DEFAULT_TRACER_NAME8 = "autotel-plugins/rabbitmq";
3128
2289
  async function withPublishSpan(descriptor, fn) {
3129
2290
  const {
3130
2291
  name,
@@ -3134,9 +2295,9 @@ async function withPublishSpan(descriptor, fn) {
3134
2295
  correlationId,
3135
2296
  system = "rabbitmq"
3136
2297
  } = descriptor;
3137
- const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME10);
2298
+ const tracer = otelTrace.getTracer(DEFAULT_TRACER_NAME8);
3138
2299
  const span = tracer.startSpan(name, {
3139
- kind: SpanKind$1.PRODUCER
2300
+ kind: SpanKind.PRODUCER
3140
2301
  });
3141
2302
  span.setAttribute(SEMATTRS_MESSAGING_SYSTEM, system);
3142
2303
  span.setAttribute(SEMATTRS_MESSAGING_DESTINATION_NAME, exchange);
@@ -3221,6 +2382,6 @@ function recordAckResult(span, result, options) {
3221
2382
  }
3222
2383
  }
3223
2384
 
3224
- export { BigQueryInstrumentation, CORRELATION_ID_HEADER, ConsumerMetrics, MongooseInstrumentation, SEMATTRS_DB_COLLECTION_NAME, SEMATTRS_DB_NAME, SEMATTRS_DB_NAMESPACE, SEMATTRS_DB_OPERATION, SEMATTRS_DB_OPERATION_NAME, SEMATTRS_DB_QUERY_SUMMARY, SEMATTRS_DB_QUERY_TEXT, SEMATTRS_DB_STATEMENT, SEMATTRS_DB_SYSTEM, SEMATTRS_DB_SYSTEM_NAME, SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, SEMATTRS_GCP_BIGQUERY_JOB_ID, SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, SEMATTRS_GCP_BIGQUERY_PROJECT_ID, SEMATTRS_GCP_BIGQUERY_QUERY_HASH, SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED, SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED, SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS, SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES, SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE, SEMATTRS_LINKED_TRACE_ID_COUNT, SEMATTRS_LINKED_TRACE_ID_HASH, SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, SEMATTRS_MESSAGING_CONSUMER_ID, SEMATTRS_MESSAGING_DESTINATION_NAME, SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, SEMATTRS_MESSAGING_KAFKA_OFFSET, SEMATTRS_MESSAGING_KAFKA_PARTITION, SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, SEMATTRS_MESSAGING_MESSAGE_ID, SEMATTRS_MESSAGING_OPERATION, SEMATTRS_MESSAGING_OPERATION_NAME, SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_NET_PEER_NAME, SEMATTRS_NET_PEER_PORT, createMessageErrorSpan, createStreamProcessor, deriveCorrelationId, deriveCorrelationId2 as deriveRabbitMQCorrelationId, extractBatchLineage, extractBatchLineageAsync, extractCorrelationId, extractBatchLineage2 as extractRabbitMQBatchLineage, extractCorrelationId2 as extractRabbitMQCorrelationId, extractTraceContext2 as extractRabbitMQTraceContext, extractTraceContext, injectTraceHeaders2 as injectRabbitMQTraceHeaders, injectTraceHeaders, instrumentBigQuery, instrumentConsumerEvents, instrumentDrizzle, instrumentDrizzleClient, instrumentMongoose, normalizeHeaders, normalizeHeaders2 as normalizeRabbitMQHeaders, recordAckResult, withBatchConsumer, withConsumeSpan, withProcessingSpan, withProducerSpan, withPublishSpan };
2385
+ export { BigQueryInstrumentation, CORRELATION_ID_HEADER, ConsumerMetrics, SEMATTRS_DB_COLLECTION_NAME, SEMATTRS_DB_NAME, SEMATTRS_DB_NAMESPACE, SEMATTRS_DB_OPERATION, SEMATTRS_DB_OPERATION_NAME, SEMATTRS_DB_QUERY_SUMMARY, SEMATTRS_DB_QUERY_TEXT, SEMATTRS_DB_STATEMENT, SEMATTRS_DB_SYSTEM, SEMATTRS_DB_SYSTEM_NAME, SEMATTRS_GCP_BIGQUERY_DESTINATION_TABLE, SEMATTRS_GCP_BIGQUERY_JOB_ID, SEMATTRS_GCP_BIGQUERY_JOB_LOCATION, SEMATTRS_GCP_BIGQUERY_PROJECT_ID, SEMATTRS_GCP_BIGQUERY_QUERY_HASH, SEMATTRS_GCP_BIGQUERY_ROWS_AFFECTED, SEMATTRS_GCP_BIGQUERY_ROWS_RETURNED, SEMATTRS_GCP_BIGQUERY_SCHEMA_FIELDS, SEMATTRS_GCP_BIGQUERY_SOURCE_TABLES, SEMATTRS_GCP_BIGQUERY_STATEMENT_TYPE, SEMATTRS_LINKED_TRACE_ID_COUNT, SEMATTRS_LINKED_TRACE_ID_HASH, SEMATTRS_MESSAGING_BATCH_MESSAGE_COUNT, SEMATTRS_MESSAGING_CONSUMER_ID, SEMATTRS_MESSAGING_DESTINATION_NAME, SEMATTRS_MESSAGING_KAFKA_BATCH_FIRST_OFFSET, SEMATTRS_MESSAGING_KAFKA_BATCH_LAST_OFFSET, SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_FAILED, SEMATTRS_MESSAGING_KAFKA_BATCH_MESSAGES_PROCESSED, SEMATTRS_MESSAGING_KAFKA_BATCH_PROCESSING_TIME_MS, SEMATTRS_MESSAGING_KAFKA_CONSUMER_GROUP, SEMATTRS_MESSAGING_KAFKA_MESSAGE_KEY, SEMATTRS_MESSAGING_KAFKA_OFFSET, SEMATTRS_MESSAGING_KAFKA_PARTITION, SEMATTRS_MESSAGING_MESSAGE_CONVERSATION_ID, SEMATTRS_MESSAGING_MESSAGE_ID, SEMATTRS_MESSAGING_OPERATION, SEMATTRS_MESSAGING_OPERATION_NAME, SEMATTRS_MESSAGING_RABBITMQ_ACK_RESULT, SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_EXCHANGE, SEMATTRS_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, SEMATTRS_MESSAGING_RABBITMQ_REQUEUE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_NET_PEER_NAME, SEMATTRS_NET_PEER_PORT, createMessageErrorSpan, createStreamProcessor, deriveCorrelationId, deriveCorrelationId2 as deriveRabbitMQCorrelationId, extractBatchLineage, extractBatchLineageAsync, extractCorrelationId, extractBatchLineage2 as extractRabbitMQBatchLineage, extractCorrelationId2 as extractRabbitMQCorrelationId, extractTraceContext2 as extractRabbitMQTraceContext, extractTraceContext, injectTraceHeaders2 as injectRabbitMQTraceHeaders, injectTraceHeaders, instrumentBigQuery, instrumentConsumerEvents, normalizeHeaders, normalizeHeaders2 as normalizeRabbitMQHeaders, recordAckResult, withBatchConsumer, withConsumeSpan, withProcessingSpan, withProducerSpan, withPublishSpan };
3225
2386
  //# sourceMappingURL=index.js.map
3226
2387
  //# sourceMappingURL=index.js.map