autotel 2.25.2 → 2.25.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.
Files changed (135) hide show
  1. package/README.md +152 -1
  2. package/dist/attributes.d.cts +2 -2
  3. package/dist/attributes.d.ts +2 -2
  4. package/dist/auto.cjs +6 -6
  5. package/dist/auto.js +4 -4
  6. package/dist/{chunk-BGVKKL2N.cjs → chunk-7FIGORWI.cjs} +46 -2
  7. package/dist/chunk-7FIGORWI.cjs.map +1 -0
  8. package/dist/{chunk-4KGC5N3J.cjs → chunk-A5ZUL2RZ.cjs} +16 -16
  9. package/dist/{chunk-4KGC5N3J.cjs.map → chunk-A5ZUL2RZ.cjs.map} +1 -1
  10. package/dist/{chunk-SR35DG5A.js → chunk-BBBWDIYQ.js} +27 -13
  11. package/dist/chunk-BBBWDIYQ.js.map +1 -0
  12. package/dist/{chunk-QUW4I2OI.js → chunk-CMUM4JQI.js} +3 -3
  13. package/dist/{chunk-QUW4I2OI.js.map → chunk-CMUM4JQI.js.map} +1 -1
  14. package/dist/{chunk-MNMLCLHH.cjs → chunk-EEJGUBWV.cjs} +5 -5
  15. package/dist/{chunk-MNMLCLHH.cjs.map → chunk-EEJGUBWV.cjs.map} +1 -1
  16. package/dist/{chunk-W4EUTSB2.cjs → chunk-HZ3FYBJG.cjs} +27 -12
  17. package/dist/chunk-HZ3FYBJG.cjs.map +1 -0
  18. package/dist/{chunk-L627YSSP.cjs → chunk-I6JPSD4R.cjs} +9 -9
  19. package/dist/{chunk-L627YSSP.cjs.map → chunk-I6JPSD4R.cjs.map} +1 -1
  20. package/dist/{chunk-JVICEM6W.cjs → chunk-ITYASFHQ.cjs} +91 -19
  21. package/dist/chunk-ITYASFHQ.cjs.map +1 -0
  22. package/dist/{chunk-XRKAL7WJ.cjs → chunk-JSNUWSBH.cjs} +6 -6
  23. package/dist/chunk-JSNUWSBH.cjs.map +1 -0
  24. package/dist/{chunk-GVLK7YUU.cjs → chunk-KZEC4CHV.cjs} +6 -4
  25. package/dist/chunk-KZEC4CHV.cjs.map +1 -0
  26. package/dist/{chunk-UKUYBUFQ.cjs → chunk-MN6PZ4AN.cjs} +7 -7
  27. package/dist/{chunk-UKUYBUFQ.cjs.map → chunk-MN6PZ4AN.cjs.map} +1 -1
  28. package/dist/{chunk-VXLEJWLY.js → chunk-MNBAXRVG.js} +89 -17
  29. package/dist/chunk-MNBAXRVG.js.map +1 -0
  30. package/dist/{chunk-6YIDHH2S.cjs → chunk-OFPZULMQ.cjs} +32 -10
  31. package/dist/chunk-OFPZULMQ.cjs.map +1 -0
  32. package/dist/{chunk-IKRHEUS7.js → chunk-OPTGXEVN.js} +370 -351
  33. package/dist/chunk-OPTGXEVN.js.map +1 -0
  34. package/dist/{chunk-77PLEJ54.js → chunk-QDREXAD7.js} +4 -4
  35. package/dist/{chunk-77PLEJ54.js.map → chunk-QDREXAD7.js.map} +1 -1
  36. package/dist/{chunk-RWOVNF3V.cjs → chunk-QQLP4M6W.cjs} +400 -381
  37. package/dist/chunk-QQLP4M6W.cjs.map +1 -0
  38. package/dist/{chunk-YTGF4L2C.js → chunk-RUD7KS4R.js} +27 -5
  39. package/dist/chunk-RUD7KS4R.js.map +1 -0
  40. package/dist/{chunk-USSL3D6L.js → chunk-S4OFEXLA.js} +6 -6
  41. package/dist/chunk-S4OFEXLA.js.map +1 -0
  42. package/dist/{chunk-XND7WBVX.js → chunk-VYA6QDNA.js} +43 -3
  43. package/dist/chunk-VYA6QDNA.js.map +1 -0
  44. package/dist/{chunk-KUSYIHW7.js → chunk-WYP6OOCT.js} +3 -3
  45. package/dist/{chunk-KUSYIHW7.js.map → chunk-WYP6OOCT.js.map} +1 -1
  46. package/dist/{chunk-4SCBD22Z.js → chunk-XB2GITM5.js} +4 -4
  47. package/dist/{chunk-4SCBD22Z.js.map → chunk-XB2GITM5.js.map} +1 -1
  48. package/dist/{chunk-X4RMFFMR.js → chunk-XDKK53OL.js} +6 -4
  49. package/dist/chunk-XDKK53OL.js.map +1 -0
  50. package/dist/correlation-id.cjs +10 -9
  51. package/dist/correlation-id.d.cts +4 -1
  52. package/dist/correlation-id.d.ts +4 -1
  53. package/dist/correlation-id.js +2 -1
  54. package/dist/decorators.cjs +8 -8
  55. package/dist/decorators.js +7 -7
  56. package/dist/event.cjs +10 -9
  57. package/dist/event.js +7 -6
  58. package/dist/functional.cjs +14 -14
  59. package/dist/functional.js +7 -7
  60. package/dist/http.cjs +2 -2
  61. package/dist/http.js +1 -1
  62. package/dist/index.cjs +85 -65
  63. package/dist/index.d.cts +4 -4
  64. package/dist/index.d.ts +4 -4
  65. package/dist/index.js +16 -16
  66. package/dist/{init-Q4uIQKbq.d.cts → init-CIzpC5kZ.d.cts} +9 -2
  67. package/dist/{init-ls4xSZe5.d.ts → init-C_PiC_Su.d.ts} +9 -2
  68. package/dist/instrumentation.cjs +12 -12
  69. package/dist/instrumentation.cjs.map +1 -1
  70. package/dist/instrumentation.js +4 -4
  71. package/dist/instrumentation.js.map +1 -1
  72. package/dist/messaging-adapters.d.cts +1 -1
  73. package/dist/messaging-adapters.d.ts +1 -1
  74. package/dist/messaging.cjs +11 -11
  75. package/dist/messaging.d.cts +1 -1
  76. package/dist/messaging.d.ts +1 -1
  77. package/dist/messaging.js +8 -8
  78. package/dist/metric-helpers.d.cts +1 -1
  79. package/dist/metric-helpers.d.ts +1 -1
  80. package/dist/sampling.cjs +26 -10
  81. package/dist/sampling.d.cts +49 -1
  82. package/dist/sampling.d.ts +49 -1
  83. package/dist/sampling.js +1 -1
  84. package/dist/semantic-helpers.cjs +12 -12
  85. package/dist/semantic-helpers.js +8 -8
  86. package/dist/tail-sampling-processor.cjs +6 -2
  87. package/dist/tail-sampling-processor.d.cts +2 -2
  88. package/dist/tail-sampling-processor.d.ts +2 -2
  89. package/dist/tail-sampling-processor.js +5 -1
  90. package/dist/trace-helpers.d.cts +1 -1
  91. package/dist/trace-helpers.d.ts +1 -1
  92. package/dist/{utils-D1trOLNm.d.ts → utils-Buel3cj0.d.ts} +1 -1
  93. package/dist/{utils-DuNJfXSH.d.cts → utils-CbUkl8r1.d.cts} +1 -1
  94. package/dist/webhook.cjs +8 -8
  95. package/dist/webhook.js +7 -7
  96. package/dist/workflow-distributed.cjs +9 -9
  97. package/dist/workflow-distributed.js +7 -7
  98. package/dist/workflow.cjs +12 -12
  99. package/dist/workflow.js +8 -8
  100. package/dist/yaml-config.cjs +5 -5
  101. package/dist/yaml-config.d.cts +5 -4
  102. package/dist/yaml-config.d.ts +5 -4
  103. package/dist/yaml-config.js +2 -2
  104. package/package.json +1 -1
  105. package/src/correlation-id.ts +10 -5
  106. package/src/env-config.test.ts +77 -0
  107. package/src/env-config.ts +106 -0
  108. package/src/functional.ts +447 -421
  109. package/src/index.ts +6 -0
  110. package/src/init.customization.test.ts +61 -0
  111. package/src/init.integrations.test.ts +6 -1
  112. package/src/init.ts +23 -13
  113. package/src/instrumentation.ts +1 -1
  114. package/src/sampling.test.ts +96 -3
  115. package/src/sampling.ts +90 -0
  116. package/src/tail-sampling-processor.test.ts +26 -22
  117. package/src/tail-sampling-processor.ts +8 -4
  118. package/src/trace-context.test.ts +73 -0
  119. package/src/trace-context.ts +44 -12
  120. package/src/yaml-config.test.ts +71 -0
  121. package/src/yaml-config.ts +32 -2
  122. package/dist/chunk-6YIDHH2S.cjs.map +0 -1
  123. package/dist/chunk-BGVKKL2N.cjs.map +0 -1
  124. package/dist/chunk-GVLK7YUU.cjs.map +0 -1
  125. package/dist/chunk-IKRHEUS7.js.map +0 -1
  126. package/dist/chunk-JVICEM6W.cjs.map +0 -1
  127. package/dist/chunk-RWOVNF3V.cjs.map +0 -1
  128. package/dist/chunk-SR35DG5A.js.map +0 -1
  129. package/dist/chunk-USSL3D6L.js.map +0 -1
  130. package/dist/chunk-VXLEJWLY.js.map +0 -1
  131. package/dist/chunk-W4EUTSB2.cjs.map +0 -1
  132. package/dist/chunk-X4RMFFMR.js.map +0 -1
  133. package/dist/chunk-XND7WBVX.js.map +0 -1
  134. package/dist/chunk-XRKAL7WJ.cjs.map +0 -1
  135. package/dist/chunk-YTGF4L2C.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkW4EUTSB2_cjs = require('./chunk-W4EUTSB2.cjs');
