autotel 6.5.0 → 7.0.1

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 (166) hide show
  1. package/README.md +30 -23
  2. package/dist/{attribute-redacting-processor-Pk7lAzWd.d.cts → attribute-redacting-processor-CvBE0z1p.d.cts} +33 -1
  3. package/dist/{attribute-redacting-processor-Pk7lAzWd.d.ts → attribute-redacting-processor-CvBE0z1p.d.ts} +33 -1
  4. package/dist/attribute-redacting-processor.cjs +34 -32
  5. package/dist/attribute-redacting-processor.d.cts +1 -1
  6. package/dist/attribute-redacting-processor.d.ts +1 -1
  7. package/dist/attribute-redacting-processor.js +35 -32
  8. package/dist/{attributes-aDmJYral.cjs → attributes-Cxys8tgr.cjs} +34 -35
  9. package/dist/{attributes-B7wix2VG.js → attributes-Dt4YUYbP.js} +34 -35
  10. package/dist/attributes.cjs +1 -1
  11. package/dist/attributes.d.cts +1 -1
  12. package/dist/attributes.d.ts +1 -1
  13. package/dist/attributes.js +1 -1
  14. package/dist/auto.cjs +1 -1
  15. package/dist/auto.js +1 -1
  16. package/dist/business-baggage.cjs +19 -12
  17. package/dist/business-baggage.d.cts +8 -3
  18. package/dist/business-baggage.d.ts +8 -3
  19. package/dist/business-baggage.js +19 -12
  20. package/dist/{canonical-log-line-processor-DxtBGZIi.cjs → canonical-log-line-processor-DolzdawH.cjs} +43 -32
  21. package/dist/{canonical-log-line-processor-B4WgG-VS.d.cts → canonical-log-line-processor-cPB4Axk-.d.ts} +4 -3
  22. package/dist/{canonical-log-line-processor-B0vq_QR6.js → canonical-log-line-processor-hFUmS__K.js} +43 -32
  23. package/dist/{canonical-log-line-processor-CL_J7gb5.d.ts → canonical-log-line-processor-l0Aqe6yp.d.cts} +4 -3
  24. package/dist/config.d.cts +1 -1
  25. package/dist/config.d.ts +1 -1
  26. package/dist/{correlated-events-kSwLo3mi.cjs → correlated-events-CcuknWnU.cjs} +2 -1
  27. package/dist/{correlated-events-Bzh5y-UB.js → correlated-events-DwMMbItg.js} +3 -1
  28. package/dist/correlation-id.cjs +1 -1
  29. package/dist/correlation-id.js +1 -1
  30. package/dist/db.cjs +34 -19
  31. package/dist/db.js +34 -19
  32. package/dist/decorators.cjs +4 -2
  33. package/dist/decorators.d.cts +16 -11
  34. package/dist/decorators.d.ts +16 -11
  35. package/dist/decorators.js +4 -2
  36. package/dist/{define-event-CGG048HE.d.cts → define-event-BNeuKUPv.d.cts} +1 -1
  37. package/dist/{define-event-B2z1SBe7.d.ts → define-event-Bd8f8mST.d.ts} +1 -1
  38. package/dist/diagnostics.cjs +18 -16
  39. package/dist/diagnostics.d.cts +14 -10
  40. package/dist/diagnostics.d.ts +14 -10
  41. package/dist/diagnostics.js +18 -16
  42. package/dist/{event-subscriber-CWh8sTGh.d.cts → event-subscriber-DMACQA-1.d.cts} +19 -9
  43. package/dist/{event-subscriber-CWh8sTGh.d.ts → event-subscriber-DMACQA-1.d.ts} +19 -9
  44. package/dist/event-subscriber.d.cts +2 -2
  45. package/dist/event-subscriber.d.ts +2 -2
  46. package/dist/{event-testing-D0qWfqAy.d.cts → event-testing-CBtnJXE5.d.cts} +1 -1
  47. package/dist/{event-testing-CA2mIx1E.d.ts → event-testing-CkPgV3Ii.d.ts} +1 -1
  48. package/dist/event-testing.d.cts +1 -1
  49. package/dist/event-testing.d.ts +1 -1
  50. package/dist/event.cjs +1 -1
  51. package/dist/event.d.cts +5 -5
  52. package/dist/event.d.ts +5 -5
  53. package/dist/event.js +1 -1
  54. package/dist/exception-fingerprint.cjs +133 -0
  55. package/dist/exception-fingerprint.d.cts +51 -0
  56. package/dist/exception-fingerprint.d.ts +51 -0
  57. package/dist/exception-fingerprint.js +126 -0
  58. package/dist/{functional-C0uAZq2X.cjs → functional-C2ONG9PK.cjs} +27 -15
  59. package/dist/{functional-e6jw5zQj.d.cts → functional-CJn2zY4o.d.cts} +96 -39
  60. package/dist/{functional-AT22vCw6.d.ts → functional-DXy1cHFF.d.ts} +96 -39
  61. package/dist/{functional-DX7Zvag0.js → functional-nS5U4KCQ.js} +27 -15
  62. package/dist/functional.cjs +1 -1
  63. package/dist/functional.d.cts +2 -2
  64. package/dist/functional.d.ts +2 -2
  65. package/dist/functional.js +1 -1
  66. package/dist/http.cjs +11 -8
  67. package/dist/http.js +11 -8
  68. package/dist/{index-DolOVX6F.d.ts → index-CwrNAsgk.d.ts} +22 -26
  69. package/dist/{index-BPcxVucm.d.cts → index-DQHf4cNl.d.cts} +22 -26
  70. package/dist/index.cjs +41 -35
  71. package/dist/index.d.cts +45 -30
  72. package/dist/index.d.ts +45 -30
  73. package/dist/index.js +41 -35
  74. package/dist/{init-pPI3JRRf.d.ts → init-BgnYi2sm.d.ts} +6 -6
  75. package/dist/{init-CTtHITlX.cjs → init-C5aHRqi2.cjs} +111 -85
  76. package/dist/{init-WHYwyItd.js → init-DDyaLzeg.js} +106 -86
  77. package/dist/{init-ncTMKZ-s.d.cts → init-DrlL1eis.d.cts} +6 -6
  78. package/dist/instrumentation.cjs +2 -2
  79. package/dist/instrumentation.js +2 -2
  80. package/dist/{logger-D3Ej3DII.js → logger-DdPp__xW.js} +63 -54
  81. package/dist/{logger-CN4xpzMd.d.cts → logger-S1Fgl0g3.d.cts} +0 -20
  82. package/dist/{logger-CN4xpzMd.d.ts → logger-S1Fgl0g3.d.ts} +0 -20
  83. package/dist/{logger-thMPLpOG.cjs → logger-Sm66cjKl.cjs} +63 -54
  84. package/dist/logger.cjs +1 -1
  85. package/dist/logger.d.cts +1 -1
  86. package/dist/logger.d.ts +1 -1
  87. package/dist/logger.js +1 -1
  88. package/dist/messaging-adapters.cjs +26 -12
  89. package/dist/messaging-adapters.d.cts +0 -30
  90. package/dist/messaging-adapters.d.ts +0 -30
  91. package/dist/messaging-adapters.js +26 -12
  92. package/dist/messaging.cjs +37 -34
  93. package/dist/messaging.d.cts +21 -62
  94. package/dist/messaging.d.ts +21 -62
  95. package/dist/messaging.js +37 -34
  96. package/dist/{metric-testing-CpvP3ZIa.d.cts → metric-testing-86WO1wan.d.cts} +1 -1
  97. package/dist/{metric-testing-CWm6UhaR.d.ts → metric-testing-CbCxdPBp.d.ts} +1 -1
  98. package/dist/metric-testing.d.cts +1 -1
  99. package/dist/metric-testing.d.ts +1 -1
  100. package/dist/metric.d.cts +3 -3
  101. package/dist/metric.d.ts +3 -3
  102. package/dist/{node-require-vROmTeJ8.js → node-require-DSPjaw_l.js} +3 -2
  103. package/dist/{node-require-PFqDihze.cjs → node-require-EifOMikz.cjs} +3 -2
  104. package/dist/parse-error.cjs +18 -12
  105. package/dist/parse-error.d.cts +2 -1
  106. package/dist/parse-error.d.ts +2 -1
  107. package/dist/parse-error.js +19 -12
  108. package/dist/policy.cjs +0 -0
  109. package/dist/policy.js +0 -0
  110. package/dist/processors.cjs +1 -1
  111. package/dist/processors.d.cts +1 -1
  112. package/dist/processors.d.ts +1 -1
  113. package/dist/processors.js +1 -1
  114. package/dist/{sampling-BR9fkSwx.d.cts → sampling-CM5S2Lp3.d.ts} +5 -6
  115. package/dist/{sampling-CP3e7-Yr.d.ts → sampling-CmRdnXUi.d.cts} +5 -6
  116. package/dist/sampling.cjs +3 -2
  117. package/dist/sampling.d.cts +1 -1
  118. package/dist/sampling.d.ts +1 -1
  119. package/dist/sampling.js +3 -2
  120. package/dist/semantic-helpers.cjs +9 -9
  121. package/dist/semantic-helpers.d.cts +1 -1
  122. package/dist/semantic-helpers.d.ts +1 -1
  123. package/dist/semantic-helpers.js +9 -9
  124. package/dist/{stable-hash-ChFBIhNt.js → stable-hash-BkoAYVks.js} +4 -3
  125. package/dist/{stable-hash-CS9BxvVQ.cjs → stable-hash-C0pOegH_.cjs} +4 -3
  126. package/dist/{structured-error-CHg7DoIQ.cjs → structured-error--_wXpd_C.cjs} +34 -25
  127. package/dist/{structured-error-9--cxBay.js → structured-error-YIuka-FE.js} +34 -25
  128. package/dist/test-span-collector.cjs +15 -8
  129. package/dist/test-span-collector.js +15 -8
  130. package/dist/testing.cjs +16 -18
  131. package/dist/testing.d.cts +7 -6
  132. package/dist/testing.d.ts +7 -6
  133. package/dist/testing.js +16 -18
  134. package/dist/{trace-context-IuyoPyNq.d.cts → trace-context-C1Cn1q0y.d.cts} +8 -7
  135. package/dist/{trace-context-IuyoPyNq.d.ts → trace-context-f89xPJbK.d.ts} +8 -7
  136. package/dist/trace-helpers.cjs +16 -13
  137. package/dist/trace-helpers.d.cts +9 -4
  138. package/dist/trace-helpers.d.ts +9 -4
  139. package/dist/trace-helpers.js +16 -13
  140. package/dist/tracer-provider.cjs +8 -12
  141. package/dist/tracer-provider.js +8 -12
  142. package/dist/validate.cjs +22 -20
  143. package/dist/validate.d.cts +3 -2
  144. package/dist/validate.d.ts +3 -2
  145. package/dist/validate.js +22 -20
  146. package/dist/values-BenyvWKz.js +141 -0
  147. package/dist/values-CeMH-mYG.d.cts +8 -0
  148. package/dist/values-CeMH-mYG.d.ts +8 -0
  149. package/dist/values-DApyq53y.cjs +267 -0
  150. package/dist/webhook.cjs +3 -3
  151. package/dist/webhook.d.cts +1 -1
  152. package/dist/webhook.d.ts +1 -1
  153. package/dist/webhook.js +3 -3
  154. package/dist/workflow-distributed.cjs +9 -7
  155. package/dist/workflow-distributed.d.cts +9 -8
  156. package/dist/workflow-distributed.d.ts +9 -8
  157. package/dist/workflow-distributed.js +9 -7
  158. package/dist/workflow.cjs +26 -17
  159. package/dist/workflow.d.cts +1 -28
  160. package/dist/workflow.d.ts +1 -28
  161. package/dist/workflow.js +26 -17
  162. package/dist/yaml-config.cjs +26 -11
  163. package/dist/yaml-config.d.cts +9 -3
  164. package/dist/yaml-config.d.ts +9 -3
  165. package/dist/yaml-config.js +26 -11
  166. package/package.json +6 -1
