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,9 +1,9 @@
1
- import { createTraceContext, getContextStorage, getActiveContextWithBaggage } from './chunk-SR35DG5A.js';
2
1
  import { setSpanName } from './chunk-B3ZHLLMP.js';
3
2
  import { validateEvent, runInOperationContext } from './chunk-WD4RP6IV.js';
4
- import { getOrCreateCorrelationId } from './chunk-USSL3D6L.js';
5
- import { getValidationConfig, isInitialized, warnIfNotInitialized, getConfig as getConfig$1, getEventsConfig, getLogger, getSdk } from './chunk-VXLEJWLY.js';
6
- import { AlwaysSampler } from './chunk-XND7WBVX.js';
3
+ import { getOrCreateCorrelationId } from './chunk-S4OFEXLA.js';
4
+ import { createTraceContext, getActiveContextWithBaggage, getContextStorage, enterOrRun } from './chunk-BBBWDIYQ.js';
5
+ import { getValidationConfig, isInitialized, warnIfNotInitialized, getConfig as getConfig$1, getEventsConfig, getLogger, getSdk } from './chunk-MNBAXRVG.js';
6
+ import { AlwaysSampler, AUTOTEL_SAMPLING_TAIL_KEEP, AUTOTEL_SAMPLING_TAIL_EVALUATED } from './chunk-VYA6QDNA.js';
7
7
  import { getConfig } from './chunk-J5QENANM.js';
8
8
  import { trace, SpanStatusCode, context, propagation } from '@opentelemetry/api';
9
9
  import { readFileSync } from 'fs';
