autotel 7.6.2 → 7.7.0

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 (71) 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/decorators.cjs +1 -1
  10. package/dist/decorators.d.cts +2 -2
  11. package/dist/decorators.d.ts +2 -2
  12. package/dist/decorators.js +1 -1
  13. package/dist/event.cjs +1 -1
  14. package/dist/event.js +1 -1
  15. package/dist/{functional-CgWcRXGX.d.cts → functional-C4mjgtJb.d.cts} +25 -2
  16. package/dist/{functional-uOagkiCk.cjs → functional-CJI0HCVJ.cjs} +112 -22
  17. package/dist/{functional-DzIFi7ml.js → functional-Cnga_Lnv.js} +109 -25
  18. package/dist/{functional-RFFpQzAV.d.ts → functional-DN_ztd9C.d.ts} +25 -2
  19. package/dist/functional.cjs +2 -1
  20. package/dist/functional.d.cts +3 -3
  21. package/dist/functional.d.ts +3 -3
  22. package/dist/functional.js +2 -2
  23. package/dist/http.cjs +1 -1
  24. package/dist/http.js +1 -1
  25. package/dist/{index-Y7If_wH4.d.cts → index-8bFU4kmd.d.cts} +1 -1
  26. package/dist/{index-CsoeCsGL.d.ts → index-o_6YjZhV.d.ts} +1 -1
  27. package/dist/index.cjs +4 -3
  28. package/dist/index.d.cts +14 -5
  29. package/dist/index.d.ts +14 -5
  30. package/dist/index.js +4 -4
  31. package/dist/{init-zGVUHByM.cjs → init-BYXDCfRL.cjs} +57 -20
  32. package/dist/{init-BHV2gWsV.d.ts → init-CKSMbJUG.d.ts} +17 -1
  33. package/dist/{init-Dwj1goyE.js → init-Dyq6WtsO.js} +57 -20
  34. package/dist/{init-DxmeJ3d0.d.cts → init-WwjD-kQu.d.cts} +17 -1
  35. package/dist/instrumentation.cjs +1 -1
  36. package/dist/instrumentation.js +1 -1
  37. package/dist/messaging.cjs +2 -2
  38. package/dist/messaging.d.cts +1 -1
  39. package/dist/messaging.d.ts +1 -1
  40. package/dist/messaging.js +2 -2
  41. package/dist/sampling.cjs +1 -1
  42. package/dist/sampling.js +1 -1
  43. package/dist/semantic-helpers.cjs +1 -1
  44. package/dist/semantic-helpers.d.cts +1 -1
  45. package/dist/semantic-helpers.d.ts +1 -1
  46. package/dist/semantic-helpers.js +1 -1
  47. package/dist/{structured-error-BI9PFKZr.cjs → structured-error-BAXhglRE.cjs} +47 -24
  48. package/dist/{structured-error-XpBdwnmv.js → structured-error-Y9y-1Pae.js} +47 -24
  49. package/dist/tail-sampling-processor.cjs +1 -1
  50. package/dist/tail-sampling-processor.js +1 -1
  51. package/dist/{trace-context-f89xPJbK.d.ts → trace-context-CqCblIQE.d.ts} +12 -5
  52. package/dist/{trace-context-C1Cn1q0y.d.cts → trace-context-f7Xq0Q2q.d.cts} +12 -5
  53. package/dist/validate.cjs +1 -1
  54. package/dist/validate.js +1 -1
  55. package/dist/webhook.cjs +2 -2
  56. package/dist/webhook.d.cts +1 -1
  57. package/dist/webhook.d.ts +1 -1
  58. package/dist/webhook.js +2 -2
  59. package/dist/workflow-distributed.cjs +1 -1
  60. package/dist/workflow-distributed.d.cts +1 -1
  61. package/dist/workflow-distributed.d.ts +1 -1
  62. package/dist/workflow-distributed.js +1 -1
  63. package/dist/workflow.cjs +1 -1
  64. package/dist/workflow.d.cts +1 -1
  65. package/dist/workflow.d.ts +1 -1
  66. package/dist/workflow.js +1 -1
  67. package/dist/yaml-config.cjs +1 -1
  68. package/dist/yaml-config.d.cts +2 -2
  69. package/dist/yaml-config.d.ts +2 -2
  70. package/dist/yaml-config.js +1 -1
  71. package/package.json +1 -1
