autotel 7.6.2 → 7.7.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 (75) hide show
  1. package/dist/attributes.d.cts +1 -1
  2. package/dist/attributes.d.ts +1 -1
  3. package/dist/auto.cjs +1 -1
  4. package/dist/auto.js +1 -1
  5. package/dist/business-baggage.d.cts +1 -1
  6. package/dist/business-baggage.d.ts +1 -1
  7. package/dist/correlation-id.cjs +1 -1
  8. package/dist/correlation-id.js +1 -1
  9. package/dist/db.cjs +1 -1
  10. package/dist/db.js +1 -1
  11. package/dist/decorators.cjs +1 -1
  12. package/dist/decorators.d.cts +2 -2
  13. package/dist/decorators.d.ts +2 -2
  14. package/dist/decorators.js +1 -1
  15. package/dist/event.cjs +1 -1
  16. package/dist/event.js +1 -1
  17. package/dist/{functional-CgWcRXGX.d.cts → functional-C4mjgtJb.d.cts} +25 -2
  18. package/dist/{functional-RFFpQzAV.d.ts → functional-DN_ztd9C.d.ts} +25 -2
  19. package/dist/{functional-DzIFi7ml.js → functional-S9IJNlBn.js} +111 -26
  20. package/dist/{functional-uOagkiCk.cjs → functional-UIJ0CaTV.cjs} +114 -23
  21. package/dist/functional.cjs +2 -1
  22. package/dist/functional.d.cts +3 -3
  23. package/dist/functional.d.ts +3 -3
  24. package/dist/functional.js +2 -2
  25. package/dist/http.cjs +1 -1
  26. package/dist/http.js +1 -1
  27. package/dist/{index-Y7If_wH4.d.cts → index-8bFU4kmd.d.cts} +1 -1
  28. package/dist/{index-CsoeCsGL.d.ts → index-o_6YjZhV.d.ts} +1 -1
  29. package/dist/index.cjs +4 -3
  30. package/dist/index.d.cts +14 -5
  31. package/dist/index.d.ts +14 -5
  32. package/dist/index.js +4 -4
  33. package/dist/{init-zGVUHByM.cjs → init-BYXDCfRL.cjs} +57 -20
  34. package/dist/{init-BHV2gWsV.d.ts → init-CKSMbJUG.d.ts} +17 -1
  35. package/dist/{init-Dwj1goyE.js → init-Dyq6WtsO.js} +57 -20
  36. package/dist/{init-DxmeJ3d0.d.cts → init-WwjD-kQu.d.cts} +17 -1
  37. package/dist/instrumentation.cjs +1 -1
  38. package/dist/instrumentation.js +1 -1
  39. package/dist/messaging.cjs +2 -2
  40. package/dist/messaging.d.cts +1 -1
  41. package/dist/messaging.d.ts +1 -1
  42. package/dist/messaging.js +2 -2
  43. package/dist/sampling.cjs +1 -1
  44. package/dist/sampling.js +1 -1
  45. package/dist/semantic-helpers.cjs +1 -1
  46. package/dist/semantic-helpers.d.cts +1 -1
  47. package/dist/semantic-helpers.d.ts +1 -1
  48. package/dist/semantic-helpers.js +1 -1
  49. package/dist/{structured-error-BI9PFKZr.cjs → structured-error-BAXhglRE.cjs} +47 -24
  50. package/dist/{structured-error-XpBdwnmv.js → structured-error-Y9y-1Pae.js} +47 -24
  51. package/dist/tail-sampling-processor.cjs +1 -1
  52. package/dist/tail-sampling-processor.js +1 -1
  53. package/dist/testing.cjs +14 -0
  54. package/dist/testing.js +15 -1
  55. package/dist/{trace-context-f89xPJbK.d.ts → trace-context-CqCblIQE.d.ts} +12 -5
  56. package/dist/{trace-context-C1Cn1q0y.d.cts → trace-context-f7Xq0Q2q.d.cts} +12 -5
  57. package/dist/validate.cjs +1 -1
  58. package/dist/validate.js +1 -1
  59. package/dist/webhook.cjs +2 -2
  60. package/dist/webhook.d.cts +1 -1
  61. package/dist/webhook.d.ts +1 -1
  62. package/dist/webhook.js +2 -2
  63. package/dist/workflow-distributed.cjs +1 -1
  64. package/dist/workflow-distributed.d.cts +1 -1
  65. package/dist/workflow-distributed.d.ts +1 -1
  66. package/dist/workflow-distributed.js +1 -1
  67. package/dist/workflow.cjs +1 -1
  68. package/dist/workflow.d.cts +1 -1
  69. package/dist/workflow.d.ts +1 -1
  70. package/dist/workflow.js +1 -1
  71. package/dist/yaml-config.cjs +1 -1
  72. package/dist/yaml-config.d.cts +2 -2
  73. package/dist/yaml-config.d.ts +2 -2
  74. package/dist/yaml-config.js +1 -1
  75. package/package.json +419 -159