@@ -1076,113 +1076,119 @@ function wrapWithTracing(fnFactory, options, variableName) {
1076
1076
  if (options.spanKind !== void 0) {
1077
1077
  spanOptions.kind = options.spanKind;
1078
1078
  }
1079
- return tracer.startActiveSpan(spanName, spanOptions, async (span2) => {
1080
- return runInOperationContext(spanName, async () => {
1081
- let shouldKeepSpan = true;
1082
- setSpanName(span2, spanName);
1083
- const initialContext = context.active();
1084
- const contextStorage = getContextStorage();
1085
- if (!contextStorage.getStore()) {
1086
- contextStorage.enterWith(initialContext);
1087
- }
1088
- const ctxValue = createTraceContext(span2);
1089
- const fn = fnFactory(ctxValue);
1090
- const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1091
- const handleTailSampling = (success, duration, error) => {
1092
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1093
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1094
- success,
1095
- duration,
1096
- error
1097
- });
1098
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1099
- span2.setAttribute("sampling.tail.evaluated", true);
1100
- }
1101
- };
1102
- const onSuccess = async (result) => {
1103
- const duration = performance.now() - startTime;
1104
- callCounter?.add(1, {
1105
- operation: spanName,
1106
- status: "success"
1107
- });
1108
- durationHistogram?.record(duration, {
1109
- operation: spanName,
1110
- status: "success"
1111
- });
1112
- const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1113
- span2.setStatus({ code: SpanStatusCode.OK });
1114
- span2.setAttributes({
1115
- ...argsAttributes,
1116
- ...resultAttributes,
1117
- "operation.name": spanName,
1118
- "code.function": spanName,
1119
- "operation.duration": duration,
1120
- "operation.success": true
1121
- });
1122
- handleTailSampling(true, duration);
1123
- span2.end();
1124
- await flushIfNeeded();
1125
- return result;
1126
- };
1127
- const onError = async (error) => {
1128
- const duration = performance.now() - startTime;
1129
- callCounter?.add(1, {
1130
- operation: spanName,
1131
- status: "error"
1132
- });
1133
- durationHistogram?.record(duration, {
1134
- operation: spanName,
1135
- status: "error"
1136
- });
1137
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1138
- const truncatedMessage = truncateErrorMessage(errorMessage);
1139
- span2.setStatus({
1140
- code: SpanStatusCode.ERROR,
1141
- message: truncatedMessage
1142
- });
1143
- span2.setAttributes({
1144
- ...argsAttributes,
1145
- "operation.name": spanName,
1146
- "code.function": spanName,
1147
- "operation.duration": duration,
1148
- "operation.success": false,
1149
- error: true,
1150
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1151
- "exception.message": truncatedMessage
1152
- });
1153
- if (error instanceof Error && error.stack) {
1154
- span2.setAttribute(
1155
- "exception.stack",
1156
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1157
- );
1079
+ const parentContext = getActiveContextWithBaggage();
1080
+ return tracer.startActiveSpan(
1081
+ spanName,
1082
+ spanOptions,
1083
+ parentContext,
1084
+ async (span2) => {
1085
+ return runInOperationContext(spanName, async () => {
1086
+ let shouldKeepSpan = true;
1087
+ setSpanName(span2, spanName);
1088
+ const initialContext = context.active();
1089
+ const contextStorage = getContextStorage();
1090
+ if (!contextStorage.getStore()) {
1091
+ enterOrRun(contextStorage, initialContext);
1158
1092
  }
1159
- span2.recordException(
1160
- error instanceof Error ? error : new Error(String(error))
1161
- );
1162
- handleTailSampling(false, duration, error);
1163
- span2.end();
1164
- await flushIfNeeded();
1165
- throw error;
1166
- };
1167
- try {
1168
- callCounter?.add(1, {
1169
- operation: spanName,
1170
- status: "started"
1171
- });
1172
- const executeWithContext = async () => {
1173
- const currentContext = getActiveContextWithBaggage();
1174
- return context.with(currentContext, async () => {
1175
- return fn.call(this, ...args);
1093
+ const ctxValue = createTraceContext(span2);
1094
+ const fn = fnFactory(ctxValue);
1095
+ const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1096
+ const handleTailSampling = (success, duration, error) => {
1097
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1098
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1099
+ success,
1100
+ duration,
1101
+ error
1102
+ });
1103
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1104
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1105
+ }
1106
+ };
1107
+ const onSuccess = async (result) => {
1108
+ const duration = performance.now() - startTime;
1109
+ callCounter?.add(1, {
1110
+ operation: spanName,
1111
+ status: "success"
1112
+ });
1113
+ durationHistogram?.record(duration, {
1114
+ operation: spanName,
1115
+ status: "success"
1116
+ });
1117
+ const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1118
+ span2.setStatus({ code: SpanStatusCode.OK });
1119
+ span2.setAttributes({
1120
+ ...argsAttributes,
1121
+ ...resultAttributes,
1122
+ "operation.name": spanName,
1123
+ "code.function": spanName,
1124
+ "operation.duration": duration,
1125
+ "operation.success": true
1176
1126
  });
1127
+ handleTailSampling(true, duration);
1128
+ span2.end();
1129
+ await flushIfNeeded();
1130
+ return result;
1177
1131
  };
1178
- const result = await executeWithContext();
1179
- return await onSuccess(result);
1180
- } catch (error) {
1181
- await onError(error);
1182
- throw error;
1183
- }
1184
- });
1185
- });
1132
+ const onError = async (error) => {
1133
+ const duration = performance.now() - startTime;
1134
+ callCounter?.add(1, {
1135
+ operation: spanName,
1136
+ status: "error"
1137
+ });
1138
+ durationHistogram?.record(duration, {
1139
+ operation: spanName,
1140
+ status: "error"
1141
+ });
1142
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1143
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1144
+ span2.setStatus({
1145
+ code: SpanStatusCode.ERROR,
1146
+ message: truncatedMessage
1147
+ });
1148
+ span2.setAttributes({
1149
+ ...argsAttributes,
1150
+ "operation.name": spanName,
1151
+ "code.function": spanName,
1152
+ "operation.duration": duration,
1153
+ "operation.success": false,
1154
+ error: true,
1155
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1156
+ "exception.message": truncatedMessage
1157
+ });
1158
+ if (error instanceof Error && error.stack) {
1159
+ span2.setAttribute(
1160
+ "exception.stack",
1161
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1162
+ );
1163
+ }
1164
+ span2.recordException(
1165
+ error instanceof Error ? error : new Error(String(error))
1166
+ );
1167
+ handleTailSampling(false, duration, error);
1168
+ span2.end();
1169
+ await flushIfNeeded();
1170
+ throw error;
1171
+ };
1172
+ try {
1173
+ callCounter?.add(1, {
1174
+ operation: spanName,
1175
+ status: "started"
1176
+ });
1177
+ const executeWithContext = async () => {
1178
+ const currentContext = getActiveContextWithBaggage();
1179
+ return context.with(currentContext, async () => {
1180
+ return fn.call(this, ...args);
1181
+ });
1182
+ };
1183
+ const result = await executeWithContext();
1184
+ return await onSuccess(result);
1185
+ } catch (error) {
1186
+ await onError(error);
1187
+ throw error;
1188
+ }
1189
+ });
1190
+ }
1191
+ );
1186
1192
  };