@@ -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 };
@@ -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 };
@@ -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");
@@ -582,27 +582,111 @@ function getActiveTraceContext() {
582
582
  * ```
583
583
  */
584
584
  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
- }
585
+ /**
586
+ * What the methods do when no span is active - which is what a real
587
+ * `NonRecordingSpan` does too, and the reason instrumentation can never be the
588
+ * thing that throws: the same `ctx.setAttribute()` call runs under `vitest` and
589
+ * under a plain `node server.js`, where nothing preloaded the SDK.
590
+ *
591
+ * Only these names get a callable fallback. A blanket no-op would answer `then`
592
+ * as well, which would turn `ctx` into a thenable that never resolves.
593
+ * `functional.test.ts` asserts this list against a live context, so a new
594
+ * member cannot quietly go missing from it.
595
+ */
596
+ const noop = () => {};
597
+ const INACTIVE_CTX_METHODS = {
598
+ setAttribute: noop,
599
+ setAttributes: noop,
600
+ setStatus: noop,
601
+ recordException: noop,
602
+ addEvent: noop,
603
+ addLink: noop,
604
+ addLinks: noop,
605
+ updateName: noop,
606
+ recordError: noop,
607
+ track: noop,
608
+ isRecording: () => false,
609
+ getBaggage: () => void 0,
610
+ setBaggage: (_key, value) => value,
611
+ deleteBaggage: noop,
612
+ getAllBaggage: () => /* @__PURE__ */ new Map(),
613
+ getTypedBaggage: () => void 0,
614
+ setTypedBaggage: noop
615
+ };
616
+ /** A `ctx`-shaped view of whatever context `resolve` finds at access time. */
617
+ function createCtxProxy(resolve) {
618
+ return new Proxy(ctxProxyTarget, {
619
+ get(_target, prop) {
620
+ const ctxValue = resolve();
621
+ if (!ctxValue) return typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
622
+ return ctxValue[prop];
623
+ },
624
+ has(_target, prop) {
625
+ const ctxValue = resolve();
626
+ if (!ctxValue) return typeof prop === "string" && prop in INACTIVE_CTX_METHODS;
627
+ return prop in ctxValue;
628
+ },
629
+ ownKeys() {
630
+ const ctxValue = resolve();
631
+ return Object.keys(ctxValue ?? INACTIVE_CTX_METHODS);
632
+ },
633
+ getOwnPropertyDescriptor(_target, prop) {
634
+ const ctxValue = resolve();
635
+ if (!ctxValue) {
636
+ const fallback = typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
637
+ return fallback === void 0 ? void 0 : {
638
+ value: fallback,
639
+ writable: false,
640
+ enumerable: true,
641
+ configurable: true
642
+ };
643
+ }
644
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
645
+ }
646
+ });
647
+ }
648
+ const ctx = createCtxProxy(getCtxValue);
649
+ /**
650
+ * The key `@opentelemetry/core` publishes RPC metadata under. `createContextKey`
651
+ * is `Symbol.for`, so this reads exactly what `instrumentation-http` (and every
652
+ * framework instrumentation that renames the route) wrote, without taking a
653
+ * dependency on core.
654
+ */
655
+ const RPC_METADATA_KEY = (0, _opentelemetry_api.createContextKey)("OpenTelemetry SDK Context Key RPC_METADATA");
656
+ /**
657
+ * The span the current request is being recorded on, or the active span when
658
+ * there is no request - a queue consumer or a cron job has none, and an
659
+ * attribute belongs somewhere real rather than nowhere.
660
+ */
661
+ function getRequestSpan() {
662
+ const requestSpan = require_values.readProperty(_opentelemetry_api.context.active().getValue(RPC_METADATA_KEY), "span");
663
+ return require_values.isFunction(require_values.readProperty(requestSpan, "spanContext")) ? requestSpan : _opentelemetry_api.trace.getActiveSpan();
664
+ }
665
+ /**
666
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
667
+ * whatever span the calling code happens to be inside.
668
+ *
669
+ * Framework instrumentation nests spans per layer - express opens one per
670
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
671
+ * middleware records on a span that ends the moment `next()` fires. Attributes
672
+ * that describe the request as a whole (the authenticated user, the tenant, the
673
+ * plan) belong on the request span, which is what a backend shows as the
674
+ * resource and what a canonical log line is built from.
675
+ *
676
+ * Falls back to the active span outside a request, and no-ops when nothing is
677
+ * active at all, exactly as `ctx` does.
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * app.use((req, _res, next) => {
682
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
683
+ * next();
684
+ * });
685
+ * ```
686
+ */
687
+ const requestCtx = createCtxProxy(() => {
688
+ const span = getRequestSpan();
689
+ return span ? require_init.createTraceContext(span) : null;
606
690
  });
607
691
  function traceImpl(fnOrNameOrOptions, maybeFn) {
608
692
  if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
@@ -859,6 +943,12 @@ Object.defineProperty(exports, 'instrument', {
859
943
  return instrument;
860
944
  }
861
945
  });
946
+ Object.defineProperty(exports, 'requestCtx', {
947
+ enumerable: true,
948
+ get: function () {
949
+ return requestCtx;
950
+ }
951
+ });
862
952
  Object.defineProperty(exports, 'span', {
863
953
  enumerable: true,
864
954
  get: function () {
@@ -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
 
@@ -579,27 +579,111 @@ function getActiveTraceContext() {
579
579
  * ```
580
580
  */
581
581
  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
- }
582
+ /**
583
+ * What the methods do when no span is active - which is what a real
584
+ * `NonRecordingSpan` does too, and the reason instrumentation can never be the
585
+ * thing that throws: the same `ctx.setAttribute()` call runs under `vitest` and
586
+ * under a plain `node server.js`, where nothing preloaded the SDK.
587
+ *
588
+ * Only these names get a callable fallback. A blanket no-op would answer `then`
589
+ * as well, which would turn `ctx` into a thenable that never resolves.
590
+ * `functional.test.ts` asserts this list against a live context, so a new
591
+ * member cannot quietly go missing from it.
592
+ */
593
+ const noop = () => {};
594
+ const INACTIVE_CTX_METHODS = {
595
+ setAttribute: noop,
596
+ setAttributes: noop,
597
+ setStatus: noop,
598
+ recordException: noop,
599
+ addEvent: noop,
600
+ addLink: noop,
601
+ addLinks: noop,
602
+ updateName: noop,
603
+ recordError: noop,
604
+ track: noop,
605
+ isRecording: () => false,
606
+ getBaggage: () => void 0,
607
+ setBaggage: (_key, value) => value,
608
+ deleteBaggage: noop,
609
+ getAllBaggage: () => /* @__PURE__ */ new Map(),
610
+ getTypedBaggage: () => void 0,
611
+ setTypedBaggage: noop
612
+ };
613
+ /** A `ctx`-shaped view of whatever context `resolve` finds at access time. */
614
+ function createCtxProxy(resolve) {
615
+ return new Proxy(ctxProxyTarget, {
616
+ get(_target, prop) {
617
+ const ctxValue = resolve();
618
+ if (!ctxValue) return typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
619
+ return ctxValue[prop];
620
+ },
621
+ has(_target, prop) {
622
+ const ctxValue = resolve();
623
+ if (!ctxValue) return typeof prop === "string" && prop in INACTIVE_CTX_METHODS;
624
+ return prop in ctxValue;
625
+ },
626
+ ownKeys() {
627
+ const ctxValue = resolve();
628
+ return Object.keys(ctxValue ?? INACTIVE_CTX_METHODS);
629
+ },
630
+ getOwnPropertyDescriptor(_target, prop) {
631
+ const ctxValue = resolve();
632
+ if (!ctxValue) {
633
+ const fallback = typeof prop === "string" ? INACTIVE_CTX_METHODS[prop] : void 0;
634
+ return fallback === void 0 ? void 0 : {
635
+ value: fallback,
636
+ writable: false,
637
+ enumerable: true,
638
+ configurable: true
639
+ };
640
+ }
641
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
642
+ }
643
+ });
644
+ }
645
+ const ctx = createCtxProxy(getCtxValue);
646
+ /**
647
+ * The key `@opentelemetry/core` publishes RPC metadata under. `createContextKey`
648
+ * is `Symbol.for`, so this reads exactly what `instrumentation-http` (and every
649
+ * framework instrumentation that renames the route) wrote, without taking a
650
+ * dependency on core.
651
+ */
652
+ const RPC_METADATA_KEY = createContextKey("OpenTelemetry SDK Context Key RPC_METADATA");
653
+ /**
654
+ * The span the current request is being recorded on, or the active span when
655
+ * there is no request - a queue consumer or a cron job has none, and an
656
+ * attribute belongs somewhere real rather than nowhere.
657
+ */
658
+ function getRequestSpan() {
659
+ const requestSpan = readProperty(context.active().getValue(RPC_METADATA_KEY), "span");
660
+ return isFunction(readProperty(requestSpan, "spanContext")) ? requestSpan : trace.getActiveSpan();
661
+ }
662
+ /**
663
+ * The ambient {@link ctx}, aimed at the **request** span rather than at
664
+ * whatever span the calling code happens to be inside.
665
+ *
666
+ * Framework instrumentation nests spans per layer - express opens one per
667
+ * middleware and per route handler - so `ctx.setAttribute()` from a shared
668
+ * middleware records on a span that ends the moment `next()` fires. Attributes
669
+ * that describe the request as a whole (the authenticated user, the tenant, the
670
+ * plan) belong on the request span, which is what a backend shows as the
671
+ * resource and what a canonical log line is built from.
672
+ *
673
+ * Falls back to the active span outside a request, and no-ops when nothing is
674
+ * active at all, exactly as `ctx` does.
675
+ *
676
+ * @example
677
+ * ```typescript
678
+ * app.use((req, _res, next) => {
679
+ * requestCtx.setAttributes({ user: req.user }); // user.id, user.plan, ...
680
+ * next();
681
+ * });
682
+ * ```
683
+ */
684
+ const requestCtx = createCtxProxy(() => {
685
+ const span = getRequestSpan();
686
+ return span ? createTraceContext(span) : null;
603
687
  });
604
688
  function traceImpl(fnOrNameOrOptions, maybeFn) {
605
689
  if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
@@ -838,4 +922,4 @@ function withBaggage(options) {
838
922
  }
839
923
 
840
924
  //#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 };
925
+ 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 };
@@ -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,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-CJI0HCVJ.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-Cnga_Lnv.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
@@ -1,4 +1,4 @@
1
- import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-C1Cn1q0y.cjs";
1
+ import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-f7Xq0Q2q.cjs";
2
2
  import { AttributeValue, Attributes, Span } from "@opentelemetry/api";
3
3
  import { Resource } from "@opentelemetry/resources";
4
4
  //#region src/attributes/types.d.ts
@@ -1,4 +1,4 @@
1
- import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-f89xPJbK.js";
1
+ import { n as TraceContext, t as AttributeValue$1 } from "./trace-context-CqCblIQE.js";
2
2
  import { Resource } from "@opentelemetry/resources";
3
3
  import { AttributeValue, Attributes, Span } from "@opentelemetry/api";
4
4
  //#region src/attributes/types.d.ts
package/dist/index.cjs CHANGED
@@ -2,14 +2,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
3
3
  const require_values = require('./values-tm4bi0FF.cjs');
4
4
  const require_tracer_provider = require('./tracer-provider.cjs');
5
- const require_structured_error = require('./structured-error-BI9PFKZr.cjs');
6
- const require_init = require('./init-zGVUHByM.cjs');
5
+ const require_structured_error = require('./structured-error-BAXhglRE.cjs');
6
+ const require_init = require('./init-BYXDCfRL.cjs');
7
7
  const require_filtering_span_processor = require('./filtering-span-processor.cjs');
8
8
  const require_span_name_normalizer = require('./span-name-normalizer.cjs');
9
9
  const require_attribute_redacting_processor = require('./attribute-redacting-processor.cjs');
10
10
  const require_canonical_log_line_processor = require('./canonical-log-line-processor-Bvgb1lE4.cjs');
11
11
  const require_metric = require('./metric.cjs');
12
- const require_functional = require('./functional-uOagkiCk.cjs');
12
+ const require_functional = require('./functional-CJI0HCVJ.cjs');
13
13
  const require_trace_helpers = require('./trace-helpers.cjs');
14
14
  const require_stable_hash = require('./stable-hash-C9F6xjzx.cjs');
15
15
  const require_correlated_events = require('./correlated-events-9RRdfyWR.cjs');
@@ -684,6 +684,7 @@ Object.defineProperty(exports, 'propagation', {
684
684
  });
685
685
  exports.recordStructuredError = require_structured_error.recordStructuredError;
686
686
  exports.request = require_attributes.request;
687
+ exports.requestCtx = require_functional.requestCtx;
687
688
  exports.resetEvents = require_init.resetEvents;
688
689
  exports.resetMetrics = require_metric.resetMetrics;
689
690
  exports.resolveSamplingPreset = require_init.resolveSamplingPreset;