@@ -1,2 +1,2 @@
1
- import { A as ExceptionAttrs, B as PeerAttrs, C as CloudAttrs, D as DeploymentAttrs, E as DBAttrs, F as HTTPServerAttrs, G as SessionAttrs, H as RPCAttrs, I as K8sAttrs, J as URLAttrs, K as TLSAttrs, L as MessagingAttrs, M as FeatureFlagAttrs, N as GraphQLAttrs, O as DeviceAttrs, P as HTTPClientAttrs, R as NetworkAttrs, S as ClientAttrs, T as ContainerAttrs, U as ServerAddressAttrs, V as ProcessAttrs, W as ServiceAttrs, Y as UserAttrs, _ as autoRedactPII, a as httpClient, b as validateAttribute, c as mergeServiceResource, d as setError, f as setException, g as AttributePolicy, h as AttributeGuardrails, i as dbClient, j as FaaSAttrs, k as ErrorAttrs, l as request, m as setUser, n as safeSetAttributes, o as httpServer, p as setSession, q as ThreadAttrs, r as transaction, s as identify, t as mergeAttrs, u as setDevice, v as checkDeprecatedAttribute, w as CodeAttrs, x as attrs, y as defaultGuardrails, z as OTelAttrs } from "./index-Y7If_wH4.cjs";
1
+ import { A as ExceptionAttrs, B as PeerAttrs, C as CloudAttrs, D as DeploymentAttrs, E as DBAttrs, F as HTTPServerAttrs, G as SessionAttrs, H as RPCAttrs, I as K8sAttrs, J as URLAttrs, K as TLSAttrs, L as MessagingAttrs, M as FeatureFlagAttrs, N as GraphQLAttrs, O as DeviceAttrs, P as HTTPClientAttrs, R as NetworkAttrs, S as ClientAttrs, T as ContainerAttrs, U as ServerAddressAttrs, V as ProcessAttrs, W as ServiceAttrs, Y as UserAttrs, _ as autoRedactPII, a as httpClient, b as validateAttribute, c as mergeServiceResource, d as setError, f as setException, g as AttributePolicy, h as AttributeGuardrails, i as dbClient, j as FaaSAttrs, k as ErrorAttrs, l as request, m as setUser, n as safeSetAttributes, o as httpServer, p as setSession, q as ThreadAttrs, r as transaction, s as identify, t as mergeAttrs, u as setDevice, v as checkDeprecatedAttribute, w as CodeAttrs, x as attrs, y as defaultGuardrails, z as OTelAttrs } from "./index-8bFU4kmd.cjs";
2
2
  export { type AttributeGuardrails, type AttributePolicy, type ClientAttrs, type CloudAttrs, type CodeAttrs, type ContainerAttrs, type DBAttrs, type DeploymentAttrs, type DeviceAttrs, type ErrorAttrs, type ExceptionAttrs, type FaaSAttrs, type FeatureFlagAttrs, type GraphQLAttrs, type HTTPClientAttrs, type HTTPServerAttrs, type K8sAttrs, type MessagingAttrs, type NetworkAttrs, type OTelAttrs, type PeerAttrs, type ProcessAttrs, type RPCAttrs, type ServerAddressAttrs, type ServiceAttrs, type SessionAttrs, type TLSAttrs, type ThreadAttrs, type URLAttrs, type UserAttrs, attrs, autoRedactPII, checkDeprecatedAttribute, dbClient, defaultGuardrails, httpClient, httpServer, identify, mergeAttrs, mergeServiceResource, request, safeSetAttributes, setDevice, setError, setException, setSession, setUser, transaction, validateAttribute };
@@ -1,2 +1,2 @@
1
- import { A as ExceptionAttrs, B as PeerAttrs, C as CloudAttrs, D as DeploymentAttrs, E as DBAttrs, F as HTTPServerAttrs, G as SessionAttrs, H as RPCAttrs, I as K8sAttrs, J as URLAttrs, K as TLSAttrs, L as MessagingAttrs, M as FeatureFlagAttrs, N as GraphQLAttrs, O as DeviceAttrs, P as HTTPClientAttrs, R as NetworkAttrs, S as ClientAttrs, T as ContainerAttrs, U as ServerAddressAttrs, V as ProcessAttrs, W as ServiceAttrs, Y as UserAttrs, _ as autoRedactPII, a as httpClient, b as validateAttribute, c as mergeServiceResource, d as setError, f as setException, g as AttributePolicy, h as AttributeGuardrails, i as dbClient, j as FaaSAttrs, k as ErrorAttrs, l as request, m as setUser, n as safeSetAttributes, o as httpServer, p as setSession, q as ThreadAttrs, r as transaction, s as identify, t as mergeAttrs, u as setDevice, v as checkDeprecatedAttribute, w as CodeAttrs, x as attrs, y as defaultGuardrails, z as OTelAttrs } from "./index-CsoeCsGL.js";
1
+ import { A as ExceptionAttrs, B as PeerAttrs, C as CloudAttrs, D as DeploymentAttrs, E as DBAttrs, F as HTTPServerAttrs, G as SessionAttrs, H as RPCAttrs, I as K8sAttrs, J as URLAttrs, K as TLSAttrs, L as MessagingAttrs, M as FeatureFlagAttrs, N as GraphQLAttrs, O as DeviceAttrs, P as HTTPClientAttrs, R as NetworkAttrs, S as ClientAttrs, T as ContainerAttrs, U as ServerAddressAttrs, V as ProcessAttrs, W as ServiceAttrs, Y as UserAttrs, _ as autoRedactPII, a as httpClient, b as validateAttribute, c as mergeServiceResource, d as setError, f as setException, g as AttributePolicy, h as AttributeGuardrails, i as dbClient, j as FaaSAttrs, k as ErrorAttrs, l as request, m as setUser, n as safeSetAttributes, o as httpServer, p as setSession, q as ThreadAttrs, r as transaction, s as identify, t as mergeAttrs, u as setDevice, v as checkDeprecatedAttribute, w as CodeAttrs, x as attrs, y as defaultGuardrails, z as OTelAttrs } from "./index-o_6YjZhV.js";
2
2
  export { type AttributeGuardrails, type AttributePolicy, type ClientAttrs, type CloudAttrs, type CodeAttrs, type ContainerAttrs, type DBAttrs, type DeploymentAttrs, type DeviceAttrs, type ErrorAttrs, type ExceptionAttrs, type FaaSAttrs, type FeatureFlagAttrs, type GraphQLAttrs, type HTTPClientAttrs, type HTTPServerAttrs, type K8sAttrs, type MessagingAttrs, type NetworkAttrs, type OTelAttrs, type PeerAttrs, type ProcessAttrs, type RPCAttrs, type ServerAddressAttrs, type ServiceAttrs, type SessionAttrs, type TLSAttrs, type ThreadAttrs, type URLAttrs, type UserAttrs, attrs, autoRedactPII, checkDeprecatedAttribute, dbClient, defaultGuardrails, httpClient, httpServer, identify, mergeAttrs, mergeServiceResource, request, safeSetAttributes, setDevice, setError, setException, setSession, setUser, transaction, validateAttribute };