@@ -1,6 +1,6 @@
1
- import { n as TraceContext } from "./trace-context-IuyoPyNq.js";
2
- import { p as Sampler } from "./sampling-CP3e7-Yr.js";
3
- import { Span, SpanKind } from "@opentelemetry/api";
1
+ import { n as TraceContext } from "./trace-context-f89xPJbK.js";
2
+ import { p as Sampler } from "./sampling-CM5S2Lp3.js";
3
+ import { Attributes, Span, SpanKind } from "@opentelemetry/api";
4
4
  //#region src/functional-wrapper.d.ts
5
5
  type WrappedFunction<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn | Promise<TReturn>;
6
6
  /**
@@ -35,9 +35,10 @@ interface TracingOptions<TArgs extends unknown[] = unknown[], TReturn = unknown>
35
35
  */
36
36
  withMetrics?: boolean;
37
37
  /** Extract attributes from function arguments. */
38
- attributesFromArgs?: (args: TArgs) => Record<string, unknown>;
38
+ attributesFromArgs?: (args: TArgs) => Attributes;
39
39
  /** Extract attributes from the function result. */
40
- attributesFromResult?: (result: TReturn) => Record<string, unknown>;
40
+ /** Receives the resolved value when the function returns a Promise. */
41
+ attributesFromResult?: (result: Awaited<TReturn>) => Attributes;
41
42
  /**
42
43
  * Capture arguments on the span as the truncated JSON `autotel.input`
43
44
  * attribute. One argument is captured directly; multiple arguments are an
@@ -72,7 +73,7 @@ interface TracingOptions<TArgs extends unknown[] = unknown[], TReturn = unknown>
72
73
  * as `redirect()` and `notFound()`.
73
74
  * @default every throw is treated as an error
74
75
  */