1187
1193
  wrappedFunction[INSTRUMENTED_SYMBOL] = true;
1188
1194
  Object.defineProperty(wrappedFunction, "name", {
@@ -1274,98 +1280,104 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
1274
1280
  if (options.spanKind !== void 0) {
1275
1281
  spanOptions.kind = options.spanKind;
1276
1282
  }
1277
- return tracer.startActiveSpan(spanName, spanOptions, (span2) => {
1278
- return runInOperationContext(spanName, () => {
1279
- let shouldKeepSpan = true;
1280
- setSpanName(span2, spanName);
1281
- const ctxValue = createTraceContext(span2);
1282
- const fn = fnFactory(ctxValue);
1283
- const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1284
- const handleTailSampling = (success, duration, error) => {
1285
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1286
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1287
- success,
1288
- duration,
1289
- error
1283
+ const parentContext = getActiveContextWithBaggage();
1284
+ return tracer.startActiveSpan(
1285
+ spanName,
1286
+ spanOptions,
1287
+ parentContext,
1288
+ (span2) => {
1289
+ return runInOperationContext(spanName, () => {
1290
+ let shouldKeepSpan = true;
1291
+ setSpanName(span2, spanName);
1292
+ const ctxValue = createTraceContext(span2);
1293
+ const fn = fnFactory(ctxValue);
1294
+ const argsAttributes = options.attributesFromArgs ? options.attributesFromArgs(args) : {};
1295
+ const handleTailSampling = (success, duration, error) => {
1296
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1297
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1298
+ success,
1299
+ duration,
1300
+ error
1301
+ });
1302
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1303
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1304
+ }
1305
+ };
1306
+ const onSuccess = (result) => {
1307
+ const duration = performance.now() - startTime;
1308
+ callCounter?.add(1, {
1309
+ operation: spanName,
1310
+ status: "success"
1290
1311
  });
1291
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1292
- span2.setAttribute("sampling.tail.evaluated", true);
1293
- }
1294
- };
1295
- const onSuccess = (result) => {
1296
- const duration = performance.now() - startTime;
1297
- callCounter?.add(1, {
1298
- operation: spanName,
1299
- status: "success"
1300
- });
1301
- durationHistogram?.record(duration, {
1302
- operation: spanName,
1303
- status: "success"
1304
- });
1305
- const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1306
- span2.setStatus({ code: SpanStatusCode.OK });
1307
- span2.setAttributes({
1308
- ...argsAttributes,
1309
- ...resultAttributes,
1310
- "operation.name": spanName,
1311
- "code.function": spanName,
1312
- "operation.duration": duration,
1313
- "operation.success": true
1314
- });
1315
- handleTailSampling(true, duration);
1316
- span2.end();
1317
- void flushIfNeeded();
1318
- return result;
1319
- };
1320
- const onError = (error) => {
1321
- const duration = performance.now() - startTime;
1322
- callCounter?.add(1, {
1323
- operation: spanName,
1324
- status: "error"
1325
- });
1326
- durationHistogram?.record(duration, {
1327
- operation: spanName,
1328
- status: "error"
1329
- });
1330
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1331
- const truncatedMessage = truncateErrorMessage(errorMessage);
1332
- span2.setStatus({
1333
- code: SpanStatusCode.ERROR,
1334
- message: truncatedMessage
1335
- });
1336
- span2.setAttributes({
1337
- ...argsAttributes,
1338
- "operation.name": spanName,
1339
- "code.function": spanName,
1340
- "operation.duration": duration,
1341
- "operation.success": false,
1342
- error: true,
1343
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1344
- "exception.message": truncatedMessage
1345
- });
1346
- span2.recordException(
1347
- error instanceof Error ? error : new Error(String(error))
1348
- );
1349
- handleTailSampling(false, duration, error);
1350
- span2.end();
1351
- void flushIfNeeded();
1352
- throw error;
1353
- };
1354
- try {
1355
- callCounter?.add(1, {
1356
- operation: spanName,
1357
- status: "started"
1358
- });
1359
- const result = fn.call(this, ...args);
1360
- if (result instanceof Promise) {
1361
- return result.then(onSuccess, onError);
1312
+ durationHistogram?.record(duration, {
1313
+ operation: spanName,
1314
+ status: "success"
1315
+ });
1316
+ const resultAttributes = options.attributesFromResult ? options.attributesFromResult(result) : {};
1317
+ span2.setStatus({ code: SpanStatusCode.OK });
1318
+ span2.setAttributes({
1319
+ ...argsAttributes,
1320
+ ...resultAttributes,
1321
+ "operation.name": spanName,
1322
+ "code.function": spanName,
1323
+ "operation.duration": duration,
1324
+ "operation.success": true
1325
+ });
1326
+ handleTailSampling(true, duration);
1327
+ span2.end();
1328
+ void flushIfNeeded();
1329
+ return result;
1330
+ };
1331
+ const onError = (error) => {
1332
+ const duration = performance.now() - startTime;
1333
+ callCounter?.add(1, {
1334
+ operation: spanName,
1335
+ status: "error"
1336
+ });
1337
+ durationHistogram?.record(duration, {
1338
+ operation: spanName,
1339
+ status: "error"
1340
+ });
1341
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1342
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1343
+ span2.setStatus({
1344
+ code: SpanStatusCode.ERROR,
1345
+ message: truncatedMessage
1346
+ });
1347
+ span2.setAttributes({
1348
+ ...argsAttributes,
1349
+ "operation.name": spanName,
1350
+ "code.function": spanName,
1351
+ "operation.duration": duration,
1352
+ "operation.success": false,
1353
+ error: true,
1354
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1355
+ "exception.message": truncatedMessage
1356
+ });
1357
+ span2.recordException(
1358
+ error instanceof Error ? error : new Error(String(error))
1359
+ );
1360
+ handleTailSampling(false, duration, error);
1361
+ span2.end();
1362
+ void flushIfNeeded();
1363
+ throw error;
1364
+ };
1365
+ try {
1366
+ callCounter?.add(1, {
1367
+ operation: spanName,
1368
+ status: "started"
1369
+ });
1370
+ const result = fn.call(this, ...args);
1371
+ if (result instanceof Promise) {
1372
+ return result.then(onSuccess, onError);
1373
+ }
1374
+ return onSuccess(result);
1375
+ } catch (error) {
1376
+ return onError(error);
1362
1377
  }
1363
- return onSuccess(result);
1364
- } catch (error) {
1365
- return onError(error);
1366
- }
1367
- });
1368
- });
1378
+ });
1379
+ }
1380
+ );
1369
1381
  }