package/dist/auto.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
2
- const require_init = require('./init-zGVUHByM.cjs');
2
+ const require_init = require('./init-BYXDCfRL.cjs');
3
3
  let node_module = require("node:module");
4
4
  node_module = require_rolldown_runtime.__toESM(node_module, 1);
5
5
  let import_in_the_middle = require("import-in-the-middle");
package/dist/auto.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as loadYamlConfig, a as init } from "./init-Dwj1goyE.js";
1
+ import { _ as loadYamlConfig, a as init } from "./init-Dyq6WtsO.js";
2
2
  import * as nodeModule from "node:module";
3
3
  import { createAddHookMessageChannel } from "import-in-the-middle";
4
4
 
@@ -1,4 +1,4 @@
1
- import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
1
+ import { n as TraceContext } from "./trace-context-f7Xq0Q2q.cjs";
2
2
  //#region src/business-baggage.d.ts
3
3
  /**
4
4
  * Supported field types in baggage schema
@@ -1,4 +1,4 @@
1
- import { n as TraceContext } from "./trace-context-f89xPJbK.js";
1
+ import { n as TraceContext } from "./trace-context-CqCblIQE.js";
2
2
  //#region src/business-baggage.d.ts
3
3
  /**
4
4
  * Supported field types in baggage schema
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_init = require('./init-zGVUHByM.cjs');
2
+ const require_init = require('./init-BYXDCfRL.cjs');
3
3
 
4
4
  exports.CORRELATION_ID_BAGGAGE_KEY = require_init.CORRELATION_ID_BAGGAGE_KEY;
5
5
  exports.generateCorrelationId = require_init.generateCorrelationId;
@@ -1,3 +1,3 @@
1
- import { $ as getCorrelationStorage, Q as getCorrelationId, X as CORRELATION_ID_BAGGAGE_KEY, Z as generateCorrelationId, et as getOrCreateCorrelationId, nt as setCorrelationId, rt as setCorrelationIdInBaggage, tt as runWithCorrelationId } from "./init-Dwj1goyE.js";
1
+ import { $ as getCorrelationStorage, Q as getCorrelationId, X as CORRELATION_ID_BAGGAGE_KEY, Z as generateCorrelationId, et as getOrCreateCorrelationId, nt as setCorrelationId, rt as setCorrelationIdInBaggage, tt as runWithCorrelationId } from "./init-Dyq6WtsO.js";
2
2
 
3
3
  export { CORRELATION_ID_BAGGAGE_KEY, generateCorrelationId, getCorrelationId, getCorrelationStorage, getOrCreateCorrelationId, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage };
package/dist/db.cjs CHANGED
@@ -171,7 +171,6 @@ function instrumentDatabase(client, options) {
171
171
  const target = clientMembers(client);
172
172
  if (target[INSTRUMENTED_SYMBOL]) return client;
173
173
  const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
174
- const tracer = require_config.getConfig().tracer;
175
174
  const methodsToInstrument = methods || extractDatabaseMethods(client);
176
175
  const skipSet = new Set(skipMethods);
177
176
  for (const methodName of methodsToInstrument) {
@@ -184,6 +183,7 @@ function instrumentDatabase(client, options) {
184
183
  const operation = inferDbOperation(methodName);
185
184
  const table = inferTableName(methodName);
186
185
  const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
186
+ const { tracer } = require_config.getConfig();
187
187
  return tracer.startActiveSpan(spanName, async (span) => {
188
188
  const startTime = performance.now();
189
189
  try {
package/dist/db.js CHANGED
@@ -170,7 +170,6 @@ function instrumentDatabase(client, options) {
170
170
  const target = clientMembers(client);
171
171
  if (target[INSTRUMENTED_SYMBOL]) return client;
172
172
  const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
173
- const tracer = getConfig().tracer;
174
173
  const methodsToInstrument = methods || extractDatabaseMethods(client);
175
174
  const skipSet = new Set(skipMethods);
176
175
  for (const methodName of methodsToInstrument) {
@@ -183,6 +182,7 @@ function instrumentDatabase(client, options) {
183
182
  const operation = inferDbOperation(methodName);
184
183
  const table = inferTableName(methodName);
185
184
  const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
185
+ const { tracer } = getConfig();
186
186
  return tracer.startActiveSpan(spanName, async (span) => {
187
187
  const startTime = performance.now();
188
188
  try {
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_values = require('./values-tm4bi0FF.cjs');
3
3
  const require_config = require('./config.cjs');
4
- const require_init = require('./init-zGVUHByM.cjs');
4
+ const require_init = require('./init-BYXDCfRL.cjs');
5
5
  let _opentelemetry_api = require("@opentelemetry/api");
6
6
 
7
7
  //#region src/decorators.ts
@@ -1,5 +1,5 @@
1
- import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
2
- import { m as TracingOptions } from "./functional-CgWcRXGX.cjs";
1
+ import { n as TraceContext } from "./trace-context-f7Xq0Q2q.cjs";
2
+ import { h as TracingOptions } from "./functional-C4mjgtJb.cjs";
3
3
  //#region src/decorators.d.ts
4
4
  /**
5
5
  * Options for @Trace method decorator
@@ -1,5 +1,5 @@
1
- import { n as TraceContext } from "./trace-context-f89xPJbK.js";
2
- import { m as TracingOptions } from "./functional-RFFpQzAV.js";
1
+ import { n as TraceContext } from "./trace-context-CqCblIQE.js";
2
+ import { h as TracingOptions } from "./functional-DN_ztd9C.js";
3
3
  //#region src/decorators.d.ts
4
4
  /**
5
5
  * Options for @Trace method decorator
@@ -1,6 +1,6 @@
1
1
  import { y as splitNameOrOptions } from "./values-xBtdXtjA.js";
2
2
  import { getConfig } from "./config.js";
3
- import { U as createTraceContext } from "./init-Dwj1goyE.js";
3
+ import { U as createTraceContext } from "./init-Dyq6WtsO.js";
4
4
  import { SpanStatusCode } from "@opentelemetry/api";
5
5
 
6
6
  //#region src/decorators.ts
package/dist/event.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_init = require('./init-zGVUHByM.cjs');
2
+ const require_init = require('./init-BYXDCfRL.cjs');
3
3
 
4
4
  exports.Event = require_init.Event;
5
5
  exports.getEvents = require_init.getEvents;
package/dist/event.js CHANGED
@@ -1,3 +1,3 @@
1
- import { d as Event, f as getEvents, p as resetEvents } from "./init-Dwj1goyE.js";
1
+ import { d as Event, f as getEvents, p as resetEvents } from "./init-Dyq6WtsO.js";
2
2
 
3
3
  export { Event, getEvents, resetEvents };
@@ -1,4 +1,4 @@
1
- import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
1
+ import { n as TraceContext } from "./trace-context-f7Xq0Q2q.cjs";
2
2
  import { m as Sampler } from "./sampling-Er217Mge.cjs";
3
3
  import { Attributes, Span, SpanKind } from "@opentelemetry/api";
4
4
  //#region src/functional-wrapper.d.ts
@@ -144,6 +144,29 @@ type BaggageValues = Record<string, string | number | boolean>;
144
144
  */