75
- isError?: (error: unknown) => boolean;
76
+ isError?: (cause: unknown) => boolean;
76
77
  }
77
78
  /** Options for `instrument()` batch instrumentation. */
78
79
  interface InstrumentOptions<T extends Record<string, AnyInstrumentable> = Record<string, AnyInstrumentable>> extends TracingOptions {
@@ -95,6 +96,33 @@ interface SingleInstrumentOptions<TFunction extends AnyInstrumentable = AnyInstr
95
96
  }
96
97
  //#endregion
97
98
  //#region src/functional.d.ts
99
+ /**
100
+ * Complete trace context containing trace identifiers and span methods
101
+ *
102
+ * The ctx parameter in trace() functions provides:
103
+ * - traceId, spanId, correlationId from the active span
104
+ * - Span manipulation methods (setAttribute, setAttributes, setStatus, recordException)
105
+ *
106
+ * For custom context, access it directly in your functions (standard OpenTelemetry pattern).
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * import { trace } from 'autotel'
111
+ *
112
+ * export const createUser = withTracing({})((ctx) => async (data: CreateUserData) => {
113
+ * // Get custom context directly (standard OTel approach)
114
+ * const userId = getCurrentUserId()
115
+ * const tenantId = getCurrentTenant()
116
+ *
117
+ * // Use ctx for span operations and trace IDs
118
+ * ctx.setAttribute('user.id', data.id)
119
+ * ctx.setAttribute('user.tenant', tenantId)
120
+ * console.log(ctx.traceId) // Trace IDs available
121
+ * })
122
+ * ```
123
+ */
124
+ /** Baggage entries: values that survive the W3C baggage header. */
125
+ type BaggageValues = Record<string, string | number | boolean>;
98
126
  /**
99
127
  * Get the autotel {@link TraceContext} for the currently active span.
100
128
  *
@@ -105,7 +133,7 @@ interface SingleInstrumentOptions<TFunction extends AnyInstrumentable = AnyInstr
105
133
  *
106
134
  * @example
107
135
  * ```typescript
108
- * const getUser = trace('getUser', async (id: string) => {
136
+ * const getUser = trace(async function getUser(id: string) {
109
137
  * getActiveTraceContext()?.setAttribute('user.id', id);
110
138
  * return db.users.find(id);
111
139
  * });
@@ -114,34 +142,17 @@ interface SingleInstrumentOptions<TFunction extends AnyInstrumentable = AnyInstr
114
142
  * @see getActiveSpan for the raw OpenTelemetry span
115
143
  * @see getRequestLogger which reads the active context when called with no args
116
144
  */
117
- declare function getActiveTraceContext<TBaggage extends Record<string, unknown> | undefined = undefined>(): TraceContext<TBaggage> | undefined;
118
- /**
119
- * Context object that lazily evaluates the active span on property access
120
- *
121
- * Access trace context directly without function call syntax.
122
- *
123
- * @example
124
- * ```typescript
125
- * import { trace, ctx } from 'autotel'
126
- *
127
- * export const createUser = trace(async (data) => {
128
- * // Direct property access - no function call!
129
- * if (ctx.traceId) {
130
- * ctx.setAttribute('user.id', data.id)
131
- * console.log('Trace:', ctx.traceId)
132
- * }
133
- * })
134
- * ```
135
- */
145
+ declare function getActiveTraceContext<TBaggage extends BaggageValues | undefined = undefined>(): TraceContext<TBaggage> | undefined;
136
146
  declare const ctx: TraceContext;
