autotel 2.25.3 → 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 (63) hide show
  1. package/dist/{chunk-FXKB7EPR.cjs → chunk-A5ZUL2RZ.cjs} +5 -5
  2. package/dist/{chunk-FXKB7EPR.cjs.map → chunk-A5ZUL2RZ.cjs.map} +1 -1
  3. package/dist/{chunk-SR35DG5A.js → chunk-BBBWDIYQ.js} +27 -13
  4. package/dist/chunk-BBBWDIYQ.js.map +1 -0
  5. package/dist/{chunk-3ZLYWPMY.js → chunk-CMUM4JQI.js} +3 -3
  6. package/dist/{chunk-3ZLYWPMY.js.map → chunk-CMUM4JQI.js.map} +1 -1
  7. package/dist/{chunk-AQXPGGQK.cjs → chunk-EEJGUBWV.cjs} +5 -5
  8. package/dist/{chunk-AQXPGGQK.cjs.map → chunk-EEJGUBWV.cjs.map} +1 -1
  9. package/dist/{chunk-W4EUTSB2.cjs → chunk-HZ3FYBJG.cjs} +27 -12
  10. package/dist/chunk-HZ3FYBJG.cjs.map +1 -0
  11. package/dist/{chunk-WOWTZ4EB.cjs → chunk-I6JPSD4R.cjs} +5 -5
  12. package/dist/{chunk-WOWTZ4EB.cjs.map → chunk-I6JPSD4R.cjs.map} +1 -1
  13. package/dist/{chunk-XRKAL7WJ.cjs → chunk-JSNUWSBH.cjs} +6 -6
  14. package/dist/chunk-JSNUWSBH.cjs.map +1 -0
  15. package/dist/{chunk-OWXXS4JB.cjs → chunk-MN6PZ4AN.cjs} +7 -7
  16. package/dist/{chunk-OWXXS4JB.cjs.map → chunk-MN6PZ4AN.cjs.map} +1 -1
  17. package/dist/{chunk-JM63D22M.js → chunk-OPTGXEVN.js} +368 -349
  18. package/dist/chunk-OPTGXEVN.js.map +1 -0
  19. package/dist/{chunk-PKXD2RMI.js → chunk-QDREXAD7.js} +3 -3
  20. package/dist/{chunk-PKXD2RMI.js.map → chunk-QDREXAD7.js.map} +1 -1
  21. package/dist/{chunk-RMGSBMQF.cjs → chunk-QQLP4M6W.cjs} +372 -353
  22. package/dist/chunk-QQLP4M6W.cjs.map +1 -0
  23. package/dist/{chunk-USSL3D6L.js → chunk-S4OFEXLA.js} +6 -6
  24. package/dist/chunk-S4OFEXLA.js.map +1 -0
  25. package/dist/{chunk-VVYSQXQL.js → chunk-WYP6OOCT.js} +3 -3
  26. package/dist/{chunk-VVYSQXQL.js.map → chunk-WYP6OOCT.js.map} +1 -1
  27. package/dist/{chunk-IFKDBL65.js → chunk-XB2GITM5.js} +3 -3
  28. package/dist/{chunk-IFKDBL65.js.map → chunk-XB2GITM5.js.map} +1 -1
  29. package/dist/correlation-id.cjs +10 -9
  30. package/dist/correlation-id.d.cts +4 -1
  31. package/dist/correlation-id.d.ts +4 -1
  32. package/dist/correlation-id.js +2 -1
  33. package/dist/decorators.cjs +4 -4
  34. package/dist/decorators.js +3 -3
  35. package/dist/event.cjs +6 -5
  36. package/dist/event.js +3 -2
  37. package/dist/functional.cjs +10 -10
  38. package/dist/functional.js +3 -3
  39. package/dist/http.cjs +2 -2
  40. package/dist/http.js +1 -1
  41. package/dist/index.cjs +45 -45
  42. package/dist/index.js +10 -10
  43. package/dist/messaging.cjs +7 -7
  44. package/dist/messaging.js +4 -4
  45. package/dist/semantic-helpers.cjs +8 -8
  46. package/dist/semantic-helpers.js +4 -4
  47. package/dist/webhook.cjs +4 -4
  48. package/dist/webhook.js +3 -3
  49. package/dist/workflow-distributed.cjs +5 -5
  50. package/dist/workflow-distributed.js +3 -3
  51. package/dist/workflow.cjs +8 -8
  52. package/dist/workflow.js +4 -4
  53. package/package.json +1 -1
  54. package/src/correlation-id.ts +10 -5
  55. package/src/functional.ts +440 -420
  56. package/src/trace-context.test.ts +73 -0
  57. package/src/trace-context.ts +44 -12
  58. package/dist/chunk-JM63D22M.js.map +0 -1
  59. package/dist/chunk-RMGSBMQF.cjs.map +0 -1
  60. package/dist/chunk-SR35DG5A.js.map +0 -1
  61. package/dist/chunk-USSL3D6L.js.map +0 -1
  62. package/dist/chunk-W4EUTSB2.cjs.map +0 -1
  63. package/dist/chunk-XRKAL7WJ.cjs.map +0 -1
@@ -1,9 +1,9 @@
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');
5
+ var chunkJSNUWSBH_cjs = require('./chunk-JSNUWSBH.cjs');
6
+ var chunkHZ3FYBJG_cjs = require('./chunk-HZ3FYBJG.cjs');
7
7
  var chunkITYASFHQ_cjs = require('./chunk-ITYASFHQ.cjs');
8
8
  var chunk7FIGORWI_cjs = require('./chunk-7FIGORWI.cjs');
9
9
  var chunkESLWRGAG_cjs = require('./chunk-ESLWRGAG.cjs');
@@ -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();
@@ -546,7 +546,7 @@ var eventsQueue = null;
546
546
  function buildAutotelContext(span2) {
547
547
  const eventsConfig = chunkITYASFHQ_cjs.getEventsConfig();
548
548
  const config = chunkITYASFHQ_cjs.getConfig();
549
- const correlationId = chunkXRKAL7WJ_cjs.getOrCreateCorrelationId();
549
+ const correlationId = chunkJSNUWSBH_cjs.getOrCreateCorrelationId();
550
550
  if (!eventsConfig?.includeTraceContext) {
551
551
  return {
552
552
  correlation_id: correlationId
@@ -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
  {},
@@ -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(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1101
- span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_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", {
@@ -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(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1294
- span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_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", {
@@ -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(chunk7FIGORWI_cjs.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1462
- span2.setAttribute(chunk7FIGORWI_cjs.AUTOTEL_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-RMGSBMQF.cjs.map
1803
- //# sourceMappingURL=chunk-RMGSBMQF.cjs.map
1821
+ //# sourceMappingURL=chunk-QQLP4M6W.cjs.map
1822
+ //# sourceMappingURL=chunk-QQLP4M6W.cjs.map