145
145
  declare function getActiveTraceContext<TBaggage extends BaggageValues | undefined = undefined>(): TraceContext<TBaggage> | undefined;
146
146
  declare const ctx: TraceContext;
147
+ /**
148
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
149
+ * whatever span the calling code happens to be inside.
150
+ *
151
+ * Framework instrumentation nests spans per layer - express opens one per
152
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
153
+ * middleware records on a span that ends the moment `next()` fires. Attributes
154
+ * that describe the request as a whole (the authenticated user, the tenant, the
155
+ * plan) belong on the request span, which is what a backend shows as the
156
+ * resource and what a canonical log line is built from.
157
+ *
158
+ * Falls back to the active span outside a request, and no-ops when nothing is
159
+ * active at all, exactly as `ctx` does.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * app.use((req, _res, next) => {
164
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
165
+ * next();
166
+ * });
167
+ * ```
168
+ */
169
+ declare const requestCtx: TraceContext;
147
170
  /**
148
171
  * Wrap a plain function with a traced wrapper, or run one named operation
149
172
  * immediately with {@link trace.run}.
@@ -450,4 +473,4 @@ interface WithBaggageOptions<T = unknown> {
450
473
  */
451
474
  declare function withBaggage<T = unknown>(options: WithBaggageOptions<T>): T | Promise<T>;
452
475
  //#endregion
453
- export { getActiveTraceContext as a, trace$1 as c, withTracing as d, InstrumentOptions as f, ctx as i, withBaggage as l, TracingOptions as m, WithBaggageOptions as n, instrument as o, SingleInstrumentOptions as p, WithNewContextOptions as r, span as s, SpanOptions as t, withNewContext as u };
476
+ export { getActiveTraceContext as a, span as c, withNewContext as d, withTracing as f, TracingOptions as h, ctx as i, trace$1 as l, SingleInstrumentOptions as m, WithBaggageOptions as n, instrument as o, InstrumentOptions as p, WithNewContextOptions as r, requestCtx as s, SpanOptions as t, withBaggage as u };
@@ -1,4 +1,4 @@
1
- import { n as TraceContext } from "./trace-context-f89xPJbK.js";
1
+ import { n as TraceContext } from "./trace-context-CqCblIQE.js";
2
2
  import { m as Sampler } from "./sampling-DBng4Foa.js";
3
3
  import { Attributes, Span, SpanKind } from "@opentelemetry/api";
4
4
  //#region src/functional-wrapper.d.ts
@@ -144,6 +144,29 @@ type BaggageValues = Record<string, string | number | boolean>;
144
144
  */
145
145
  declare function getActiveTraceContext<TBaggage extends BaggageValues | undefined = undefined>(): TraceContext<TBaggage> | undefined;