1370
1382
  wrappedFunction[INSTRUMENTED_SYMBOL] = true;
1371
1383
  Object.defineProperty(wrappedFunction, "name", {
@@ -1444,159 +1456,165 @@ function executeImmediately(fn, options) {
1444
1456
  if (options.spanKind !== void 0) {
1445
1457
  spanOptions.kind = options.spanKind;
1446
1458
  }
1447
- return tracer.startActiveSpan(spanName, spanOptions, (span2) => {
1448
- return runInOperationContext(spanName, () => {
1449
- let shouldKeepSpan = true;
1450
- setSpanName(span2, spanName);
1451
- const ctxValue = createTraceContext(span2);
1452
- const handleTailSampling = (success, duration, error) => {
1453
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1454
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1455
- success,
1456
- duration,
1457
- error
1459
+ const parentContext = getActiveContextWithBaggage();
1460
+ return tracer.startActiveSpan(
1461
+ spanName,
1462
+ spanOptions,
1463
+ parentContext,
1464
+ (span2) => {
1465
+ return runInOperationContext(spanName, () => {
1466
+ let shouldKeepSpan = true;
1467
+ setSpanName(span2, spanName);
1468
+ const ctxValue = createTraceContext(span2);
1469
+ const handleTailSampling = (success, duration, error) => {
1470
+ if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
1471
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
1472
+ success,
1473
+ duration,
1474
+ error
1475
+ });
1476
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
1477
+ span2.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
1478
+ }
1479
+ };
1480
+ const onSuccessSync = (result) => {
1481
+ const duration = performance.now() - startTime;
1482
+ callCounter?.add(1, {
1483
+ operation: spanName,
1484
+ status: "success"
1458
1485
  });
1459
- span2.setAttribute("sampling.tail.keep", shouldKeepSpan);
1460
- span2.setAttribute("sampling.tail.evaluated", true);
1461
- }
1462
- };
1463
- const onSuccessSync = (result) => {
1464
- const duration = performance.now() - startTime;
1465
- callCounter?.add(1, {
1466
- operation: spanName,
1467
- status: "success"
1468
- });
1469
- durationHistogram?.record(duration, {
1470
- operation: spanName,
1471
- status: "success"
1472
- });
1473
- span2.setStatus({ code: SpanStatusCode.OK });
1474
- span2.setAttributes({
1475
- "operation.name": spanName,
1476
- "code.function": spanName,
1477
- "operation.duration": duration,
1478
- "operation.success": true
1479
- });
1480
- handleTailSampling(true, duration);
1481
- span2.end();
1482
- void flushIfNeeded();
1483
- return result;
1484
- };
1485
- const onErrorSync = (error) => {
1486
- const duration = performance.now() - startTime;
1487
- callCounter?.add(1, {
1488
- operation: spanName,
1489
- status: "error"
1490
- });
1491
- durationHistogram?.record(duration, {
1492
- operation: spanName,
1493
- status: "error"
1494
- });
1495
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1496
- const truncatedMessage = truncateErrorMessage(errorMessage);
1497
- span2.setStatus({
1498
- code: SpanStatusCode.ERROR,
1499
- message: truncatedMessage
1500
- });
1501
- span2.setAttributes({
1502
- "operation.name": spanName,
1503
- "code.function": spanName,
1504
- "operation.duration": duration,
1505
- "operation.success": false,
1506
- error: true,
1507
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1508
- "exception.message": truncatedMessage
1509
- });
1510
- if (error instanceof Error && error.stack) {
1511
- span2.setAttribute(
1512
- "exception.stack",
1513
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1486
+ durationHistogram?.record(duration, {
1487
+ operation: spanName,
1488
+ status: "success"
1489
+ });
1490
+ span2.setStatus({ code: SpanStatusCode.OK });
1491
+ span2.setAttributes({
1492
+ "operation.name": spanName,
1493
+ "code.function": spanName,
1494
+ "operation.duration": duration,
1495
+ "operation.success": true
1496
+ });
1497
+ handleTailSampling(true, duration);
1498
+ span2.end();
1499
+ void flushIfNeeded();
1500
+ return result;
1501
+ };
1502
+ const onErrorSync = (error) => {
1503
+ const duration = performance.now() - startTime;
1504
+ callCounter?.add(1, {
1505
+ operation: spanName,
1506
+ status: "error"
1507
+ });
1508
+ durationHistogram?.record(duration, {
1509
+ operation: spanName,
1510
+ status: "error"
1511
+ });
1512
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1513
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1514
+ span2.setStatus({
1515
+ code: SpanStatusCode.ERROR,
1516
+ message: truncatedMessage
1517
+ });
1518
+ span2.setAttributes({
1519
+ "operation.name": spanName,
1520
+ "code.function": spanName,
1521
+ "operation.duration": duration,
1522
+ "operation.success": false,
1523
+ error: true,
1524
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1525
+ "exception.message": truncatedMessage
1526
+ });
1527
+ if (error instanceof Error && error.stack) {
1528
+ span2.setAttribute(
1529
+ "exception.stack",
1530
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1531
+ );
1532
+ }
1533
+ span2.recordException(
1534
+ error instanceof Error ? error : new Error(String(error))
1514
1535
  );
1515
- }
1516
- span2.recordException(
1517
- error instanceof Error ? error : new Error(String(error))
1518
- );
1519
- handleTailSampling(false, duration, error);
1520
- span2.end();
1521
- void flushIfNeeded();
1522
- throw error;
1523
- };
1524
- const onSuccessAsync = async (result) => {
1525
- const duration = performance.now() - startTime;
1526
- callCounter?.add(1, {
1527
- operation: spanName,
1528
- status: "success"
1529
- });
1530
- durationHistogram?.record(duration, {
1531
- operation: spanName,
1532
- status: "success"
1533
- });
1534
- span2.setStatus({ code: SpanStatusCode.OK });
1535
- span2.setAttributes({
1536
- "operation.name": spanName,
1537
- "code.function": spanName,
1538
- "operation.duration": duration,
1539
- "operation.success": true
1540
- });
1541
- handleTailSampling(true, duration);
1542
- span2.end();
1543
- await flushIfNeeded();
1544
- return result;
1545
- };
1546
- const onErrorAsync = async (error) => {
1547
- const duration = performance.now() - startTime;
1548
- callCounter?.add(1, {
1549
- operation: spanName,
1550
- status: "error"
1551
- });
1552
- durationHistogram?.record(duration, {
1553
- operation: spanName,
1554
- status: "error"
1555
- });
1556
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1557
- const truncatedMessage = truncateErrorMessage(errorMessage);
1558
- span2.setStatus({
1559
- code: SpanStatusCode.ERROR,
1560
- message: truncatedMessage
1561
- });
1562
- span2.setAttributes({
1563
- "operation.name": spanName,
1564
- "code.function": spanName,
1565
- "operation.duration": duration,
1566
- "operation.success": false,
1567
- error: true,
1568
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
1569
- "exception.message": truncatedMessage
1570
- });
1571
- if (error instanceof Error && error.stack) {
1572
- span2.setAttribute(
1573
- "exception.stack",
1574
- error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1536
+ handleTailSampling(false, duration, error);
1537
+ span2.end();
1538
+ void flushIfNeeded();
1539
+ throw error;
1540
+ };
1541
+ const onSuccessAsync = async (result) => {
1542
+ const duration = performance.now() - startTime;
1543
+ callCounter?.add(1, {
1544
+ operation: spanName,
1545
+ status: "success"
1546
+ });
1547
+ durationHistogram?.record(duration, {
1548
+ operation: spanName,
1549
+ status: "success"
1550
+ });
1551
+ span2.setStatus({ code: SpanStatusCode.OK });
1552
+ span2.setAttributes({
1553
+ "operation.name": spanName,
1554
+ "code.function": spanName,
1555
+ "operation.duration": duration,
1556
+ "operation.success": true
1557
+ });
1558
+ handleTailSampling(true, duration);
1559
+ span2.end();
1560
+ await flushIfNeeded();
1561
+ return result;
1562
+ };
1563
+ const onErrorAsync = async (error) => {
1564
+ const duration = performance.now() - startTime;
1565
+ callCounter?.add(1, {
1566
+ operation: spanName,
1567
+ status: "error"
1568
+ });
1569
+ durationHistogram?.record(duration, {
1570
+ operation: spanName,
1571
+ status: "error"
1572
+ });
1573
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
1574
+ const truncatedMessage = truncateErrorMessage(errorMessage);
1575
+ span2.setStatus({
1576
+ code: SpanStatusCode.ERROR,
1577
+ message: truncatedMessage
1578
+ });
1579
+ span2.setAttributes({
1580
+ "operation.name": spanName,
1581
+ "code.function": spanName,
1582
+ "operation.duration": duration,
1583
+ "operation.success": false,
1584
+ error: true,
1585
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
1586
+ "exception.message": truncatedMessage
1587
+ });
1588
+ if (error instanceof Error && error.stack) {
1589
+ span2.setAttribute(
1590
+ "exception.stack",
1591
+ error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH)
1592
+ );
1593
+ }
1594
+ span2.recordException(
1595
+ error instanceof Error ? error : new Error(String(error))
1575
1596
  );
1597
+ handleTailSampling(false, duration, error);
1598
+ span2.end();
1599
+ await flushIfNeeded();
1600
+ throw error;
1601
+ };
1602
+ try {
1603
+ callCounter?.add(1, {
1604
+ operation: spanName,
1605
+ status: "started"
1606
+ });
1607
+ const result = fn(ctxValue);
1608
+ if (result instanceof Promise) {
1609
+ return result.then(onSuccessAsync, onErrorAsync);
1610
+ }
1611
+ return onSuccessSync(result);
1612
+ } catch (error) {
1613
+ return onErrorSync(error);
1576
1614
  }
1577
- span2.recordException(
1578
- error instanceof Error ? error : new Error(String(error))
1579
- );
1580
- handleTailSampling(false, duration, error);
1581
- span2.end();
1582
- await flushIfNeeded();
1583
- throw error;
1584
- };
1585
- try {
1586
- callCounter?.add(1, {
1587
- operation: spanName,
1588
- status: "started"
1589
- });
1590
- const result = fn(ctxValue);
1591
- if (result instanceof Promise) {
1592
- return result.then(onSuccessAsync, onErrorAsync);
1593
- }
1594
- return onSuccessSync(result);
1595
- } catch (error) {
1596
- return onErrorSync(error);
1597
- }
1598
- });
1599
- });
1615
+ });
1616
+ }
1617
+ );
1600
1618
  }