4
3
  var chunkGML3FBOT_cjs = require('./chunk-GML3FBOT.cjs');
5
4
  var chunkD5LMF53P_cjs = require('./chunk-D5LMF53P.cjs');
6
- var chunkXRKAL7WJ_cjs = require('./chunk-XRKAL7WJ.cjs');
7
- var chunkJVICEM6W_cjs = require('./chunk-JVICEM6W.cjs');
8
- var chunkBGVKKL2N_cjs = require('./chunk-BGVKKL2N.cjs');
5
+ var chunkJSNUWSBH_cjs = require('./chunk-JSNUWSBH.cjs');
6
+ var chunkHZ3FYBJG_cjs = require('./chunk-HZ3FYBJG.cjs');
7
+ var chunkITYASFHQ_cjs = require('./chunk-ITYASFHQ.cjs');
8
+ var chunk7FIGORWI_cjs = require('./chunk-7FIGORWI.cjs');
9
9
  var chunkESLWRGAG_cjs = require('./chunk-ESLWRGAG.cjs');
10
10
  var api = require('@opentelemetry/api');
11
11
  var fs = require('fs');
@@ -222,7 +222,7 @@ var EventQueue = class {
222
222
  }
223
223
  this.metrics?.dropped.add(1, attrs);
224
224
  const logLevel = reason === "payload_invalid" ? "error" : "warn";