146
146
  declare const ctx: TraceContext;
147
+ /**
148
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
149
+ * whatever span the calling code happens to be inside.
150
+ *
151
+ * Framework instrumentation nests spans per layer - express opens one per
152
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
153
+ * middleware records on a span that ends the moment `next()` fires. Attributes
154
+ * that describe the request as a whole (the authenticated user, the tenant, the
155
+ * plan) belong on the request span, which is what a backend shows as the
156
+ * resource and what a canonical log line is built from.
157
+ *
158
+ * Falls back to the active span outside a request, and no-ops when nothing is
159
+ * active at all, exactly as `ctx` does.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * app.use((req, _res, next) => {
164
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
165
+ * next();
166
+ * });
167
+ * ```
168
+ */
169
+ declare const requestCtx: TraceContext;
147
170
  /**
148
171
  * Wrap a plain function with a traced wrapper, or run one named operation
149
172
  * immediately with {@link trace.run}.
@@ -450,4 +473,4 @@ interface WithBaggageOptions<T = unknown> {
450
473
  */
451
474
  declare function withBaggage<T = unknown>(options: WithBaggageOptions<T>): T | Promise<T>;
452
475
  //#endregion
453
- export { getActiveTraceContext as a, trace$1 as c, withTracing as d, InstrumentOptions as f, ctx as i, withBaggage as l, TracingOptions as m, WithBaggageOptions as n, instrument as o, SingleInstrumentOptions as p, WithNewContextOptions as r, span as s, SpanOptions as t, withNewContext as u };
476
+ export { getActiveTraceContext as a, span as c, withNewContext as d, withTracing as f, TracingOptions as h, ctx as i, trace$1 as l, SingleInstrumentOptions as m, WithBaggageOptions as n, instrument as o, InstrumentOptions as p, WithNewContextOptions as r, requestCtx as s, SpanOptions as t, withBaggage as u };
@@ -1,10 +1,10 @@
1
- import { l as asString, m as isDevelopment } from "./values-xBtdXtjA.js";
1
+ import { _ as readProperty, h as isFunction, l as asString, m as isDevelopment } from "./values-xBtdXtjA.js";
2
2
  import { getForceFlushableProvider } from "./tracer-provider.js";
3
3
  import { getConfig } from "./config.js";
4
- import { C as AUTOTEL_SAMPLING_RATE, D as AlwaysSampler, G as getActiveContextWithBaggage, I as debugCaptureRequested, J as getEventQueue, K as getContextStorage, T as AUTOTEL_SAMPLING_TAIL_KEEP, U as createTraceContext, h as runInOperationContext, i as getSdk, n as getConfiguredSampler, q as hasExplicitSpanStatus, t as getConfig$1, w as AUTOTEL_SAMPLING_TAIL_EVALUATED, z as isForceKept } from "./init-Dwj1goyE.js";
4
+ import { C as AUTOTEL_SAMPLING_RATE, D as AlwaysSampler, G as getActiveContextWithBaggage, I as debugCaptureRequested, J as getEventQueue, K as getContextStorage, T as AUTOTEL_SAMPLING_TAIL_KEEP, U as createTraceContext, h as runInOperationContext, i as getSdk, n as getConfiguredSampler, q as hasExplicitSpanStatus, t as getConfig$1, w as AUTOTEL_SAMPLING_TAIL_EVALUATED, z as isForceKept } from "./init-Dyq6WtsO.js";
5
5
  import { evidenceAttribute } from "./evidence.js";
6
6
  import { setSpanName } from "./trace-helpers.js";