1601
1619
  function trace2(fnOrNameOrOptions, maybeFn) {
1602
1620
  if (typeof fnOrNameOrOptions === "function") {
@@ -1728,7 +1746,8 @@ function span(options, fn) {
1728
1746
  }
1729
1747
  });
1730
1748
  };
1731
- const result = tracer.startActiveSpan(name, executeSpan);
1749
+ const parentContext = getActiveContextWithBaggage();
1750
+ const result = tracer.startActiveSpan(name, {}, parentContext, executeSpan);
1732
1751
  if (result instanceof Promise) {
1733
1752
  return result;
1734
1753
  }
@@ -1764,7 +1783,7 @@ function withBaggage(options) {
1764
1783
  const newContext = propagation.setBaggage(currentContext, updatedBaggage);
1765
1784
  const ctxStorage = getContextStorage();
1766
1785
  const previousStored = ctxStorage.getStore();
1767
- const baggageEnrichedStored = previousStored ? propagation.setBaggage(previousStored, updatedBaggage) : newContext;
1786
+ const baggageEnrichedStored = previousStored ? { value: propagation.setBaggage(previousStored.value, updatedBaggage) } : { value: newContext };
1768
1787
  const result = previousStored ? ctxStorage.run(baggageEnrichedStored, () => context.with(newContext, fn)) : context.with(newContext, fn);
1769
1788
  if (result instanceof Promise) {
1770
1789
  return result.then(
@@ -1788,5 +1807,5 @@ function withBaggage(options) {
1788
1807
  }
1789
1808
 
1790
1809
  export { ctx, getEventQueue, instrument, resetEventQueue, span, trace2 as trace, track, withBaggage, withNewContext, withTracing };
1791
- //# sourceMappingURL=chunk-IKRHEUS7.js.map
1792
- //# sourceMappingURL=chunk-IKRHEUS7.js.map
1810
+ //# sourceMappingURL=chunk-OPTGXEVN.js.map
1811
+ //# sourceMappingURL=chunk-OPTGXEVN.js.map