autotel 2.1.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.
- package/LICENSE +21 -0
- package/README.md +1946 -0
- package/dist/chunk-2LNRY4QK.js +273 -0
- package/dist/chunk-2LNRY4QK.js.map +1 -0
- package/dist/chunk-3HENGDW2.js +587 -0
- package/dist/chunk-3HENGDW2.js.map +1 -0
- package/dist/chunk-4OAT42CA.cjs +73 -0
- package/dist/chunk-4OAT42CA.cjs.map +1 -0
- package/dist/chunk-5GWX5LFW.js +70 -0
- package/dist/chunk-5GWX5LFW.js.map +1 -0
- package/dist/chunk-5R2M36QB.js +195 -0
- package/dist/chunk-5R2M36QB.js.map +1 -0
- package/dist/chunk-5ZN622AO.js +73 -0
- package/dist/chunk-5ZN622AO.js.map +1 -0
- package/dist/chunk-77MSMAUQ.cjs +498 -0
- package/dist/chunk-77MSMAUQ.cjs.map +1 -0
- package/dist/chunk-ABPEQ6RK.cjs +596 -0
- package/dist/chunk-ABPEQ6RK.cjs.map +1 -0
- package/dist/chunk-BWYGJKRB.js +95 -0
- package/dist/chunk-BWYGJKRB.js.map +1 -0
- package/dist/chunk-BZHG5IZ4.js +73 -0
- package/dist/chunk-BZHG5IZ4.js.map +1 -0
- package/dist/chunk-G7VZBCD6.cjs +35 -0
- package/dist/chunk-G7VZBCD6.cjs.map +1 -0
- package/dist/chunk-GVLK7YUU.cjs +30 -0
- package/dist/chunk-GVLK7YUU.cjs.map +1 -0
- package/dist/chunk-HCCXC7XG.js +205 -0
- package/dist/chunk-HCCXC7XG.js.map +1 -0
- package/dist/chunk-HE6T6FIX.cjs +203 -0
- package/dist/chunk-HE6T6FIX.cjs.map +1 -0
- package/dist/chunk-KIXWPOCO.cjs +100 -0
- package/dist/chunk-KIXWPOCO.cjs.map +1 -0
- package/dist/chunk-KVGNW3FC.js +87 -0
- package/dist/chunk-KVGNW3FC.js.map +1 -0
- package/dist/chunk-LITNXTTT.js +3 -0
- package/dist/chunk-LITNXTTT.js.map +1 -0
- package/dist/chunk-M4ANN7RL.js +114 -0
- package/dist/chunk-M4ANN7RL.js.map +1 -0
- package/dist/chunk-NC52UBR2.cjs +32 -0
- package/dist/chunk-NC52UBR2.cjs.map +1 -0
- package/dist/chunk-NHCNRQD3.cjs +212 -0
- package/dist/chunk-NHCNRQD3.cjs.map +1 -0
- package/dist/chunk-NZ72VDNY.cjs +4 -0
- package/dist/chunk-NZ72VDNY.cjs.map +1 -0
- package/dist/chunk-P6JUDYNO.js +57 -0
- package/dist/chunk-P6JUDYNO.js.map +1 -0
- package/dist/chunk-RJYY7BWX.js +1349 -0
- package/dist/chunk-RJYY7BWX.js.map +1 -0
- package/dist/chunk-TRI4V5BF.cjs +126 -0
- package/dist/chunk-TRI4V5BF.cjs.map +1 -0
- package/dist/chunk-UL33I6IS.js +139 -0
- package/dist/chunk-UL33I6IS.js.map +1 -0
- package/dist/chunk-URRW6M2C.cjs +61 -0
- package/dist/chunk-URRW6M2C.cjs.map +1 -0
- package/dist/chunk-UY3UYPBZ.cjs +77 -0
- package/dist/chunk-UY3UYPBZ.cjs.map +1 -0
- package/dist/chunk-W3253FGB.cjs +277 -0
- package/dist/chunk-W3253FGB.cjs.map +1 -0
- package/dist/chunk-W7LHZVQF.js +26 -0
- package/dist/chunk-W7LHZVQF.js.map +1 -0
- package/dist/chunk-WBWNM6LB.cjs +1360 -0
- package/dist/chunk-WBWNM6LB.cjs.map +1 -0
- package/dist/chunk-WFJ7L2RV.js +494 -0
- package/dist/chunk-WFJ7L2RV.js.map +1 -0
- package/dist/chunk-X4RMFFMR.js +28 -0
- package/dist/chunk-X4RMFFMR.js.map +1 -0
- package/dist/chunk-Y4Y2S7BM.cjs +92 -0
- package/dist/chunk-Y4Y2S7BM.cjs.map +1 -0
- package/dist/chunk-YLPNXZFI.cjs +143 -0
- package/dist/chunk-YLPNXZFI.cjs.map +1 -0
- package/dist/chunk-YTXEZ4SD.cjs +77 -0
- package/dist/chunk-YTXEZ4SD.cjs.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +30 -0
- package/dist/chunk-Z6ZWNWWR.js.map +1 -0
- package/dist/config.cjs +26 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +75 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/db.cjs +233 -0
- package/dist/db.cjs.map +1 -0
- package/dist/db.d.cts +123 -0
- package/dist/db.d.ts +123 -0
- package/dist/db.js +228 -0
- package/dist/db.js.map +1 -0
- package/dist/decorators.cjs +67 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +91 -0
- package/dist/decorators.d.ts +91 -0
- package/dist/decorators.js +65 -0
- package/dist/decorators.js.map +1 -0
- package/dist/event-subscriber.cjs +6 -0
- package/dist/event-subscriber.cjs.map +1 -0
- package/dist/event-subscriber.d.cts +116 -0
- package/dist/event-subscriber.d.ts +116 -0
- package/dist/event-subscriber.js +3 -0
- package/dist/event-subscriber.js.map +1 -0
- package/dist/event-testing.cjs +21 -0
- package/dist/event-testing.cjs.map +1 -0
- package/dist/event-testing.d.cts +110 -0
- package/dist/event-testing.d.ts +110 -0
- package/dist/event-testing.js +4 -0
- package/dist/event-testing.js.map +1 -0
- package/dist/event.cjs +30 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +282 -0
- package/dist/event.d.ts +282 -0
- package/dist/event.js +13 -0
- package/dist/event.js.map +1 -0
- package/dist/exporters.cjs +17 -0
- package/dist/exporters.cjs.map +1 -0
- package/dist/exporters.d.cts +1 -0
- package/dist/exporters.d.ts +1 -0
- package/dist/exporters.js +4 -0
- package/dist/exporters.js.map +1 -0
- package/dist/functional.cjs +46 -0
- package/dist/functional.cjs.map +1 -0
- package/dist/functional.d.cts +478 -0
- package/dist/functional.d.ts +478 -0
- package/dist/functional.js +13 -0
- package/dist/functional.js.map +1 -0
- package/dist/http.cjs +189 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +169 -0
- package/dist/http.d.ts +169 -0
- package/dist/http.js +184 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +333 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +758 -0
- package/dist/index.d.ts +758 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.cjs +182 -0
- package/dist/instrumentation.cjs.map +1 -0
- package/dist/instrumentation.d.cts +49 -0
- package/dist/instrumentation.d.ts +49 -0
- package/dist/instrumentation.js +179 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/logger.cjs +19 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +146 -0
- package/dist/logger.d.ts +146 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/metric-helpers.cjs +31 -0
- package/dist/metric-helpers.cjs.map +1 -0
- package/dist/metric-helpers.d.cts +13 -0
- package/dist/metric-helpers.d.ts +13 -0
- package/dist/metric-helpers.js +6 -0
- package/dist/metric-helpers.js.map +1 -0
- package/dist/metric-testing.cjs +21 -0
- package/dist/metric-testing.cjs.map +1 -0
- package/dist/metric-testing.d.cts +110 -0
- package/dist/metric-testing.d.ts +110 -0
- package/dist/metric-testing.js +4 -0
- package/dist/metric-testing.js.map +1 -0
- package/dist/metric.cjs +26 -0
- package/dist/metric.cjs.map +1 -0
- package/dist/metric.d.cts +240 -0
- package/dist/metric.d.ts +240 -0
- package/dist/metric.js +9 -0
- package/dist/metric.js.map +1 -0
- package/dist/processors.cjs +17 -0
- package/dist/processors.cjs.map +1 -0
- package/dist/processors.d.cts +1 -0
- package/dist/processors.d.ts +1 -0
- package/dist/processors.js +4 -0
- package/dist/processors.js.map +1 -0
- package/dist/sampling.cjs +40 -0
- package/dist/sampling.cjs.map +1 -0
- package/dist/sampling.d.cts +260 -0
- package/dist/sampling.d.ts +260 -0
- package/dist/sampling.js +7 -0
- package/dist/sampling.js.map +1 -0
- package/dist/semantic-helpers.cjs +35 -0
- package/dist/semantic-helpers.cjs.map +1 -0
- package/dist/semantic-helpers.d.cts +442 -0
- package/dist/semantic-helpers.d.ts +442 -0
- package/dist/semantic-helpers.js +14 -0
- package/dist/semantic-helpers.js.map +1 -0
- package/dist/tail-sampling-processor.cjs +13 -0
- package/dist/tail-sampling-processor.cjs.map +1 -0
- package/dist/tail-sampling-processor.d.cts +27 -0
- package/dist/tail-sampling-processor.d.ts +27 -0
- package/dist/tail-sampling-processor.js +4 -0
- package/dist/tail-sampling-processor.js.map +1 -0
- package/dist/testing.cjs +286 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +291 -0
- package/dist/testing.d.ts +291 -0
- package/dist/testing.js +263 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-context-DRZdUvVY.d.cts +181 -0
- package/dist/trace-context-DRZdUvVY.d.ts +181 -0
- package/dist/trace-helpers.cjs +54 -0
- package/dist/trace-helpers.cjs.map +1 -0
- package/dist/trace-helpers.d.cts +524 -0
- package/dist/trace-helpers.d.ts +524 -0
- package/dist/trace-helpers.js +5 -0
- package/dist/trace-helpers.js.map +1 -0
- package/dist/tracer-provider.cjs +21 -0
- package/dist/tracer-provider.cjs.map +1 -0
- package/dist/tracer-provider.d.cts +169 -0
- package/dist/tracer-provider.d.ts +169 -0
- package/dist/tracer-provider.js +4 -0
- package/dist/tracer-provider.js.map +1 -0
- package/package.json +280 -0
- package/src/baggage-span-processor.test.ts +202 -0
- package/src/baggage-span-processor.ts +98 -0
- package/src/circuit-breaker.test.ts +341 -0
- package/src/circuit-breaker.ts +184 -0
- package/src/config.test.ts +94 -0
- package/src/config.ts +169 -0
- package/src/db.test.ts +252 -0
- package/src/db.ts +447 -0
- package/src/decorators.test.ts +203 -0
- package/src/decorators.ts +188 -0
- package/src/env-config.test.ts +246 -0
- package/src/env-config.ts +158 -0
- package/src/event-queue.test.ts +222 -0
- package/src/event-queue.ts +203 -0
- package/src/event-subscriber.ts +136 -0
- package/src/event-testing.ts +197 -0
- package/src/event.test.ts +718 -0
- package/src/event.ts +556 -0
- package/src/exporters.ts +96 -0
- package/src/functional.test.ts +1059 -0
- package/src/functional.ts +2295 -0
- package/src/http.test.ts +487 -0
- package/src/http.ts +424 -0
- package/src/index.ts +158 -0
- package/src/init.customization.test.ts +210 -0
- package/src/init.integrations.test.ts +366 -0
- package/src/init.openllmetry.test.ts +282 -0
- package/src/init.protocol.test.ts +215 -0
- package/src/init.ts +1426 -0
- package/src/instrumentation.test.ts +108 -0
- package/src/instrumentation.ts +308 -0
- package/src/logger.test.ts +117 -0
- package/src/logger.ts +246 -0
- package/src/metric-helpers.ts +47 -0
- package/src/metric-testing.ts +197 -0
- package/src/metric.ts +434 -0
- package/src/metrics.test.ts +205 -0
- package/src/operation-context.ts +93 -0
- package/src/processors.ts +106 -0
- package/src/rate-limiter.test.ts +199 -0
- package/src/rate-limiter.ts +98 -0
- package/src/sampling.test.ts +513 -0
- package/src/sampling.ts +428 -0
- package/src/semantic-helpers.test.ts +311 -0
- package/src/semantic-helpers.ts +584 -0
- package/src/shutdown.test.ts +311 -0
- package/src/shutdown.ts +222 -0
- package/src/stub.integration.test.ts +361 -0
- package/src/tail-sampling-processor.test.ts +226 -0
- package/src/tail-sampling-processor.ts +51 -0
- package/src/testing.ts +670 -0
- package/src/trace-context.ts +470 -0
- package/src/trace-helpers.new.test.ts +278 -0
- package/src/trace-helpers.test.ts +242 -0
- package/src/trace-helpers.ts +690 -0
- package/src/tracer-provider.test.ts +183 -0
- package/src/tracer-provider.ts +266 -0
- package/src/track.test.ts +153 -0
- package/src/track.ts +120 -0
- package/src/validation.test.ts +306 -0
- package/src/validation.ts +239 -0
- package/src/variable-name-inference.test.ts +178 -0
- package/src/variable-name-inference.ts +242 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { SpanStatusCode, BaggageEntry } from '@opentelemetry/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Trace context types and utilities
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base trace context containing trace identifiers
|
|
9
|
+
*/
|
|
10
|
+
interface TraceContextBase {
|
|
11
|
+
traceId: string;
|
|
12
|
+
spanId: string;
|
|
13
|
+
correlationId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Span methods available on trace context
|
|
17
|
+
*/
|
|
18
|
+
interface SpanMethods {
|
|
19
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
20
|
+
setAttributes(attrs: Record<string, string | number | boolean>): void;
|
|
21
|
+
setStatus(status: {
|
|
22
|
+
code: SpanStatusCode;
|
|
23
|
+
message?: string;
|
|
24
|
+
}): void;
|
|
25
|
+
recordException(exception: Error): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Baggage methods available on trace context
|
|
29
|
+
*
|
|
30
|
+
* @template TBaggage - Optional type for typed baggage (defaults to undefined for untyped)
|
|
31
|
+
*/
|
|
32
|
+
interface BaggageMethods<TBaggage extends Record<string, unknown> | undefined = undefined> {
|
|
33
|
+
/**
|
|
34
|
+
* Get a baggage entry by key
|
|
35
|
+
* @param key - Baggage key
|
|
36
|
+
* @returns Baggage entry value or undefined
|
|
37
|
+
*/
|
|
38
|
+
getBaggage(key: string): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Set a baggage entry
|
|
41
|
+
*
|
|
42
|
+
* Note: OpenTelemetry contexts are immutable. For proper scoping across async
|
|
43
|
+
* boundaries, use withBaggage() instead. This method updates baggage in the
|
|
44
|
+
* current context which may not propagate to all child operations.
|
|
45
|
+
*
|
|
46
|
+
* @param key - Baggage key
|
|
47
|
+
* @param value - Baggage value
|
|
48
|
+
* @returns The baggage value that was set (for chaining)
|
|
49
|
+
*
|
|
50
|
+
* @example Using withBaggage() (recommended)
|
|
51
|
+
* ```typescript
|
|
52
|
+
* await withBaggage({ baggage: { 'key': 'value' }, fn: async () => {
|
|
53
|
+
* // Baggage is available here and in child spans
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
setBaggage(key: string, value: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Delete a baggage entry
|
|
60
|
+
*
|
|
61
|
+
* Note: OpenTelemetry contexts are immutable. For proper scoping across async
|
|
62
|
+
* boundaries, use withBaggage() with only the entries you want instead.
|
|
63
|
+
*
|
|
64
|
+
* @param key - Baggage key
|
|
65
|
+
*/
|
|
66
|
+
deleteBaggage(key: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get all baggage entries
|
|
69
|
+
* @returns Map of all baggage entries
|
|
70
|
+
*/
|
|
71
|
+
getAllBaggage(): Map<string, BaggageEntry>;
|
|
72
|
+
/**
|
|
73
|
+
* Get typed baggage (only available when TBaggage is defined)
|
|
74
|
+
* This is used internally by defineBaggageSchema()
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
getTypedBaggage?: TBaggage extends Record<string, unknown> ? <T extends TBaggage>(namespace?: string) => Partial<T> | undefined : never;
|
|
79
|
+
/**
|
|
80
|
+
* Set typed baggage (only available when TBaggage is defined)
|
|
81
|
+
* This is used internally by defineBaggageSchema()
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
setTypedBaggage?: TBaggage extends Record<string, unknown> ? <T extends TBaggage>(namespace: string | undefined, value: Partial<T>) => void : never;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete trace context that merges base context, span methods, and baggage methods
|
|
89
|
+
*
|
|
90
|
+
* This is the ctx parameter passed to factory functions in trace().
|
|
91
|
+
* It provides access to trace IDs, span manipulation methods, and baggage operations.
|
|
92
|
+
*
|
|
93
|
+
* @template TBaggage - Optional type for typed baggage support
|
|
94
|
+
*
|
|
95
|
+
* @example Untyped (default)
|
|
96
|
+
* ```typescript
|
|
97
|
+
* export const handler = trace((ctx) => async () => {
|
|
98
|
+
* ctx.getBaggage('key'); // returns string | undefined
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Typed baggage
|
|
103
|
+
* ```typescript
|
|
104
|
+
* type TenantBaggage = { tenantId: string; region?: string };
|
|
105
|
+
*
|
|
106
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
107
|
+
* // Use typed schema helper for type-safe access
|
|
108
|
+
* const schema = defineBaggageSchema<TenantBaggage>('tenant');
|
|
109
|
+
* const tenant = schema.get(ctx); // Partial<TenantBaggage> | undefined
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
type TraceContext<TBaggage extends Record<string, unknown> | undefined = undefined> = TraceContextBase & SpanMethods & BaggageMethods<TBaggage>;
|
|
114
|
+
/**
|
|
115
|
+
* Define a typed baggage schema for type-safe baggage operations
|
|
116
|
+
*
|
|
117
|
+
* This helper provides a type-safe API for working with baggage entries.
|
|
118
|
+
* The namespace parameter is optional and prefixes all keys to avoid collisions.
|
|
119
|
+
*
|
|
120
|
+
* @template T - The baggage schema type (all fields are treated as optional)
|
|
121
|
+
* @param namespace - Optional namespace to prefix baggage keys
|
|
122
|
+
*
|
|
123
|
+
* @example Basic usage
|
|
124
|
+
* ```typescript
|
|
125
|
+
* type TenantBaggage = { tenantId: string; region?: string };
|
|
126
|
+
* const tenantBaggage = defineBaggageSchema<TenantBaggage>('tenant');
|
|
127
|
+
*
|
|
128
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
129
|
+
* // Get typed baggage
|
|
130
|
+
* const tenant = tenantBaggage.get(ctx);
|
|
131
|
+
* if (tenant?.tenantId) {
|
|
132
|
+
* console.log('Tenant:', tenant.tenantId);
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* // Set typed baggage
|
|
136
|
+
* tenantBaggage.set(ctx, { tenantId: 't1', region: 'us-east-1' });
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example With withBaggage helper
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const tenantBaggage = defineBaggageSchema<TenantBaggage>('tenant');
|
|
143
|
+
*
|
|
144
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
145
|
+
* return await tenantBaggage.with(ctx, { tenantId: 't1' }, async () => {
|
|
146
|
+
* // Baggage is available here and in child spans
|
|
147
|
+
* const tenant = tenantBaggage.get(ctx);
|
|
148
|
+
* });
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function defineBaggageSchema<T extends Record<string, unknown>>(namespace?: string): {
|
|
153
|
+
/**
|
|
154
|
+
* Get typed baggage from context
|
|
155
|
+
* @param ctx - Trace context
|
|
156
|
+
* @returns Partial baggage object or undefined if no baggage is set
|
|
157
|
+
*/
|
|
158
|
+
get: (ctx: TraceContext<T>) => Partial<T> | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Set typed baggage in context
|
|
161
|
+
*
|
|
162
|
+
* Note: For proper scoping across async boundaries, use the `with` method instead
|
|
163
|
+
*
|
|
164
|
+
* @param ctx - Trace context
|
|
165
|
+
* @param value - Partial baggage object to set
|
|
166
|
+
*/
|
|
167
|
+
set: (ctx: TraceContext<T>, value: Partial<T>) => void;
|
|
168
|
+
/**
|
|
169
|
+
* Run a function with typed baggage properly scoped
|
|
170
|
+
*
|
|
171
|
+
* This is the recommended way to set baggage as it ensures proper
|
|
172
|
+
* scoping across async boundaries.
|
|
173
|
+
*
|
|
174
|
+
* @param ctx - Trace context (can be omitted, will use active context)
|
|
175
|
+
* @param value - Partial baggage object to set
|
|
176
|
+
* @param fn - Function to execute with the baggage
|
|
177
|
+
*/
|
|
178
|
+
with: <R>(ctxOrValue: TraceContext<T> | Partial<T>, valueOrFn: Partial<T> | (() => R | Promise<R>), maybeFn?: () => R | Promise<R>) => R | Promise<R>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export { type TraceContext as T, defineBaggageSchema as d };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { SpanStatusCode, BaggageEntry } from '@opentelemetry/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Trace context types and utilities
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base trace context containing trace identifiers
|
|
9
|
+
*/
|
|
10
|
+
interface TraceContextBase {
|
|
11
|
+
traceId: string;
|
|
12
|
+
spanId: string;
|
|
13
|
+
correlationId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Span methods available on trace context
|
|
17
|
+
*/
|
|
18
|
+
interface SpanMethods {
|
|
19
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
20
|
+
setAttributes(attrs: Record<string, string | number | boolean>): void;
|
|
21
|
+
setStatus(status: {
|
|
22
|
+
code: SpanStatusCode;
|
|
23
|
+
message?: string;
|
|
24
|
+
}): void;
|
|
25
|
+
recordException(exception: Error): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Baggage methods available on trace context
|
|
29
|
+
*
|
|
30
|
+
* @template TBaggage - Optional type for typed baggage (defaults to undefined for untyped)
|
|
31
|
+
*/
|
|
32
|
+
interface BaggageMethods<TBaggage extends Record<string, unknown> | undefined = undefined> {
|
|
33
|
+
/**
|
|
34
|
+
* Get a baggage entry by key
|
|
35
|
+
* @param key - Baggage key
|
|
36
|
+
* @returns Baggage entry value or undefined
|
|
37
|
+
*/
|
|
38
|
+
getBaggage(key: string): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Set a baggage entry
|
|
41
|
+
*
|
|
42
|
+
* Note: OpenTelemetry contexts are immutable. For proper scoping across async
|
|
43
|
+
* boundaries, use withBaggage() instead. This method updates baggage in the
|
|
44
|
+
* current context which may not propagate to all child operations.
|
|
45
|
+
*
|
|
46
|
+
* @param key - Baggage key
|
|
47
|
+
* @param value - Baggage value
|
|
48
|
+
* @returns The baggage value that was set (for chaining)
|
|
49
|
+
*
|
|
50
|
+
* @example Using withBaggage() (recommended)
|
|
51
|
+
* ```typescript
|
|
52
|
+
* await withBaggage({ baggage: { 'key': 'value' }, fn: async () => {
|
|
53
|
+
* // Baggage is available here and in child spans
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
setBaggage(key: string, value: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Delete a baggage entry
|
|
60
|
+
*
|
|
61
|
+
* Note: OpenTelemetry contexts are immutable. For proper scoping across async
|
|
62
|
+
* boundaries, use withBaggage() with only the entries you want instead.
|
|
63
|
+
*
|
|
64
|
+
* @param key - Baggage key
|
|
65
|
+
*/
|
|
66
|
+
deleteBaggage(key: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get all baggage entries
|
|
69
|
+
* @returns Map of all baggage entries
|
|
70
|
+
*/
|
|
71
|
+
getAllBaggage(): Map<string, BaggageEntry>;
|
|
72
|
+
/**
|
|
73
|
+
* Get typed baggage (only available when TBaggage is defined)
|
|
74
|
+
* This is used internally by defineBaggageSchema()
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
getTypedBaggage?: TBaggage extends Record<string, unknown> ? <T extends TBaggage>(namespace?: string) => Partial<T> | undefined : never;
|
|
79
|
+
/**
|
|
80
|
+
* Set typed baggage (only available when TBaggage is defined)
|
|
81
|
+
* This is used internally by defineBaggageSchema()
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
setTypedBaggage?: TBaggage extends Record<string, unknown> ? <T extends TBaggage>(namespace: string | undefined, value: Partial<T>) => void : never;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Complete trace context that merges base context, span methods, and baggage methods
|
|
89
|
+
*
|
|
90
|
+
* This is the ctx parameter passed to factory functions in trace().
|
|
91
|
+
* It provides access to trace IDs, span manipulation methods, and baggage operations.
|
|
92
|
+
*
|
|
93
|
+
* @template TBaggage - Optional type for typed baggage support
|
|
94
|
+
*
|
|
95
|
+
* @example Untyped (default)
|
|
96
|
+
* ```typescript
|
|
97
|
+
* export const handler = trace((ctx) => async () => {
|
|
98
|
+
* ctx.getBaggage('key'); // returns string | undefined
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Typed baggage
|
|
103
|
+
* ```typescript
|
|
104
|
+
* type TenantBaggage = { tenantId: string; region?: string };
|
|
105
|
+
*
|
|
106
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
107
|
+
* // Use typed schema helper for type-safe access
|
|
108
|
+
* const schema = defineBaggageSchema<TenantBaggage>('tenant');
|
|
109
|
+
* const tenant = schema.get(ctx); // Partial<TenantBaggage> | undefined
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
type TraceContext<TBaggage extends Record<string, unknown> | undefined = undefined> = TraceContextBase & SpanMethods & BaggageMethods<TBaggage>;
|
|
114
|
+
/**
|
|
115
|
+
* Define a typed baggage schema for type-safe baggage operations
|
|
116
|
+
*
|
|
117
|
+
* This helper provides a type-safe API for working with baggage entries.
|
|
118
|
+
* The namespace parameter is optional and prefixes all keys to avoid collisions.
|
|
119
|
+
*
|
|
120
|
+
* @template T - The baggage schema type (all fields are treated as optional)
|
|
121
|
+
* @param namespace - Optional namespace to prefix baggage keys
|
|
122
|
+
*
|
|
123
|
+
* @example Basic usage
|
|
124
|
+
* ```typescript
|
|
125
|
+
* type TenantBaggage = { tenantId: string; region?: string };
|
|
126
|
+
* const tenantBaggage = defineBaggageSchema<TenantBaggage>('tenant');
|
|
127
|
+
*
|
|
128
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
129
|
+
* // Get typed baggage
|
|
130
|
+
* const tenant = tenantBaggage.get(ctx);
|
|
131
|
+
* if (tenant?.tenantId) {
|
|
132
|
+
* console.log('Tenant:', tenant.tenantId);
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* // Set typed baggage
|
|
136
|
+
* tenantBaggage.set(ctx, { tenantId: 't1', region: 'us-east-1' });
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example With withBaggage helper
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const tenantBaggage = defineBaggageSchema<TenantBaggage>('tenant');
|
|
143
|
+
*
|
|
144
|
+
* export const handler = trace<TenantBaggage>((ctx) => async () => {
|
|
145
|
+
* return await tenantBaggage.with(ctx, { tenantId: 't1' }, async () => {
|
|
146
|
+
* // Baggage is available here and in child spans
|
|
147
|
+
* const tenant = tenantBaggage.get(ctx);
|
|
148
|
+
* });
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare function defineBaggageSchema<T extends Record<string, unknown>>(namespace?: string): {
|
|
153
|
+
/**
|
|
154
|
+
* Get typed baggage from context
|
|
155
|
+
* @param ctx - Trace context
|
|
156
|
+
* @returns Partial baggage object or undefined if no baggage is set
|
|
157
|
+
*/
|
|
158
|
+
get: (ctx: TraceContext<T>) => Partial<T> | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Set typed baggage in context
|
|
161
|
+
*
|
|
162
|
+
* Note: For proper scoping across async boundaries, use the `with` method instead
|
|
163
|
+
*
|
|
164
|
+
* @param ctx - Trace context
|
|
165
|
+
* @param value - Partial baggage object to set
|
|
166
|
+
*/
|
|
167
|
+
set: (ctx: TraceContext<T>, value: Partial<T>) => void;
|
|
168
|
+
/**
|
|
169
|
+
* Run a function with typed baggage properly scoped
|
|
170
|
+
*
|
|
171
|
+
* This is the recommended way to set baggage as it ensures proper
|
|
172
|
+
* scoping across async boundaries.
|
|
173
|
+
*
|
|
174
|
+
* @param ctx - Trace context (can be omitted, will use active context)
|
|
175
|
+
* @param value - Partial baggage object to set
|
|
176
|
+
* @param fn - Function to execute with the baggage
|
|
177
|
+
*/
|
|
178
|
+
with: <R>(ctxOrValue: TraceContext<T> | Partial<T>, valueOrFn: Partial<T> | (() => R | Promise<R>), maybeFn?: () => R | Promise<R>) => R | Promise<R>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export { type TraceContext as T, defineBaggageSchema as d };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkTRI4V5BF_cjs = require('./chunk-TRI4V5BF.cjs');
|
|
4
|
+
require('./chunk-NHCNRQD3.cjs');
|
|
5
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "createDeterministicTraceId", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkTRI4V5BF_cjs.createDeterministicTraceId; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "enrichWithTraceContext", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkTRI4V5BF_cjs.enrichWithTraceContext; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "finalizeSpan", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkTRI4V5BF_cjs.finalizeSpan; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "flattenMetadata", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunkTRI4V5BF_cjs.flattenMetadata; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "getActiveContext", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return chunkTRI4V5BF_cjs.getActiveContext; }
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "getActiveSpan", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return chunkTRI4V5BF_cjs.getActiveSpan; }
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "getTraceContext", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return chunkTRI4V5BF_cjs.getTraceContext; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getTracer", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return chunkTRI4V5BF_cjs.getTracer; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "isTracing", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return chunkTRI4V5BF_cjs.isTracing; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "runWithSpan", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return chunkTRI4V5BF_cjs.runWithSpan; }
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "setSpanName", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return chunkTRI4V5BF_cjs.setSpanName; }
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=trace-helpers.cjs.map
|
|
54
|
+
//# sourceMappingURL=trace-helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"trace-helpers.cjs"}
|