137
147
  /**
138
- * Wrap a plain function with automatic tracing. The function receives its real
139
- * arguments; no context parameter is injected. Use
140
- * {@link getActiveTraceContext} inside the function, or use {@link withTracing}
141
- * for the explicit `(ctx) => (...args) => result` factory form.
148
+ * Wrap a plain function with a traced wrapper, or run one named operation
149
+ * immediately with {@link trace.run}.
142
150
  *
143
- * `trace()` never executes or inspects the function during wrapper
144
- * construction.
151
+ * Every `trace(...)` call returns a **wrapper**. Nothing runs until you call
152
+ * what you get back, so a `trace()` call can never execute your function at
153
+ * module load. Reach the span from inside the body through the ambient
154
+ * {@link ctx} - it resolves at any depth, so a helper three frames down sees
155
+ * the same span without being handed anything.
145
156
  *
146
157
  * @example Auto-inferred name
147
158
  * ```typescript
@@ -150,24 +161,70 @@ declare const ctx: TraceContext;
150
161
  * })
151
162
  * ```
152
163
  *
153
- * @example Ambient context access
164
+ * @example Explicit name
154
165
  * ```typescript
155
- * export const createUser = trace(async (data) => {
156
- * getActiveTraceContext()?.setAttribute('user.id', data.id)
166
+ * export const createUser = trace('user.create', async (data) => {
157
167
  * return await db.users.create(data)
158
168
  * })
159
169
  * ```
160
170
  *
161
- * @example Explicit name
171
+ * @example Ambient context, at any depth
162
172
  * ```typescript
173
+ * import { trace, ctx } from 'autotel'
174
+ *
163
175
  * export const createUser = trace('user.create', async (data) => {
176
+ * ctx.setAttribute('user.id', data.id)
164
177
  * return await db.users.create(data)
165
178
  * })
166
179
  * ```
180
+ *
181
+ * @example Curried, for a shared configuration
182
+ * ```typescript
183
+ * const traced = trace({ serviceName: 'users' })
184
+ * export const createUser = traced(async (data) => db.users.create(data))
185
+ * ```
186
+ *
187
+ * @example One operation, run now - see {@link trace.run}
188
+ * ```typescript
189
+ * const user = await trace.run('user.create', async (ctx) => {
190
+ * ctx.setAttribute('user.id', input.id)
191
+ * return db.users.create(input)
192
+ * })
193
+ * ```
194
+ */
195
+ declare function traceImpl<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
196
+ declare function traceImpl<TArgs extends unknown[], TReturn>(name: string, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
197
+ declare function traceImpl<TArgs extends unknown[], TReturn>(options: TracingOptions<TArgs, TReturn>, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
198
+ declare function traceImpl(name: string): <TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
199
+ declare function traceImpl<TArgs extends unknown[], TReturn>(options: TracingOptions<TArgs, TReturn>): (fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
200
+ /**
201
+ * Run one named operation immediately and return its result, with the
202
+ * {@link TraceContext} passed in.
203
+ *
204
+ * This is the counterpart to {@link trace}: `trace(...)` always hands back a
205
+ * wrapper to call later, `trace.run(...)` runs the operation now. Keeping them
206
+ * under separate names is deliberate - a single call shape that sometimes
207
+ * wrapped and sometimes ran is what made dispatch depend on a callback's
208
+ * parameter name, which a minifier is free to rewrite (#166).
209
+ *
210
+ * The body can equally read the ambient {@link ctx}; the parameter is here for
211
+ * when an explicit binding reads better.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const user = await trace.run('user.create', async (ctx) => {
216
+ * ctx.setAttribute('user.id', input.id)
217
+ * return db.users.create(input)
218
+ * })
219
+ * ```
167
220
  */
168
- declare function trace$1<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
169
- declare function trace$1<TArgs extends unknown[], TReturn>(name: string, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
170
- declare function trace$1<TArgs extends unknown[], TReturn>(options: TracingOptions<TArgs, TReturn>, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
221
+ declare function run<TReturn>(name: string, operation: (ctx: TraceContext) => Promise<TReturn>): Promise<TReturn>;
222
+ declare function run<TReturn>(name: string, operation: (ctx: TraceContext) => TReturn): TReturn;
223
+ declare function run<TReturn>(options: TracingOptions<[], TReturn>, operation: (ctx: TraceContext) => Promise<TReturn>): Promise<TReturn>;
224
+ declare function run<TReturn>(options: TracingOptions<[], TReturn>, operation: (ctx: TraceContext) => TReturn): TReturn;
225
+ declare const trace$1: typeof traceImpl & {
226
+ run: typeof run;
227
+ };
171
228
  /**
172
229
  * Approach 2: withTracing() - Middleware-style composable wrapper
173
230
  *
@@ -1,7 +1,8 @@
1
+ import { l as asString, m as isDevelopment } from "./values-BenyvWKz.js";
1
2
  import { getForceFlushableProvider } from "./tracer-provider.js";
2
3
  import { getConfig } from "./config.js";
3
4
  import { AUTOTEL_SAMPLING_RATE, AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AlwaysSampler } from "./sampling.js";
4
- import { D as getActiveContextWithBaggage, O as getContextStorage, T as createTraceContext, h as getEventQueue, m as runInOperationContext, r as getSdk, t as getConfig$1 } from "./init-WHYwyItd.js";
5
+ import { D as getActiveContextWithBaggage, O as getContextStorage, T as createTraceContext, h as getEventQueue, k as hasExplicitSpanStatus, m as runInOperationContext, r as getSdk, t as getConfig$1 } from "./init-DDyaLzeg.js";
5
6
  import { setSpanName } from "./trace-helpers.js";
6
7
  import { SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
7
8
  import * as nodeFs from "node:fs";
@@ -175,9 +176,9 @@ function getSpanName(options, fn, variableName) {
175
176
  if (options.serviceName) return `${options.serviceName}.${fnName}`;
176
177
  if (fnName !== "anonymous") return fnName;
177
178
  const initConfig = getConfig$1();
178
- if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && !unknownSpanNameWarningEmitted && initConfig?.logger?.warn) {
179
+ if (isDevelopment() && !unknownSpanNameWarningEmitted && initConfig?.logger?.warn) {
179
180
  unknownSpanNameWarningEmitted = true;
180
- initConfig.logger.warn({}, "[autotel] Span name resolved to \"unknown\". Pass an explicit name, for example trace(\"operation.name\", fn).");
181
+ initConfig.logger.warn({}, "[autotel] Span name resolved to \"unknown\". Use instrument({ key: \"operation.name\", fn }) for a reusable named wrapper.");
181
182
  }
182
183
  return "unknown";
183
184
  }
@@ -204,7 +205,7 @@ function createDummyCtx() {
204
205
  function serializeCapture(value) {
205
206
  if (value === void 0) return void 0;
206
207
  try {
207
- const json = typeof value === "string" ? value : JSON.stringify(value);
208
+ const json = asString(value) ?? JSON.stringify(value);
208
209
  if (json === void 0) return void 0;
209
210
  return json.length > CAPTURE_MAX_CHARS ? `${json.slice(0, CAPTURE_MAX_CHARS)}…[truncated]` : json;
210
211
  } catch {
@@ -330,7 +331,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
330
331
  const fn = fnFactory(createTraceContext(span));
331
332
  const argsAttributes = {
332
333
  ...captureInputAttrs(args, options.captureInput),
333
- ...options.attributesFromArgs ? options.attributesFromArgs(args) : {}
334
+ ...options.attributesFromArgs?.(args)
334
335
  };
335
336
  const handleTailSampling = (success, duration, error) => {
336
337
  if (needsTailSampling && sampler.shouldKeepTrace) {
@@ -355,9 +356,9 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
355
356
  });
356
357
  const resultAttributes = {
357
358
  ...captureOutputAttrs(result, options.captureOutput),
358
- ...options.attributesFromResult ? options.attributesFromResult(result) : {}
359
+ ...options.attributesFromResult?.(result)
359
360
  };
360
- span.setStatus({ code: SpanStatusCode.OK });
361
+ if (!hasExplicitSpanStatus(span)) span.setStatus({ code: SpanStatusCode.OK });
361
362
  span.setAttributes({
362
363
  ...argsAttributes,
363
364
  ...resultAttributes,
@@ -370,8 +371,8 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
370
371
  span.end();
371
372
  return result;
372
373
  };
373
- const onError = (error) => {
374
- finalizeThrownSpan(error, options.isError, {
374
+ const onError = (cause) => {
375
+ finalizeThrownSpan(cause, options.isError, {
375
376
  span,
376
377
  spanName,
377
378
  duration: performance.now() - startTime,
@@ -380,7 +381,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
380
381
  handleTailSampling,
381
382
  extraAttributes: argsAttributes
382
383
  });
383
- throw error;
384
+ throw cause;
384
385
  };
385
386
  try {
386
387
  callCounter?.add(1, {
@@ -425,6 +426,10 @@ function wrapFactoryWithTracing(factory, options, variableName) {
425
426
  function wrapPlainWithTracing(fn, options, variableName) {
426
427
  return wrapWithTracingSync((_ctx) => fn, options, resolveVariableName(fn, variableName));
427
428
  }
429
+ /** Run one operation immediately with its span-bound context. */
430
+ function runWithTraceContext(operation, options) {
431
+ return wrapFactoryWithTracing((ctx) => () => operation(ctx), options)();
432
+ }
428
433
 
429
434
  //#endregion
430
435
  //#region src/functional.ts
@@ -490,7 +495,7 @@ function getCtxValue() {
490
495
  *
491
496
  * @example
492
497
  * ```typescript
493
- * const getUser = trace('getUser', async (id: string) => {
498
+ * const getUser = trace(async function getUser(id: string) {
494
499
  * getActiveTraceContext()?.setAttribute('user.id', id);
495
500
  * return db.users.find(id);
496
501
  * });
@@ -520,7 +525,8 @@ function getActiveTraceContext() {
520
525
  * })
521
526
  * ```
522
527
  */
523
- const ctx = new Proxy({}, {
528
+ const ctxProxyTarget = {};
529
+ const ctx = new Proxy(ctxProxyTarget, {
524
530
  get(_target, prop) {
525
531
  const ctxValue = getCtxValue();
526
532
  if (!ctxValue) return;
@@ -542,11 +548,17 @@ const ctx = new Proxy({}, {
542
548
  return Object.getOwnPropertyDescriptor(ctxValue, prop);
543
549
  }
544
550
  });
545
- function trace$1(fnOrNameOrOptions, maybeFn) {
551
+ function traceImpl(fnOrNameOrOptions, maybeFn) {
546
552
  if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
547
- if (!maybeFn) throw new Error("trace(name|options, fn): fn is required");
548
- return wrapPlainWithTracing(maybeFn, typeof fnOrNameOrOptions === "string" ? { name: fnOrNameOrOptions } : fnOrNameOrOptions);
553
+ const options = typeof fnOrNameOrOptions === "string" ? { name: fnOrNameOrOptions } : fnOrNameOrOptions;
554
+ if (maybeFn === void 0) return ((fn) => wrapPlainWithTracing(fn, options));
555
+ return wrapPlainWithTracing(maybeFn, options);
556
+ }
557
+ function run(nameOrOptions, operation) {
558
+ if (typeof operation !== "function") throw new TypeError("trace.run(name, operation): operation must be a function");
559
+ return runWithTraceContext(operation, typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions);
549
560
  }
561
+ const trace$1 = Object.assign(traceImpl, { run });
550
562
  /**
551
563
  * Approach 2: withTracing() - Middleware-style composable wrapper
552
564
  *
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_functional = require('./functional-C0uAZq2X.cjs');
2
+ const require_functional = require('./functional-C2ONG9PK.cjs');
3
3
 
4
4
  exports.ctx = require_functional.ctx;
5
5
  exports.getActiveTraceContext = require_functional.getActiveTraceContext;
@@ -1,3 +1,3 @@
1
- import { n as TraceContext } from "./trace-context-IuyoPyNq.cjs";
2
- import { a as getActiveTraceContext, c as trace, d as withTracing, f as InstrumentOptions, i as ctx, l as withBaggage, m as TracingOptions, n as WithBaggageOptions, o as instrument, p as SingleInstrumentOptions, r as WithNewContextOptions, s as span, t as SpanOptions, u as withNewContext } from "./functional-e6jw5zQj.cjs";
1
+ import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
2
+ import { a as getActiveTraceContext, c as trace, d as withTracing, f as InstrumentOptions, i as ctx, l as withBaggage, m as TracingOptions, n as WithBaggageOptions, o as instrument, p as SingleInstrumentOptions, r as WithNewContextOptions, s as span, t as SpanOptions, u as withNewContext } from "./functional-CJn2zY4o.cjs";
3
3
  export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
@@ -1,3 +1,3 @@
1
- import { n as TraceContext } from "./trace-context-IuyoPyNq.js";
2
- import { a as getActiveTraceContext, c as trace, d as withTracing, f as InstrumentOptions, i as ctx, l as withBaggage, m as TracingOptions, n as WithBaggageOptions, o as instrument, p as SingleInstrumentOptions, r as WithNewContextOptions, s as span, t as SpanOptions, u as withNewContext } from "./functional-AT22vCw6.js";
1
+ import { n as TraceContext } from "./trace-context-f89xPJbK.js";
2
+ import { a as getActiveTraceContext, c as trace, d as withTracing, f as InstrumentOptions, i as ctx, l as withBaggage, m as TracingOptions, n as WithBaggageOptions, o as instrument, p as SingleInstrumentOptions, r as WithNewContextOptions, s as span, t as SpanOptions, u as withNewContext } from "./functional-DXy1cHFF.js";
3
3
  export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
@@ -1,3 +1,3 @@
1
- import { a as trace, c as withTracing, i as span, n as getActiveTraceContext, o as withBaggage, r as instrument, s as withNewContext, t as ctx } from "./functional-DX7Zvag0.js";
1
+ import { a as trace, c as withTracing, i as span, n as getActiveTraceContext, o as withBaggage, r as instrument, s as withNewContext, t as ctx } from "./functional-nS5U4KCQ.js";
2
2
 
3
3
  export { ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
package/dist/http.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_values = require('./values-DApyq53y.cjs');
2
3
  const require_config = require('./config.cjs');
3
- const require_init = require('./init-CTtHITlX.cjs');
4
+ const require_init = require('./init-C5aHRqi2.cjs');
4
5
  let _opentelemetry_api = require("@opentelemetry/api");
5
6
 
6
7
  //#region src/http.ts
@@ -75,13 +76,13 @@ function HttpInstrumented(options = {}) {
75
76
  constructor(...args) {
76
77
  super(...args);
77
78
  const proto = target.prototype;
78
- const methodNames = Object.getOwnPropertyNames(proto).filter((name) => name !== "constructor" && typeof proto[name] === "function" && !name.startsWith("_"));
79
+ const methodNames = Object.getOwnPropertyNames(proto).filter((name) => name !== "constructor" && require_values.isFunction(require_values.readProperty(proto, name)) && !name.startsWith("_"));
79
80
  for (const methodName of methodNames) {
80
81
  const originalMethod = proto[methodName];
81
82
  if (originalMethod.constructor.name === "AsyncFunction" || originalMethod.toString().startsWith("async ")) {
82
83
  const wrappedMethod = async (...args) => {
83
84
  const tracer = require_config.getConfig().tracer;
84
- const url = options.urlExtractor ? options.urlExtractor(args) : args[0];
85
+ const url = options.urlExtractor ? options.urlExtractor(args) : require_values.asString(args[0]);
85
86
  const method = options.methodExtractor ? options.methodExtractor(methodName, args) : inferHttpMethod(methodName);
86
87
  const spanName = url ? `HTTP ${method} ${extractPath(url)}` : `HTTP ${method}`;
87
88
  return tracer.startActiveSpan(spanName, async (span) => {
@@ -136,7 +137,12 @@ function HttpInstrumented(options = {}) {
136
137
  }
137
138
  });
138
139
  };
139
- this[methodName] = wrappedMethod;
140
+ Object.defineProperty(this, methodName, {
141
+ value: wrappedMethod,
142
+ writable: true,
143
+ enumerable: true,
144
+ configurable: true
145
+ });
140
146
  }
141
147
  }
142
148
  }
@@ -207,10 +213,7 @@ function parseUrl(url) {
207
213
  }
208
214
  }
209
215
  function extractStatusCode(result) {
210
- if (result && typeof result === "object") {
211
- if ("status" in result && typeof result.status === "number") return result.status;
212
- if ("statusCode" in result && typeof result.statusCode === "number") return result.statusCode;
213
- }
216
+ return require_values.asNumber(require_values.readProperty(result, "status")) ?? require_values.asNumber(require_values.readProperty(result, "statusCode"));
214
217
  }
215
218
  /**
216
219
  * Inject trace context into HTTP headers (for distributed tracing)
package/dist/http.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { _ as readProperty, h as isFunction, i as asNumber, l as asString } from "./values-BenyvWKz.js";
1
2
  import { getConfig } from "./config.js";
2
- import { D as getActiveContextWithBaggage } from "./init-WHYwyItd.js";
3
+ import { D as getActiveContextWithBaggage } from "./init-DDyaLzeg.js";
3
4
  import { SpanStatusCode, context, propagation } from "@opentelemetry/api";
4
5
 
5
6
  //#region src/http.ts
@@ -74,13 +75,13 @@ function HttpInstrumented(options = {}) {
74
75
  constructor(...args) {
75
76
  super(...args);
76
77
  const proto = target.prototype;
77
- const methodNames = Object.getOwnPropertyNames(proto).filter((name) => name !== "constructor" && typeof proto[name] === "function" && !name.startsWith("_"));
78
+ const methodNames = Object.getOwnPropertyNames(proto).filter((name) => name !== "constructor" && isFunction(readProperty(proto, name)) && !name.startsWith("_"));
78
79
  for (const methodName of methodNames) {
79
80
  const originalMethod = proto[methodName];
80
81
  if (originalMethod.constructor.name === "AsyncFunction" || originalMethod.toString().startsWith("async ")) {
81
82
  const wrappedMethod = async (...args) => {
82
83
  const tracer = getConfig().tracer;
83
- const url = options.urlExtractor ? options.urlExtractor(args) : args[0];
84
+ const url = options.urlExtractor ? options.urlExtractor(args) : asString(args[0]);
84
85
  const method = options.methodExtractor ? options.methodExtractor(methodName, args) : inferHttpMethod(methodName);
85
86
  const spanName = url ? `HTTP ${method} ${extractPath(url)}` : `HTTP ${method}`;
86
87
  return tracer.startActiveSpan(spanName, async (span) => {
@@ -135,7 +136,12 @@ function HttpInstrumented(options = {}) {
135
136
  }
136
137
  });
137
138
  };
138
- this[methodName] = wrappedMethod;
139
+ Object.defineProperty(this, methodName, {
140
+ value: wrappedMethod,
141
+ writable: true,
142
+ enumerable: true,
143
+ configurable: true
144
+ });
139
145
  }
140
146
  }
141
147
  }
@@ -206,10 +212,7 @@ function parseUrl(url) {
206
212
  }
207
213
  }
208
214
  function extractStatusCode(result) {
209
- if (result && typeof result === "object") {
210
- if ("status" in result && typeof result.status === "number") return result.status;
211
- if ("statusCode" in result && typeof result.statusCode === "number") return result.statusCode;
212
- }
215
+ return asNumber(readProperty(result, "status")) ?? asNumber(readProperty(result, "statusCode"));
213
216
  }
214
217
  /**
215
218
  * Inject trace context into HTTP headers (for distributed tracing)
@@ -1,6 +1,6 @@
1
- import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-IuyoPyNq.js";
1
+ import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-f89xPJbK.js";
2
2
  import { Resource } from "@opentelemetry/resources";
3
- import { Span } from "@opentelemetry/api";
3
+ import { AttributeValue, Attributes, Span } from "@opentelemetry/api";
4
4
  //#region src/attributes/types.d.ts
5
5
  interface UserAttrs {
6
6
  id?: string;
@@ -201,7 +201,7 @@ declare const attrs: {
201
201
  readonly roles: (value: string[]) => {
202
202
  "user.roles": string[];
203
203
  };
204
- readonly data: (data: UserAttrs) => Record<string, unknown>;
204
+ readonly data: (data: UserAttrs) => Attributes;
205
205
  };
206
206
  readonly session: {
207
207
  readonly id: (value: string) => {
@@ -210,7 +210,7 @@ declare const attrs: {
210
210
  readonly previousId: (value: string) => {
211
211
  "session.previous_id": string;
212
212
  };
213
- readonly data: (data: SessionAttrs) => Record<string, unknown>;
213
+ readonly data: (data: SessionAttrs) => Attributes;
214
214
  };
215
215
  readonly device: {
216
216
  readonly id: (value: string) => {
@@ -225,7 +225,7 @@ declare const attrs: {
225
225
  readonly modelName: (value: string) => {
226
226
  "device.model.name": string;
227
227
  };
228
- readonly data: (data: DeviceAttrs) => Record<string, unknown>;
228
+ readonly data: (data: DeviceAttrs) => Attributes;
229
229
  };
230
230
  readonly http: {
231
231
  readonly request: {
@@ -262,8 +262,8 @@ declare const attrs: {
262
262
  readonly connectionState: (value: string) => {
263
263
  "http.connection.state": string;
264
264
  };
265
- readonly server: (data: HTTPServerAttrs) => Record<string, unknown>;
266
- readonly client: (data: HTTPClientAttrs) => Record<string, unknown>;
265
+ readonly server: (data: HTTPServerAttrs) => Attributes;
266
+ readonly client: (data: HTTPClientAttrs) => Attributes;
267
267
  };
268
268
  readonly db: {
269
269
  readonly client: {
@@ -294,7 +294,7 @@ declare const attrs: {
294
294
  readonly rowsReturned: (value: number) => {
295
295
  "db.response.returned_rows": number;
296
296
  };
297
- readonly data: (data: DBAttrs) => Record<string, unknown>;
297
+ readonly data: (data: DBAttrs) => Attributes;
298
298
  };
299
299
  };
300
300
  readonly service: {
@@ -307,7 +307,7 @@ declare const attrs: {
307
307
  readonly version: (value: string) => {
308
308
  "service.version": string;
309
309
  };
310
- readonly data: (data: ServiceAttrs) => Record<string, unknown>;
310
+ readonly data: (data: ServiceAttrs) => Attributes;
311
311
  };
312
312
  readonly network: {
313
313
  readonly peerAddress: (value: string) => {
@@ -325,7 +325,7 @@ declare const attrs: {
325
325
  readonly protocolVersion: (value: string) => {
326
326
  "network.protocol.version": string;
327
327
  };
328
- readonly data: (data: NetworkAttrs) => Record<string, unknown>;
328
+ readonly data: (data: NetworkAttrs) => Attributes;
329
329
  };
330
330
  readonly server: {
331
331
  readonly address: (value: string) => {
@@ -337,7 +337,7 @@ declare const attrs: {
337
337
  readonly socketAddress: (value: string) => {
338
338
  "server.socket.address": string;
339
339
  };
340
- readonly data: (data: ServerAddressAttrs) => Record<string, unknown>;
340
+ readonly data: (data: ServerAddressAttrs) => Attributes;
341
341
  };
342
342
  readonly url: {
343
343
  readonly scheme: (value: string) => {
@@ -355,7 +355,7 @@ declare const attrs: {
355
355
  readonly fragment: (value: string) => {
356
356
  "url.fragment": string;
357
357
  };
358
- readonly data: (data: URLAttrs) => Record<string, unknown>;
358
+ readonly data: (data: URLAttrs) => Attributes;
359
359
  };
360
360
  readonly error: {
361
361
  readonly type: (value: string) => {
@@ -370,7 +370,7 @@ declare const attrs: {
370
370
  readonly code: (value: string | number) => {
371
371
  "error.code": string | number;
372
372
  };
373
- readonly data: (data: ErrorAttrs) => Record<string, unknown>;
373
+ readonly data: (data: ErrorAttrs) => Attributes;
374
374
  };
375
375
  readonly exception: {
376
376
  readonly escaped: (value: boolean) => {
@@ -388,7 +388,7 @@ declare const attrs: {
388
388
  readonly moduleName: (value: string) => {
389
389
  "exception.module": string;
390
390
  };
391
- readonly data: (data: ExceptionAttrs) => Record<string, unknown>;
391
+ readonly data: (data: ExceptionAttrs) => Attributes;
392
392
  };
393
393
  readonly process: {
394
394
  readonly pid: (value: number) => {
@@ -403,7 +403,7 @@ declare const attrs: {
403
403
  readonly owner: (value: string) => {
404
404
  "process.owner": string;
405
405
  };
406
- readonly data: (data: ProcessAttrs) => Record<string, unknown>;
406
+ readonly data: (data: ProcessAttrs) => Attributes;
407
407
  };
408
408
  readonly thread: {
409
409
  readonly id: (value: number) => {
@@ -426,7 +426,7 @@ declare const attrs: {
426
426
  readonly tag: (value: string) => {
427
427
  "container.image.tag": string;
428
428
  };
429
- readonly data: (data: ContainerAttrs) => Record<string, unknown>;
429
+ readonly data: (data: ContainerAttrs) => Attributes;
430
430
  };
431
431
  readonly k8s: {
432
432
  readonly podName: (value: string) => {
@@ -458,7 +458,7 @@ declare const attrs: {
458
458
  readonly platform: (value: string) => {
459
459
  "cloud.platform": string;
460
460
  };
461
- readonly data: (data: CloudAttrs) => Record<string, unknown>;
461
+ readonly data: (data: CloudAttrs) => Attributes;
462
462
  };
463
463
  readonly faas: {
464
464
  readonly name: (value: string) => {
@@ -504,7 +504,7 @@ declare const attrs: {
504
504
  readonly conversationId: (value: string) => {
505
505
  "messaging.conversation_id": string;
506
506
  };
507
- readonly data: (data: MessagingAttrs) => Record<string, unknown>;
507
+ readonly data: (data: MessagingAttrs) => Attributes;
508
508
  };
509
509
  readonly rpc: {
510
510
  readonly system: (value: string) => {
@@ -588,10 +588,6 @@ declare const attrs: {
588
588
  };
589
589
  //#endregion
590
590
  //#region src/attributes/validators.d.ts
591
- /**
592
- * Attribute validation, PII detection, and guardrails
593
- * Provides safe-by-default attribute handling with configurable policies
594
- */
595
591
  interface AttributeGuardrails {
596
592
  /** How to handle PII in attributes */
597
593
  pii?: 'allow' | 'redact' | 'hash' | 'block';
@@ -609,9 +605,9 @@ interface AttributePolicy {
609
605
  /** Custom deprecation warnings for specific attributes */
610
606
  deprecatedWarnings?: Record<string, string>;
611
607
  }
612
- declare function validateAttribute(key: string, value: unknown, policy?: AttributePolicy): unknown;
608
+ declare function validateAttribute(key: string, value: AttributeValue | undefined, policy?: AttributePolicy): AttributeValue | undefined;
613
609
  declare function checkDeprecatedAttribute(key: string, policy?: AttributePolicy): string | null;
614
- declare function autoRedactPII(attributes: Record<string, unknown>, policy?: AttributePolicy): Record<string, unknown>;
610
+ declare function autoRedactPII(attributes: Attributes, policy?: AttributePolicy): Attributes;
615
611
  declare function defaultGuardrails(): AttributeGuardrails;
616
612
  //#endregion
617
613
  //#region src/attributes/attachers.d.ts
@@ -670,7 +666,7 @@ declare function transaction(spanOrContext: TraceContext, config: {
670
666
  type AttributeSetter = {
671
667
  setAttributes: (attrs: Record<string, AttributeValue$1>) => void;
672
668
  };
673
- declare function mergeAttrs(...attrSets: Array<Record<string, unknown> | undefined>): Record<string, unknown>;
674
- declare function safeSetAttributes(span: AttributeSetter, attrs: Record<string, unknown>, policy?: AttributePolicy): void;
669
+ declare function mergeAttrs(...attrSets: Array<Attributes | undefined>): Attributes;
670
+ declare function safeSetAttributes(span: AttributeSetter, attrs: Attributes, policy?: AttributePolicy): void;
675
671
  //#endregion
676
672
  export { ExceptionAttrs as A, PeerAttrs as B, CloudAttrs as C, DeploymentAttrs as D, DBAttrs as E, HTTPServerAttrs as F, SessionAttrs as G, RPCAttrs as H, K8sAttrs as I, URLAttrs as J, TLSAttrs as K, MessagingAttrs as L, FeatureFlagAttrs as M, GraphQLAttrs as N, DeviceAttrs as O, HTTPClientAttrs as P, NetworkAttrs as R, ClientAttrs as S, ContainerAttrs as T, ServerAddressAttrs as U, ProcessAttrs as V, ServiceAttrs as W, UserAttrs as Y, autoRedactPII as _, httpClient as a, validateAttribute as b, mergeServiceResource as c, setError as d, setException as f, AttributePolicy as g, AttributeGuardrails as h, dbClient as i, FaaSAttrs as j, ErrorAttrs as k, request as l, setUser as m, safeSetAttributes as n, httpServer as o, setSession as p, ThreadAttrs as q, transaction as r, identify as s, mergeAttrs as t, setDevice as u, checkDeprecatedAttribute as v, CodeAttrs as w, attrs as x, defaultGuardrails as y, OTelAttrs as z };