7
- import { SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
7
+ import { SpanStatusCode, context, createContextKey, propagation, trace } from "@opentelemetry/api";
8
8
  import * as nodeFs from "node:fs";
9
9
  import * as nodeUrl from "node:url";
10
10
 
@@ -346,7 +346,7 @@ function runWithTraceContextStorage(fn) {
346
346
  /** Used when neither the wrapper nor `init()` chose a sampler. */
347
347
  const FALLBACK_SAMPLER = new AlwaysSampler();
348
348
  function wrapWithTracingSync(fnFactory, options, variableName) {
349
- const { tracer, meter } = getConfig();
349
+ const { meter } = getConfig();
350
350
  const resolveSampler = () => options.sampler ?? getConfiguredSampler() ?? FALLBACK_SAMPLER;
351
351
  const spanName = getSpanName(options, fnFactory, variableName);
352
352
  const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
@@ -376,6 +376,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
376
376
  const spanOptions = {};
377
377
  if (options.startNewRoot) spanOptions.root = true;
378
378
  if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
379
+ const { tracer } = getConfig();
379
380
  return tracer.startActiveSpan(spanName, spanOptions, getActiveContextWithBaggage(), (span) => runInOperationContext(spanName, () => runWithTraceContextStorage(() => {
380
381
  let shouldKeepSpan = true;
381
382
  setSpanName(span, spanName);
@@ -579,27 +580,111 @@ function getActiveTraceContext() {
579
580
  * ```
580
581
  */
581
582
  const ctxProxyTarget = {};
582
- const ctx = new Proxy(ctxProxyTarget, {
583
- get(_target, prop) {
584
- const ctxValue = getCtxValue();
585
- if (!ctxValue) return;
586
- return ctxValue[prop];
587
- },
588
- has(_target, prop) {
589
- const ctxValue = getCtxValue();
590
- if (!ctxValue) return false;
591
- return prop in ctxValue;
592
- },
593
- ownKeys() {
594
- const ctxValue = getCtxValue();
595
- if (!ctxValue) return [];
596
- return Object.keys(ctxValue);
597
- },
598
- getOwnPropertyDescriptor(_target, prop) {
599
- const ctxValue = getCtxValue();
600
- if (!ctxValue) return;
601
- return Object.getOwnPropertyDescriptor(ctxValue, prop);
602
- }
583
+ /**
584
+ * What the methods do when no span is active - which is what a real
585
+ * `NonRecordingSpan` does too, and the reason instrumentation can never be the
586
+ * thing that throws: the same `ctx.setAttribute()` call runs under `vitest` and
587
+ * under a plain `node server.js`, where nothing preloaded the SDK.
588
+ *
589
+ * Only these names get a callable fallback. A blanket no-op would answer `then`
590
+ * as well, which would turn `ctx` into a thenable that never resolves.
591
+ * `functional.test.ts` asserts this list against a live context, so a new
592
+ * member cannot quietly go missing from it.
593
+ */
594
+ const noop = () => {};
595
+ const INACTIVE_CTX_METHODS = {
596
+ setAttribute: noop,
597
+ setAttributes: noop,
598
+ setStatus: noop,
599
+ recordException: noop,
600
+ addEvent: noop,
601
+ addLink: noop,
602
+ addLinks: noop,
603
+ updateName: noop,
604
+ recordError: noop,
605
+ track: noop,
606
+ isRecording: () => false,
607
+ getBaggage: () => void 0,
608
+ setBaggage: (_key, value) => value,
609
+ deleteBaggage: noop,
610
+ getAllBaggage: () => /* @__PURE__ */ new Map(),
611
+ getTypedBaggage: () => void 0,
612
+ setTypedBaggage: noop
613
+ };
614
+ /** A `ctx`-shaped view of whatever context `resolve` finds at access time. */
615
+ function createCtxProxy(resolve) {
616
+ return new Proxy(ctxProxyTarget, {
617
+ get(_target, prop) {
618
+ const ctxValue = resolve();
619
+ if (!ctxValue) return typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
620
+ return ctxValue[prop];
621
+ },
622
+ has(_target, prop) {
623
+ const ctxValue = resolve();
624
+ if (!ctxValue) return typeof prop === "string" && prop in INACTIVE_CTX_METHODS;
625
+ return prop in ctxValue;
626
+ },
627
+ ownKeys() {
628
+ const ctxValue = resolve();
629
+ return Object.keys(ctxValue ?? INACTIVE_CTX_METHODS);
630
+ },
631
+ getOwnPropertyDescriptor(_target, prop) {
632
+ const ctxValue = resolve();
633
+ if (!ctxValue) {
634
+ const fallback = typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
635
+ return fallback === void 0 ? void 0 : {
636
+ value: fallback,
637
+ writable: false,
638
+ enumerable: true,
639
+ configurable: true
640
+ };
641
+ }
642
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
643
+ }
644
+ });
645
+ }
646
+ const ctx = createCtxProxy(getCtxValue);
647
+ /**
648
+ * The key `@opentelemetry/core` publishes RPC metadata under. `createContextKey`
649
+ * is `Symbol.for`, so this reads exactly what `instrumentation-http` (and every
650
+ * framework instrumentation that renames the route) wrote, without taking a
651
+ * dependency on core.
652
+ */
653
+ const RPC_METADATA_KEY = createContextKey("OpenTelemetry SDK Context Key RPC_METADATA");
654
+ /**
655
+ * The span the current request is being recorded on, or the active span when
656
+ * there is no request - a queue consumer or a cron job has none, and an
657
+ * attribute belongs somewhere real rather than nowhere.
658
+ */
659
+ function getRequestSpan() {
660
+ const requestSpan = readProperty(context.active().getValue(RPC_METADATA_KEY), "span");
661
+ return isFunction(readProperty(requestSpan, "spanContext")) ? requestSpan : trace.getActiveSpan();
662
+ }
663
+ /**
664
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
665
+ * whatever span the calling code happens to be inside.
666
+ *
667
+ * Framework instrumentation nests spans per layer - express opens one per
668
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
669
+ * middleware records on a span that ends the moment `next()` fires. Attributes
670
+ * that describe the request as a whole (the authenticated user, the tenant, the
671
+ * plan) belong on the request span, which is what a backend shows as the
672
+ * resource and what a canonical log line is built from.
673
+ *
674
+ * Falls back to the active span outside a request, and no-ops when nothing is
675
+ * active at all, exactly as `ctx` does.
676
+ *
677
+ * @example
678
+ * ```typescript
679
+ * app.use((req, _res, next) => {
680
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
681
+ * next();
682
+ * });
683
+ * ```
684
+ */
685
+ const requestCtx = createCtxProxy(() => {
686
+ const span = getRequestSpan();
687
+ return span ? createTraceContext(span) : null;
603
688
  });
604
689
  function traceImpl(fnOrNameOrOptions, maybeFn) {
605
690
  if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
@@ -838,4 +923,4 @@ function withBaggage(options) {
838
923
  }
839
924
 
840
925
  //#endregion
841
- export { trace$1 as a, withTracing as c, span as i, getActiveTraceContext as n, withBaggage as o, instrument as r, withNewContext as s, ctx as t };
926
+ export { span as a, withNewContext as c, requestCtx as i, withTracing as l, getActiveTraceContext as n, trace$1 as o, instrument as r, withBaggage as s, ctx as t };
@@ -2,7 +2,7 @@ const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
2
2
  const require_values = require('./values-tm4bi0FF.cjs');
3
3
  const require_tracer_provider = require('./tracer-provider.cjs');
4
4
  const require_config = require('./config.cjs');
5
- const require_init = require('./init-zGVUHByM.cjs');
5
+ const require_init = require('./init-BYXDCfRL.cjs');
6
6
  const require_evidence = require('./evidence.cjs');
7
7
  const require_trace_helpers = require('./trace-helpers.cjs');
8
8
  let _opentelemetry_api = require("@opentelemetry/api");
@@ -349,7 +349,7 @@ function runWithTraceContextStorage(fn) {
349
349
  /** Used when neither the wrapper nor `init()` chose a sampler. */
350
350
  const FALLBACK_SAMPLER = new require_init.AlwaysSampler();
351
351
  function wrapWithTracingSync(fnFactory, options, variableName) {
352
- const { tracer, meter } = require_config.getConfig();
352
+ const { meter } = require_config.getConfig();
353
353
  const resolveSampler = () => options.sampler ?? require_init.getConfiguredSampler() ?? FALLBACK_SAMPLER;
354
354
  const spanName = getSpanName(options, fnFactory, variableName);
355
355
  const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
@@ -379,6 +379,7 @@ function wrapWithTracingSync(fnFactory, options, variableName) {
379
379
  const spanOptions = {};
380
380
  if (options.startNewRoot) spanOptions.root = true;
381
381
  if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
382
+ const { tracer } = require_config.getConfig();
382
383
  return tracer.startActiveSpan(spanName, spanOptions, require_init.getActiveContextWithBaggage(), (span) => require_init.runInOperationContext(spanName, () => runWithTraceContextStorage(() => {
383
384
  let shouldKeepSpan = true;
384
385
  require_trace_helpers.setSpanName(span, spanName);
@@ -582,27 +583,111 @@ function getActiveTraceContext() {
582
583
  * ```
583
584
  */
584
585
  const ctxProxyTarget = {};
585
- const ctx = new Proxy(ctxProxyTarget, {
586
- get(_target, prop) {
587
- const ctxValue = getCtxValue();
588
- if (!ctxValue) return;
589
- return ctxValue[prop];
590
- },
591
- has(_target, prop) {
592
- const ctxValue = getCtxValue();
593
- if (!ctxValue) return false;
594
- return prop in ctxValue;
595
- },
596
- ownKeys() {
597
- const ctxValue = getCtxValue();
598
- if (!ctxValue) return [];
599
- return Object.keys(ctxValue);
600
- },
601
- getOwnPropertyDescriptor(_target, prop) {
602
- const ctxValue = getCtxValue();
603
- if (!ctxValue) return;
604
- return Object.getOwnPropertyDescriptor(ctxValue, prop);
605
- }
586
+ /**
587
+ * What the methods do when no span is active - which is what a real
588
+ * `NonRecordingSpan` does too, and the reason instrumentation can never be the
589
+ * thing that throws: the same `ctx.setAttribute()` call runs under `vitest` and
590
+ * under a plain `node server.js`, where nothing preloaded the SDK.
591
+ *
592
+ * Only these names get a callable fallback. A blanket no-op would answer `then`
593
+ * as well, which would turn `ctx` into a thenable that never resolves.
594
+ * `functional.test.ts` asserts this list against a live context, so a new
595
+ * member cannot quietly go missing from it.
596
+ */
597
+ const noop = () => {};
598
+ const INACTIVE_CTX_METHODS = {
599
+ setAttribute: noop,
600
+ setAttributes: noop,
601
+ setStatus: noop,
602
+ recordException: noop,
603
+ addEvent: noop,
604
+ addLink: noop,
605
+ addLinks: noop,
606
+ updateName: noop,
607
+ recordError: noop,
608
+ track: noop,
609
+ isRecording: () => false,
610
+ getBaggage: () => void 0,
611
+ setBaggage: (_key, value) => value,
612
+ deleteBaggage: noop,
613
+ getAllBaggage: () => /* @__PURE__ */ new Map(),
614
+ getTypedBaggage: () => void 0,
615
+ setTypedBaggage: noop
616
+ };
617
+ /** A `ctx`-shaped view of whatever context `resolve` finds at access time. */
618
+ function createCtxProxy(resolve) {
619
+ return new Proxy(ctxProxyTarget, {
620
+ get(_target, prop) {
621
+ const ctxValue = resolve();
622
+ if (!ctxValue) return typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
623
+ return ctxValue[prop];
624
+ },
625
+ has(_target, prop) {
626
+ const ctxValue = resolve();
627
+ if (!ctxValue) return typeof prop === "string" && prop in INACTIVE_CTX_METHODS;
628
+ return prop in ctxValue;
629
+ },
630
+ ownKeys() {
631
+ const ctxValue = resolve();
632
+ return Object.keys(ctxValue ?? INACTIVE_CTX_METHODS);
633
+ },
634
+ getOwnPropertyDescriptor(_target, prop) {
635
+ const ctxValue = resolve();
636
+ if (!ctxValue) {
637
+ const fallback = typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
638
+ return fallback === void 0 ? void 0 : {
639
+ value: fallback,
640
+ writable: false,
641
+ enumerable: true,
642
+ configurable: true
643
+ };
644
+ }
645
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
646
+ }
647
+ });
648
+ }
649
+ const ctx = createCtxProxy(getCtxValue);
650
+ /**
651
+ * The key `@opentelemetry/core` publishes RPC metadata under. `createContextKey`
652
+ * is `Symbol.for`, so this reads exactly what `instrumentation-http` (and every
653
+ * framework instrumentation that renames the route) wrote, without taking a
654
+ * dependency on core.
655
+ */
656
+ const RPC_METADATA_KEY = (0, _opentelemetry_api.createContextKey)("OpenTelemetry SDK Context Key RPC_METADATA");
657
+ /**
658
+ * The span the current request is being recorded on, or the active span when
659
+ * there is no request - a queue consumer or a cron job has none, and an
660
+ * attribute belongs somewhere real rather than nowhere.
661
+ */
662
+ function getRequestSpan() {
663
+ const requestSpan = require_values.readProperty(_opentelemetry_api.context.active().getValue(RPC_METADATA_KEY), "span");
664
+ return require_values.isFunction(require_values.readProperty(requestSpan, "spanContext")) ? requestSpan : _opentelemetry_api.trace.getActiveSpan();
665
+ }
666
+ /**
667
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
668
+ * whatever span the calling code happens to be inside.
669
+ *
670
+ * Framework instrumentation nests spans per layer - express opens one per
671
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
672
+ * middleware records on a span that ends the moment `next()` fires. Attributes
673
+ * that describe the request as a whole (the authenticated user, the tenant, the
674
+ * plan) belong on the request span, which is what a backend shows as the
675
+ * resource and what a canonical log line is built from.
676
+ *
677
+ * Falls back to the active span outside a request, and no-ops when nothing is
678
+ * active at all, exactly as `ctx` does.
679
+ *
680
+ * @example
681
+ * ```typescript
682
+ * app.use((req, _res, next) => {
683
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
684
+ * next();
685
+ * });
686
+ * ```
687
+ */
688
+ const requestCtx = createCtxProxy(() => {
689
+ const span = getRequestSpan();
690
+ return span ? require_init.createTraceContext(span) : null;
606
691
  });
607
692
  function traceImpl(fnOrNameOrOptions, maybeFn) {
608
693
  if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
@@ -859,6 +944,12 @@ Object.defineProperty(exports, 'instrument', {
859
944
  return instrument;
860
945
  }
861
946
  });
947
+ Object.defineProperty(exports, 'requestCtx', {
948
+ enumerable: true,
949
+ get: function () {
950
+ return requestCtx;
951
+ }
952
+ });
862
953
  Object.defineProperty(exports, 'span', {
863
954
  enumerable: true,
864
955
  get: function () {
@@ -1,9 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_functional = require('./functional-uOagkiCk.cjs');
2
+ const require_functional = require('./functional-UIJ0CaTV.cjs');
3
3
 
4
4
  exports.ctx = require_functional.ctx;
5
5
  exports.getActiveTraceContext = require_functional.getActiveTraceContext;
6
6
  exports.instrument = require_functional.instrument;
7
+ exports.requestCtx = require_functional.requestCtx;
7
8
  exports.span = require_functional.span;
8
9
  exports.trace = require_functional.trace;
9
10
  exports.withBaggage = require_functional.withBaggage;
@@ -1,3 +1,3 @@
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-CgWcRXGX.cjs";
3
- export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
1
+ import { n as TraceContext } from "./trace-context-f7Xq0Q2q.cjs";
2
+ import { a as getActiveTraceContext, c as span, d as withNewContext, f as withTracing, h as TracingOptions, i as ctx, l as trace, m as SingleInstrumentOptions, n as WithBaggageOptions, o as instrument, p as InstrumentOptions, r as WithNewContextOptions, s as requestCtx, t as SpanOptions, u as withBaggage } from "./functional-C4mjgtJb.cjs";
3
+ export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, requestCtx, span, trace, withBaggage, withNewContext, withTracing };
@@ -1,3 +1,3 @@
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-RFFpQzAV.js";
3
- export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
1
+ import { n as TraceContext } from "./trace-context-CqCblIQE.js";
2
+ import { a as getActiveTraceContext, c as span, d as withNewContext, f as withTracing, h as TracingOptions, i as ctx, l as trace, m as SingleInstrumentOptions, n as WithBaggageOptions, o as instrument, p as InstrumentOptions, r as WithNewContextOptions, s as requestCtx, t as SpanOptions, u as withBaggage } from "./functional-DN_ztd9C.js";
3
+ export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, requestCtx, 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-DzIFi7ml.js";
1
+ import { a as span, c as withNewContext, i as requestCtx, l as withTracing, n as getActiveTraceContext, o as trace, r as instrument, s as withBaggage, t as ctx } from "./functional-S9IJNlBn.js";
2
2
 
3
- export { ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
3
+ export { ctx, getActiveTraceContext, instrument, requestCtx, span, trace, withBaggage, withNewContext, withTracing };
package/dist/http.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_values = require('./values-tm4bi0FF.cjs');
3
3
  const require_config = require('./config.cjs');
4
- const require_init = require('./init-zGVUHByM.cjs');
4
+ const require_init = require('./init-BYXDCfRL.cjs');
5
5
  let _opentelemetry_api = require("@opentelemetry/api");
6
6
 
7
7
  //#region src/http.ts
package/dist/http.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { _ as readProperty, h as isFunction, i as asNumber, l as asString } from "./values-xBtdXtjA.js";
2
2
  import { getConfig } from "./config.js";
3
- import { G as getActiveContextWithBaggage } from "./init-Dwj1goyE.js";
3
+ import { G as getActiveContextWithBaggage } from "./init-Dyq6WtsO.js";
4
4
  import { SpanStatusCode, context, propagation } from "@opentelemetry/api";
5
5
 
6
6
  //#region src/http.ts