225
- const logger = chunkJVICEM6W_cjs.getLogger();
225
+ const logger = chunkITYASFHQ_cjs.getLogger();
226
226
  if (logLevel === "error") {
227
227
  logger.error(
228
228
  {
@@ -254,7 +254,7 @@ var EventQueue = class {
254
254
  recordFailed(event, subscriberName, error) {
255
255
  this.metrics?.failed.add(1, { subscriber: subscriberName });
256
256
  this.subscriberHealthy.set(subscriberName, false);
257
- chunkJVICEM6W_cjs.getLogger().error(
257
+ chunkITYASFHQ_cjs.getLogger().error(
258
258
  {
259
259
  eventName: event.name,
260
260
  subscriber: subscriberName,
@@ -295,7 +295,7 @@ var EventQueue = class {
295
295
  if (this.queue.length >= this.config.maxSize) {
296
296
  const droppedEvent = this.queue.shift();
297
297
  this.recordDropped("rate_limit", droppedEvent);
298
- chunkJVICEM6W_cjs.getLogger().warn(
298
+ chunkITYASFHQ_cjs.getLogger().warn(
299
299
  {
300
300
  droppedEvent: droppedEvent?.name
301
301
  },
@@ -304,7 +304,7 @@ var EventQueue = class {
304
304
  }
305
305
  const enrichedEvent = {
306
306
  ...event,
307
- _correlationId: event._correlationId || chunkXRKAL7WJ_cjs.getOrCreateCorrelationId()
307
+ _correlationId: event._correlationId || chunkJSNUWSBH_cjs.getOrCreateCorrelationId()
308
308
  };
309
309
  this.queue.push(enrichedEvent);
310
310
  this.scheduleBatchFlush();
@@ -391,7 +391,7 @@ var EventQueue = class {
391
391
  const failedSubscriberNames = [
392
392
  ...new Set(failedDeliveries.map((f) => f.subscriberName))
393
393
  ];
394
- chunkJVICEM6W_cjs.getLogger().error(
394
+ chunkITYASFHQ_cjs.getLogger().error(
395
395
  {
396
396
  failedSubscribers: failedSubscriberNames,
397
397
  retriesAttempted: this.config.maxRetries
@@ -544,9 +544,9 @@ var EventQueue = class {
544
544
  // src/track.ts
545
545
  var eventsQueue = null;
546
546
  function buildAutotelContext(span2) {
547
- const eventsConfig = chunkJVICEM6W_cjs.getEventsConfig();
548
- const config = chunkJVICEM6W_cjs.getConfig();
549
- const correlationId = chunkXRKAL7WJ_cjs.getOrCreateCorrelationId();
547
+ const eventsConfig = chunkITYASFHQ_cjs.getEventsConfig();
548
+ const config = chunkITYASFHQ_cjs.getConfig();
549
+ const correlationId = chunkJSNUWSBH_cjs.getOrCreateCorrelationId();
550
550
  if (!eventsConfig?.includeTraceContext) {
551
551
  return {
552
552
  correlation_id: correlationId
@@ -599,12 +599,12 @@ function buildAutotelContext(span2) {
599
599
  return autotelContext;
600
600
  }
601
601
  function getOrCreateQueue() {
602
- if (!chunkJVICEM6W_cjs.isInitialized()) {
603
- chunkJVICEM6W_cjs.warnIfNotInitialized("track()");
602
+ if (!chunkITYASFHQ_cjs.isInitialized()) {
603
+ chunkITYASFHQ_cjs.warnIfNotInitialized("track()");
604
604
  return null;
605
605
  }
606
606
  if (!eventsQueue) {
607
- const config = chunkJVICEM6W_cjs.getConfig();
607
+ const config = chunkITYASFHQ_cjs.getConfig();
608
608
  if (!config?.subscribers || config.subscribers.length === 0) {
609
609
  return null;
610
610
  }
@@ -615,7 +615,7 @@ function getOrCreateQueue() {
615
615
  function track(event, data) {
616
616
  const queue = getOrCreateQueue();
617
617
  if (!queue) return;
618
- const validationConfig = chunkJVICEM6W_cjs.getValidationConfig();
618
+ const validationConfig = chunkITYASFHQ_cjs.getValidationConfig();
619
619
  const validated = chunkD5LMF53P_cjs.validateEvent(event, data, validationConfig || void 0);
620
620
  const span2 = api.trace.getActiveSpan();
621
621
  const enrichedData = span2 ? {
@@ -969,7 +969,7 @@ function shouldSkip(key, fn, skip) {
969
969
  function getCtxValue() {
970
970
  const activeSpan = api.trace.getActiveSpan();
971
971
  if (!activeSpan) return null;
972
- return chunkW4EUTSB2_cjs.createTraceContext(activeSpan);
972
+ return chunkHZ3FYBJG_cjs.createTraceContext(activeSpan);
973
973
  }
974
974
  var ctx = new Proxy(
975
975
  {},
@@ -1009,7 +1009,7 @@ function wrapWithTracing(fnFactory, options, variableName) {
1009
1009
  const config = chunkESLWRGAG_cjs.getConfig();
1010
1010
  const tracer = config.tracer;
1011
1011
  const meter = config.meter;
1012
- const sampler = options.sampler || new chunkBGVKKL2N_cjs.AlwaysSampler();
1012
+ const sampler = options.sampler || new chunk7FIGORWI_cjs.AlwaysSampler();
1013
1013
  const tempFn = fnFactory(createDummyCtx());
1014
1014
  const spanName = getSpanName(options, tempFn, variableName);
1015
1015
  const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
@@ -1034,8 +1034,8 @@ function wrapWithTracing(fnFactory, options, variableName) {
1034
1034
  }
1035
1035
  const startTime = performance.now();
1036
1036
  const isRootSpan = options.startNewRoot || api.trace.getActiveSpan() === void 0;
1037
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkJVICEM6W_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1038
- const shouldAutoFlushSpans = chunkJVICEM6W_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1037
+ const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkITYASFHQ_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1038
+ const shouldAutoFlushSpans = chunkITYASFHQ_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1039
1039
  const flushIfNeeded = async () => {
1040
1040
  if (!shouldAutoFlush || !isRootSpan) return;
1041
1041
  try {
@@ -1044,7 +1044,7 @@ function wrapWithTracing(fnFactory, options, variableName) {
1044
1044
  await queue.flush();
1045
1045
  }
1046
1046
  if (shouldAutoFlushSpans) {
1047
- const sdk = chunkJVICEM6W_cjs.getSdk();
1047
+ const sdk = chunkITYASFHQ_cjs.getSdk();
1048
1048
  if (sdk) {
1049
1049
  try {
1050
1050
  const sdkAny = sdk;
@@ -1059,7 +1059,7 @@ function wrapWithTracing(fnFactory, options, variableName) {
1059
1059
  }
1060
1060
  }
1061
1061
  } catch (error) {
1062
- const initConfig = chunkJVICEM6W_cjs.getConfig();
1062
+ const initConfig = chunkITYASFHQ_cjs.getConfig();
1063
1063
  const logger = initConfig?.logger;
1064
1064
  if (logger?.error) {
1065
1065
  logger.error(
@@ -1078,113 +1078,119 @@ function wrapWithTracing(fnFactory, options, variableName) {
1078
1078
  if (options.spanKind !== void 0) {
1079
1079
  spanOptions.kind = options.spanKind;
1080
1080
  }
1081
- return tracer.startActiveSpan(spanName, spanOptions, async (span2) => {
1082
- return chunkD5LMF53P_cjs.runInOperationContext(spanName, async () => {
1083
- let shouldKeepSpan = true;
1084
- chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1085
- const initialContext = api.context.active();
1086
- const contextStorage = chunkW4EUTSB2_cjs.getContextStorage();
1087
- if (!contextStorage.getStore()) {
1088
- contextStorage.enterWith(initialContext);
1089
- }
1090
- const ctxValue = chunkW4EUTSB2_cjs.createTraceContext(span2);
1091
- const fn = fnFactory(ctxValue);
1092
- const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1093
- const handleTailSampling = (success, duration, error) => {
1094
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1095
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1096
- success,
1097
- duration,
1098
- error
1099
- });
1100
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1101
- span2.setAttribute("sampling.tail.evaluated", true);
1081
+ const parentContext = chunkHZ3FYBJG_cjs.getActiveContextWithBaggage();
1082
+ return tracer.startActiveSpan(
1083
+ spanName,
1084
+ spanOptions,
1085
+ parentContext,
1086
+ async (span2) => {
1087
+ return chunkD5LMF53P_cjs.runInOperationContext(spanName, async () => {
1088
+ let shouldKeepSpan = true;
1089
+ chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1090
+ const initialContext = api.context.active();
1091
+ const contextStorage = chunkHZ3FYBJG_cjs.getContextStorage();
1092
+ if (!contextStorage.getStore()) {
1093
+ chunkHZ3FYBJG_cjs.enterOrRun(contextStorage, initialContext);
1102
1094
  }
1103
- };
1104
- const onSuccess = async (result) => {
1105
- const duration = performance.now() - startTime;
1106
- callCounter?.add(1, {
1107
- operation: spanName,
1108
- status: "success"
1109
- });
1110
- durationHistogram?.record(duration, {
1111
- operation: spanName,
1112
- status: "success"
1113
- });
1114
- const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1115
- span2.setStatus({ code: api.SpanStatusCode.OK });
1116
- span2.setAttributes({
1117
- ...argsAttributes,
1118
- ...resultAttributes,
1119
- "operation.name": spanName,
1120
- "code.function": spanName,
1121
- "operation.duration": duration,
1122
- "operation.success": true
1123
- });
1124
- handleTailSampling(true, duration);
1125
- span2.end();
1126
- await flushIfNeeded();
1127
- return result;
1128
- };
1129
- const onError = async (error) => {
1130
- const duration = performance.now() - startTime;
1131
- callCounter?.add(1, {
1132
- operation: spanName,
1133
- status: "error"
1134
- });
1135
- durationHistogram?.record(duration, {
1136
- operation: spanName,
1137
- status: "error"
1138
- });
1139
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1140
- const truncatedMessage = truncateErrorMessage(errorMessage);
1141
- span2.setStatus({
1142
- code: api.SpanStatusCode.ERROR,
1143
- message: truncatedMessage
1144
- });
1145
- span2.setAttributes({
1146
- ...argsAttributes,
1147
- "operation.name": spanName,
1148
- "code.function": spanName,
1149
- "operation.duration": duration,
1150
- "operation.success": false,
1151
- error: true,
1152
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1153
- "exception.message": truncatedMessage
1154
- });
1155
- if (error instanceof Error && error.stack) {
1156
- span2.setAttribute(
1157
- "exception.stack",
1158
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1159
- );
1160
- }
1161
- span2.recordException(
1162
- error instanceof Error ? error : new Error(String(error))
1163
- );
1164
- handleTailSampling(false, duration, error);
1165
- span2.end();
1166
- await flushIfNeeded();
1167
- throw error;
1168
- };
1169
- try {
1170
- callCounter?.add(1, {
1171
- operation: spanName,
1172
- status: "started"
1173
- });
1174
- const executeWithContext = async () => {
1175
- const currentContext = chunkW4EUTSB2_cjs.getActiveContextWithBaggage();
1176
- return api.context.with(currentContext, async () => {
1177
- return fn.call(this, ...args);
1095
+ const ctxValue = chunkHZ3FYBJG_cjs.createTraceContext(span2);
1096
+ const fn = fnFactory(ctxValue);
1097
+ const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1098
+ const handleTailSampling = (success, duration, error) => {
1099
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1100
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1101
+ success,
1102
+ duration,
1103
+ error
1104
+ });
1105
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1106
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1107
+ }
1108
+ };
1109
+ const onSuccess = async (result) => {
1110
+ const duration = performance.now() - startTime;
1111
+ callCounter?.add(1, {
1112
+ operation: spanName,
1113
+ status: "success"
1114
+ });
1115
+ durationHistogram?.record(duration, {
1116
+ operation: spanName,
1117
+ status: "success"
1118
+ });
1119
+ const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1120
+ span2.setStatus({ code: api.SpanStatusCode.OK });
1121
+ span2.setAttributes({
1122
+ ...argsAttributes,
1123
+ ...resultAttributes,
1124
+ "operation.name": spanName,
1125
+ "code.function": spanName,
1126
+ "operation.duration": duration,
1127
+ "operation.success": true
1178
1128
  });
1129
+ handleTailSampling(true, duration);
1130
+ span2.end();
1131
+ await flushIfNeeded();
1132
+ return result;
1179
1133
  };
1180
- const result = await executeWithContext();
1181
- return await onSuccess(result);
1182
- } catch (error) {
1183
- await onError(error);
1184
- throw error;
1185
- }
1186
- });
1187
- });
1134
+ const onError = async (error) => {
1135
+ const duration = performance.now() - startTime;
1136
+ callCounter?.add(1, {
1137
+ operation: spanName,
1138
+ status: "error"
1139
+ });
1140
+ durationHistogram?.record(duration, {
1141
+ operation: spanName,
1142
+ status: "error"
1143
+ });
1144
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1145
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1146
+ span2.setStatus({
1147
+ code: api.SpanStatusCode.ERROR,
1148
+ message: truncatedMessage
1149
+ });
1150
+ span2.setAttributes({
1151
+ ...argsAttributes,
1152
+ "operation.name": spanName,
1153
+ "code.function": spanName,
1154
+ "operation.duration": duration,
1155
+ "operation.success": false,
1156
+ error: true,
1157
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1158
+ "exception.message": truncatedMessage
1159
+ });
1160
+ if (error instanceof Error && error.stack) {
1161
+ span2.setAttribute(
1162
+ "exception.stack",
1163
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1164
+ );
1165
+ }
1166
+ span2.recordException(
1167
+ error instanceof Error ? error : new Error(String(error))
1168
+ );
1169
+ handleTailSampling(false, duration, error);
1170
+ span2.end();
1171
+ await flushIfNeeded();
1172
+ throw error;
1173
+ };
1174
+ try {
1175
+ callCounter?.add(1, {
1176
+ operation: spanName,
1177
+ status: "started"
1178
+ });
1179
+ const executeWithContext = async () => {
1180
+ const currentContext = chunkHZ3FYBJG_cjs.getActiveContextWithBaggage();
1181
+ return api.context.with(currentContext, async () => {
1182
+ return fn.call(this, ...args);
1183
+ });
1184
+ };
1185
+ const result = await executeWithContext();
1186
+ return await onSuccess(result);
1187
+ } catch (error) {
1188
+ await onError(error);
1189
+ throw error;
1190
+ }
1191
+ });
1192
+ }
1193
+ );
1188
1194
  };
1189
1195
  wrappedFunction[INSTRUMENTED_SYMBOL] = true;
1190
1196
  Object.defineProperty(wrappedFunction, "name", {
@@ -1198,7 +1204,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1198
1204
  const config = chunkESLWRGAG_cjs.getConfig();
1199
1205
  const tracer = config.tracer;
1200
1206
  const meter = config.meter;
1201
- const sampler = options.sampler || new chunkBGVKKL2N_cjs.AlwaysSampler();
1207
+ const sampler = options.sampler || new chunk7FIGORWI_cjs.AlwaysSampler();
1202
1208
  const tempFn = fnFactory(createDummyCtx());
1203
1209
  const spanName = getSpanName(options, tempFn, variableName);
1204
1210
  const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
@@ -1223,14 +1229,14 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1223
1229
  }
1224
1230
  const startTime = performance.now();
1225
1231
  const isRootSpan = options.startNewRoot || api.trace.getActiveSpan() === void 0;
1226
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkJVICEM6W_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1227
- const shouldAutoFlushSpans = chunkJVICEM6W_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1232
+ const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkITYASFHQ_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1233
+ const shouldAutoFlushSpans = chunkITYASFHQ_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1228
1234
  const flushIfNeeded = () => {
1229
1235
  if (!shouldAutoFlush || !isRootSpan) return;
1230
1236
  const queue = getEventQueue();
1231
1237
  if (queue && queue.size() > 0) {
1232
1238
  void queue.flush().catch((error) => {
1233
- const initConfig = chunkJVICEM6W_cjs.getConfig();
1239
+ const initConfig = chunkITYASFHQ_cjs.getConfig();
1234
1240
  const logger = initConfig?.logger;
1235
1241
  if (logger?.error) {
1236
1242
  logger.error(
@@ -1243,7 +1249,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1243
1249
  });
1244
1250
  }
1245
1251
  if (shouldAutoFlushSpans) {
1246
- const sdk = chunkJVICEM6W_cjs.getSdk();
1252
+ const sdk = chunkITYASFHQ_cjs.getSdk();
1247
1253
  if (sdk) {
1248
1254
  try {
1249
1255
  const sdkAny = sdk;
@@ -1251,7 +1257,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1251
1257
  const tracerProvider = sdkAny.getTracerProvider();
1252
1258
  if (tracerProvider && typeof tracerProvider.forceFlush === "function") {
1253
1259
  void tracerProvider.forceFlush().catch((error) => {
1254
- const initConfig = chunkJVICEM6W_cjs.getConfig();
1260
+ const initConfig = chunkITYASFHQ_cjs.getConfig();
1255
1261
  const logger = initConfig?.logger;
1256
1262
  if (logger?.error) {
1257
1263
  logger.error(
@@ -1276,98 +1282,104 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1276
1282
  if (options.spanKind !== void 0) {
1277
1283
  spanOptions.kind = options.spanKind;
1278
1284
  }
1279
- return tracer.startActiveSpan(spanName, spanOptions, (span2) => {
1280
- return chunkD5LMF53P_cjs.runInOperationContext(spanName, () => {
1281
- let shouldKeepSpan = true;
1282
- chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1283
- const ctxValue = chunkW4EUTSB2_cjs.createTraceContext(span2);
1284
- const fn = fnFactory(ctxValue);
1285
- const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1286
- const handleTailSampling = (success, duration, error) => {
1287
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1288
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1289
- success,
1290
- duration,
1291
- error
1285
+ const parentContext = chunkHZ3FYBJG_cjs.getActiveContextWithBaggage();
1286
+ return tracer.startActiveSpan(
1287
+ spanName,
1288
+ spanOptions,
1289
+ parentContext,
1290
+ (span2) => {
1291
+ return chunkD5LMF53P_cjs.runInOperationContext(spanName, () => {
1292
+ let shouldKeepSpan = true;
1293
+ chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1294
+ const ctxValue = chunkHZ3FYBJG_cjs.createTraceContext(span2);
1295
+ const fn = fnFactory(ctxValue);
1296
+ const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1297
+ const handleTailSampling = (success, duration, error) => {
1298
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1299
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1300
+ success,
1301
+ duration,
1302
+ error
1303
+ });
1304
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1305
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1306
+ }
1307
+ };
1308
+ const onSuccess = (result) => {
1309
+ const duration = performance.now() - startTime;
1310
+ callCounter?.add(1, {
1311
+ operation: spanName,
1312
+ status: "success"
1292
1313
  });
1293
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1294
- span2.setAttribute("sampling.tail.evaluated", true);
1295
- }
1296
- };
1297
- const onSuccess = (result) => {
1298
- const duration = performance.now() - startTime;
1299
- callCounter?.add(1, {
1300
- operation: spanName,
1301
- status: "success"
1302
- });
1303
- durationHistogram?.record(duration, {
1304
- operation: spanName,
1305
- status: "success"
1306
- });
1307
- const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1308
- span2.setStatus({ code: api.SpanStatusCode.OK });
1309
- span2.setAttributes({
1310
- ...argsAttributes,
1311
- ...resultAttributes,
1312
- "operation.name": spanName,
1313
- "code.function": spanName,
1314
- "operation.duration": duration,
1315
- "operation.success": true
1316
- });
1317
- handleTailSampling(true, duration);
1318
- span2.end();
1319
- void flushIfNeeded();
1320
- return result;
1321
- };
1322
- const onError = (error) => {
1323
- const duration = performance.now() - startTime;
1324
- callCounter?.add(1, {
1325
- operation: spanName,
1326
- status: "error"
1327
- });
1328
- durationHistogram?.record(duration, {
1329
- operation: spanName,
1330
- status: "error"
1331
- });
1332
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1333
- const truncatedMessage = truncateErrorMessage(errorMessage);
1334
- span2.setStatus({
1335
- code: api.SpanStatusCode.ERROR,
1336
- message: truncatedMessage
1337
- });
1338
- span2.setAttributes({
1339
- ...argsAttributes,
1340
- "operation.name": spanName,
1341
- "code.function": spanName,
1342
- "operation.duration": duration,
1343
- "operation.success": false,
1344
- error: true,
1345
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1346
- "exception.message": truncatedMessage
1347
- });
1348
- span2.recordException(
1349
- error instanceof Error ? error : new Error(String(error))
1350
- );
1351
- handleTailSampling(false, duration, error);
1352
- span2.end();
1353
- void flushIfNeeded();
1354
- throw error;
1355
- };
1356
- try {
1357
- callCounter?.add(1, {
1358
- operation: spanName,
1359
- status: "started"
1360
- });
1361
- const result = fn.call(this, ...args);
1362
- if (result instanceof Promise) {
1363
- return result.then(onSuccess, onError);
1314
+ durationHistogram?.record(duration, {
1315
+ operation: spanName,
1316
+ status: "success"
1317
+ });
1318
+ const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1319
+ span2.setStatus({ code: api.SpanStatusCode.OK });
1320
+ span2.setAttributes({
1321
+ ...argsAttributes,
1322
+ ...resultAttributes,
1323
+ "operation.name": spanName,
1324
+ "code.function": spanName,
1325
+ "operation.duration": duration,
1326
+ "operation.success": true
1327
+ });
1328
+ handleTailSampling(true, duration);
1329
+ span2.end();
1330
+ void flushIfNeeded();
1331
+ return result;
1332
+ };
1333
+ const onError = (error) => {
1334
+ const duration = performance.now() - startTime;
1335
+ callCounter?.add(1, {
1336
+ operation: spanName,
1337
+ status: "error"
1338
+ });
1339
+ durationHistogram?.record(duration, {
1340
+ operation: spanName,
1341
+ status: "error"
1342
+ });
1343
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1344
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1345
+ span2.setStatus({
1346
+ code: api.SpanStatusCode.ERROR,
1347
+ message: truncatedMessage
1348
+ });
1349
+ span2.setAttributes({
1350
+ ...argsAttributes,
1351
+ "operation.name": spanName,
1352
+ "code.function": spanName,
1353
+ "operation.duration": duration,
1354
+ "operation.success": false,
1355
+ error: true,
1356
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1357
+ "exception.message": truncatedMessage
1358
+ });
1359
+ span2.recordException(
1360
+ error instanceof Error ? error : new Error(String(error))
1361
+ );
1362
+ handleTailSampling(false, duration, error);
1363
+ span2.end();
1364
+ void flushIfNeeded();
1365
+ throw error;
1366
+ };
1367
+ try {
1368
+ callCounter?.add(1, {
1369
+ operation: spanName,
1370
+ status: "started"
1371
+ });
1372
+ const result = fn.call(this, ...args);
1373
+ if (result instanceof Promise) {
1374
+ return result.then(onSuccess, onError);
1375
+ }
1376
+ return onSuccess(result);
1377
+ } catch (error) {
1378
+ return onError(error);
1364
1379
  }
1365
- return onSuccess(result);
1366
- } catch (error) {
1367
- return onError(error);
1368
- }
1369
- });
1370
- });
1380
+ });
1381
+ }
1382
+ );
1371
1383
  }
1372
1384
  wrappedFunction[INSTRUMENTED_SYMBOL] = true;
1373
1385
  Object.defineProperty(wrappedFunction, "name", {
@@ -1380,7 +1392,7 @@ function executeImmediately(fn, options) {
1380
1392
  const config = chunkESLWRGAG_cjs.getConfig();
1381
1393
  const tracer = config.tracer;
1382
1394
  const meter = config.meter;
1383
- const sampler = options.sampler || new chunkBGVKKL2N_cjs.AlwaysSampler();
1395
+ const sampler = options.sampler || new chunk7FIGORWI_cjs.AlwaysSampler();
1384
1396
  const spanName = options.name || "anonymous";
1385
1397
  const samplingContext = {
1386
1398
  operationName: spanName,
@@ -1394,8 +1406,8 @@ function executeImmediately(fn, options) {
1394
1406
  }
1395
1407
  const startTime = performance.now();
1396
1408
  const isRootSpan = options.startNewRoot || api.trace.getActiveSpan() === void 0;
1397
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkJVICEM6W_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1398
- const shouldAutoFlushSpans = chunkJVICEM6W_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1409
+ const shouldAutoFlush = options.flushOnRootSpanEnd ?? chunkITYASFHQ_cjs.getConfig()?.flushOnRootSpanEnd ?? true;
1410
+ const shouldAutoFlushSpans = chunkITYASFHQ_cjs.getConfig()?.forceFlushOnShutdown ?? false;
1399
1411
  const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
1400
1412
  description: `Call count for ${spanName}`,
1401
1413
  unit: "1"
@@ -1412,7 +1424,7 @@ function executeImmediately(fn, options) {
1412
1424
  await queue.flush();
1413
1425
  }
1414
1426
  if (shouldAutoFlushSpans) {
1415
- const sdk = chunkJVICEM6W_cjs.getSdk();
1427
+ const sdk = chunkITYASFHQ_cjs.getSdk();
1416
1428
  if (sdk) {
1417
1429
  try {
1418
1430
  const sdkAny = sdk;
@@ -1427,7 +1439,7 @@ function executeImmediately(fn, options) {
1427
1439
  }
1428
1440
  }
1429
1441
  } catch (error) {
1430
- const initConfig = chunkJVICEM6W_cjs.getConfig();
1442
+ const initConfig = chunkITYASFHQ_cjs.getConfig();
1431
1443
  const logger = initConfig?.logger;
1432
1444
  if (logger?.error) {
1433
1445
  logger.error(
@@ -1446,159 +1458,165 @@ function executeImmediately(fn, options) {
1446
1458
  if (options.spanKind !== void 0) {
1447
1459
  spanOptions.kind = options.spanKind;
1448
1460
  }
1449
- return tracer.startActiveSpan(spanName, spanOptions, (span2) => {
1450
- return chunkD5LMF53P_cjs.runInOperationContext(spanName, () => {
1451
- let shouldKeepSpan = true;
1452
- chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1453
- const ctxValue = chunkW4EUTSB2_cjs.createTraceContext(span2);
1454
- const handleTailSampling = (success, duration, error) => {
1455
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1456
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1457
- success,
1458
- duration,
1459
- error
1461
+ const parentContext = chunkHZ3FYBJG_cjs.getActiveContextWithBaggage();
1462
+ return tracer.startActiveSpan(
1463
+ spanName,
1464
+ spanOptions,
1465
+ parentContext,
1466
+ (span2) => {
1467
+ return chunkD5LMF53P_cjs.runInOperationContext(spanName, () => {
1468
+ let shouldKeepSpan = true;
1469
+ chunkGML3FBOT_cjs.setSpanName(span2, spanName);
1470
+ const ctxValue = chunkHZ3FYBJG_cjs.createTraceContext(span2);
1471
+ const handleTailSampling = (success, duration, error) => {
1472
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1473
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1474
+ success,
1475
+ duration,
1476
+ error
1477
+ });
1478
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1479
+ span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1480
+ }
1481
+ };
1482
+ const onSuccessSync = (result) => {
1483
+ const duration = performance.now() - startTime;
1484
+ callCounter?.add(1, {
1485
+ operation: spanName,
1486
+ status: "success"
1460
1487
  });
1461
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1462
- span2.setAttribute("sampling.tail.evaluated", true);
1463
- }
1464
- };
1465
- const onSuccessSync = (result) => {
1466
- const duration = performance.now() - startTime;
1467
- callCounter?.add(1, {
1468
- operation: spanName,
1469
- status: "success"
1470
- });
1471
- durationHistogram?.record(duration, {
1472
- operation: spanName,
1473
- status: "success"
1474
- });
1475
- span2.setStatus({ code: api.SpanStatusCode.OK });
1476
- span2.setAttributes({
1477
- "operation.name": spanName,
1478
- "code.function": spanName,
1479
- "operation.duration": duration,
1480
- "operation.success": true
1481
- });
1482
- handleTailSampling(true, duration);
1483
- span2.end();
1484
- void flushIfNeeded();
1485
- return result;
1486
- };
1487
- const onErrorSync = (error) => {
1488
- const duration = performance.now() - startTime;
1489
- callCounter?.add(1, {
1490
- operation: spanName,
1491
- status: "error"
1492
- });
1493
- durationHistogram?.record(duration, {
1494
- operation: spanName,
1495
- status: "error"
1496
- });
1497
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1498
- const truncatedMessage = truncateErrorMessage(errorMessage);
1499
- span2.setStatus({
1500
- code: api.SpanStatusCode.ERROR,
1501
- message: truncatedMessage
1502
- });
1503
- span2.setAttributes({
1504
- "operation.name": spanName,
1505
- "code.function": spanName,
1506
- "operation.duration": duration,
1507
- "operation.success": false,
1508
- error: true,
1509
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1510
- "exception.message": truncatedMessage
1511
- });
1512
- if (error instanceof Error && error.stack) {
1513
- span2.setAttribute(
1514
- "exception.stack",
1515
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1488
+ durationHistogram?.record(duration, {
1489
+ operation: spanName,
1490
+ status: "success"
1491
+ });
1492
+ span2.setStatus({ code: api.SpanStatusCode.OK });
1493
+ span2.setAttributes({
1494
+ "operation.name": spanName,
1495
+ "code.function": spanName,
1496
+ "operation.duration": duration,
1497
+ "operation.success": true
1498
+ });
1499
+ handleTailSampling(true, duration);
1500
+ span2.end();
1501
+ void flushIfNeeded();
1502
+ return result;
1503
+ };
1504
+ const onErrorSync = (error) => {
1505
+ const duration = performance.now() - startTime;
1506
+ callCounter?.add(1, {
1507
+ operation: spanName,
1508
+ status: "error"
1509
+ });
1510
+ durationHistogram?.record(duration, {
1511
+ operation: spanName,
1512
+ status: "error"
1513
+ });
1514
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1515
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1516
+ span2.setStatus({
1517
+ code: api.SpanStatusCode.ERROR,
1518
+ message: truncatedMessage
1519
+ });
1520
+ span2.setAttributes({
1521
+ "operation.name": spanName,
1522
+ "code.function": spanName,
1523
+ "operation.duration": duration,
1524
+ "operation.success": false,
1525
+ error: true,
1526
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1527
+ "exception.message": truncatedMessage
1528
+ });
1529
+ if (error instanceof Error && error.stack) {
1530
+ span2.setAttribute(
1531
+ "exception.stack",
1532
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1533
+ );
1534
+ }
1535
+ span2.recordException(
1536
+ error instanceof Error ? error : new Error(String(error))
1516
1537
  );
1517
- }
1518
- span2.recordException(
1519
- error instanceof Error ? error : new Error(String(error))
1520
- );
1521
- handleTailSampling(false, duration, error);
1522
- span2.end();
1523
- void flushIfNeeded();
1524
- throw error;
1525
- };
1526
- const onSuccessAsync = async (result) => {
1527
- const duration = performance.now() - startTime;
1528
- callCounter?.add(1, {
1529
- operation: spanName,
1530
- status: "success"
1531
- });
1532
- durationHistogram?.record(duration, {
1533
- operation: spanName,
1534
- status: "success"
1535
- });
1536
- span2.setStatus({ code: api.SpanStatusCode.OK });
1537
- span2.setAttributes({
1538
- "operation.name": spanName,
1539
- "code.function": spanName,
1540
- "operation.duration": duration,
1541
- "operation.success": true
1542
- });
1543
- handleTailSampling(true, duration);
1544
- span2.end();
1545
- await flushIfNeeded();
1546
- return result;
1547
- };
1548
- const onErrorAsync = async (error) => {
1549
- const duration = performance.now() - startTime;
1550
- callCounter?.add(1, {
1551
- operation: spanName,
1552
- status: "error"
1553
- });
1554
- durationHistogram?.record(duration, {
1555
- operation: spanName,
1556
- status: "error"
1557
- });
1558
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1559
- const truncatedMessage = truncateErrorMessage(errorMessage);
1560
- span2.setStatus({
1561
- code: api.SpanStatusCode.ERROR,
1562
- message: truncatedMessage
1563
- });
1564
- span2.setAttributes({
1565
- "operation.name": spanName,
1566
- "code.function": spanName,
1567
- "operation.duration": duration,
1568
- "operation.success": false,
1569
- error: true,
1570
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1571
- "exception.message": truncatedMessage
1572
- });
1573
- if (error instanceof Error && error.stack) {
1574
- span2.setAttribute(
1575
- "exception.stack",
1576
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1538
+ handleTailSampling(false, duration, error);
1539
+ span2.end();
1540
+ void flushIfNeeded();
1541
+ throw error;
1542
+ };
1543
+ const onSuccessAsync = async (result) => {
1544
+ const duration = performance.now() - startTime;
1545
+ callCounter?.add(1, {
1546
+ operation: spanName,
1547
+ status: "success"
1548
+ });
1549
+ durationHistogram?.record(duration, {
1550
+ operation: spanName,
1551
+ status: "success"
1552
+ });
1553
+ span2.setStatus({ code: api.SpanStatusCode.OK });
1554
+ span2.setAttributes({
1555
+ "operation.name": spanName,
1556
+ "code.function": spanName,
1557
+ "operation.duration": duration,
1558
+ "operation.success": true
1559
+ });
1560
+ handleTailSampling(true, duration);
1561
+ span2.end();
1562
+ await flushIfNeeded();
1563
+ return result;
1564
+ };
1565
+ const onErrorAsync = async (error) => {
1566
+ const duration = performance.now() - startTime;
1567
+ callCounter?.add(1, {
1568
+ operation: spanName,
1569
+ status: "error"
1570
+ });
1571
+ durationHistogram?.record(duration, {
1572
+ operation: spanName,
1573
+ status: "error"
1574
+ });
1575
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1576
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1577
+ span2.setStatus({
1578
+ code: api.SpanStatusCode.ERROR,
1579
+ message: truncatedMessage
1580
+ });
1581
+ span2.setAttributes({
1582
+ "operation.name": spanName,
1583
+ "code.function": spanName,
1584
+ "operation.duration": duration,
1585
+ "operation.success": false,
1586
+ error: true,
1587
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1588
+ "exception.message": truncatedMessage
1589
+ });
1590
+ if (error instanceof Error && error.stack) {
1591
+ span2.setAttribute(
1592
+ "exception.stack",
1593
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1594
+ );
1595
+ }
1596
+ span2.recordException(
1597
+ error instanceof Error ? error : new Error(String(error))
1577
1598
  );
1599
+ handleTailSampling(false, duration, error);
1600
+ span2.end();
1601
+ await flushIfNeeded();
1602
+ throw error;
1603
+ };
1604
+ try {
1605
+ callCounter?.add(1, {
1606
+ operation: spanName,
1607
+ status: "started"
1608
+ });
1609
+ const result = fn(ctxValue);
1610
+ if (result instanceof Promise) {
1611
+ return result.then(onSuccessAsync, onErrorAsync);
1612
+ }
1613
+ return onSuccessSync(result);
1614
+ } catch (error) {
1615
+ return onErrorSync(error);
1578
1616
  }
1579
- span2.recordException(
1580
- error instanceof Error ? error : new Error(String(error))
1581
- );
1582
- handleTailSampling(false, duration, error);
1583
- span2.end();
1584
- await flushIfNeeded();
1585
- throw error;
1586
- };
1587
- try {
1588
- callCounter?.add(1, {
1589
- operation: spanName,
1590
- status: "started"
1591
- });
1592
- const result = fn(ctxValue);
1593
- if (result instanceof Promise) {
1594
- return result.then(onSuccessAsync, onErrorAsync);
1595
- }
1596
- return onSuccessSync(result);
1597
- } catch (error) {
1598
- return onErrorSync(error);
1599
- }
1600
- });
1601
- });
1617
+ });
1618
+ }
1619
+ );
1602
1620
  }
1603
1621
  function trace2(fnOrNameOrOptions, maybeFn) {
1604
1622
  if (typeof fnOrNameOrOptions === "function") {
@@ -1730,7 +1748,8 @@ function span(options, fn) {
1730
1748
  }
1731
1749
  });
1732
1750
  };
1733
- const result = tracer.startActiveSpan(name, executeSpan);
1751
+ const parentContext = chunkHZ3FYBJG_cjs.getActiveContextWithBaggage();
1752
+ const result = tracer.startActiveSpan(name, {}, parentContext, executeSpan);
1734
1753
  if (result instanceof Promise) {
1735
1754
  return result;
1736
1755
  }
@@ -1764,9 +1783,9 @@ function withBaggage(options) {
1764
1783
  updatedBaggage = updatedBaggage.setEntry(key, { value });
1765
1784
  }
1766
1785
  const newContext = api.propagation.setBaggage(currentContext, updatedBaggage);
1767
- const ctxStorage = chunkW4EUTSB2_cjs.getContextStorage();
1786
+ const ctxStorage = chunkHZ3FYBJG_cjs.getContextStorage();
1768
1787
  const previousStored = ctxStorage.getStore();
1769
- const baggageEnrichedStored = previousStored ? api.propagation.setBaggage(previousStored, updatedBaggage) : newContext;
1788
+ const baggageEnrichedStored = previousStored ? { value: api.propagation.setBaggage(previousStored.value, updatedBaggage) } : { value: newContext };
1770
1789
  const result = previousStored ? ctxStorage.run(baggageEnrichedStored, () => api.context.with(newContext, fn)) : api.context.with(newContext, fn);
1771
1790
  if (result instanceof Promise) {
1772
1791
  return result.then(
@@ -1799,5 +1818,5 @@ exports.track = track;
1799
1818
  exports.withBaggage = withBaggage;
1800
1819
  exports.withNewContext = withNewContext;
1801
1820
  exports.withTracing = withTracing;
1802
- //# sourceMappingURL=chunk-RWOVNF3V.cjs.map
1803
- //# sourceMappingURL=chunk-RWOVNF3V.cjs.map
1821
+ //# sourceMappingURL=chunk-QQLP4M6W.cjs.map
1822
+ //# sourceMappingURL=chunk-QQLP4M6W.cjs.map