autotel-edge 3.0.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 +333 -0
- package/dist/chunk-F32WSLNX.js +309 -0
- package/dist/chunk-F32WSLNX.js.map +1 -0
- package/dist/events.d.ts +86 -0
- package/dist/events.js +157 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +326 -0
- package/dist/index.js +921 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +89 -0
- package/dist/logger.js +81 -0
- package/dist/logger.js.map +1 -0
- package/dist/sampling.d.ts +166 -0
- package/dist/sampling.js +108 -0
- package/dist/sampling.js.map +1 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-Dj85cPUj.d.ts +182 -0
- package/package.json +88 -0
- package/src/api/logger.test.ts +367 -0
- package/src/api/logger.ts +197 -0
- package/src/compose.ts +243 -0
- package/src/core/buffer.ts +16 -0
- package/src/core/config.test.ts +388 -0
- package/src/core/config.ts +167 -0
- package/src/core/context.ts +224 -0
- package/src/core/exporter.ts +99 -0
- package/src/core/provider.ts +45 -0
- package/src/core/span.ts +222 -0
- package/src/core/spanprocessor.test.ts +521 -0
- package/src/core/spanprocessor.ts +232 -0
- package/src/core/trace-context.ts +66 -0
- package/src/core/tracer.test.ts +123 -0
- package/src/core/tracer.ts +216 -0
- package/src/events/index.test.ts +242 -0
- package/src/events/index.ts +338 -0
- package/src/events.ts +6 -0
- package/src/functional.test.ts +702 -0
- package/src/functional.ts +846 -0
- package/src/index.ts +81 -0
- package/src/logger.ts +13 -0
- package/src/sampling/index.test.ts +297 -0
- package/src/sampling/index.ts +276 -0
- package/src/sampling.ts +6 -0
- package/src/testing/index.ts +9 -0
- package/src/testing.ts +6 -0
- package/src/types.ts +267 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for autotel-edge
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
Attributes,
|
|
7
|
+
Context,
|
|
8
|
+
Span,
|
|
9
|
+
SpanOptions,
|
|
10
|
+
TextMapPropagator,
|
|
11
|
+
} from '@opentelemetry/api';
|
|
12
|
+
import type {
|
|
13
|
+
ReadableSpan,
|
|
14
|
+
Sampler,
|
|
15
|
+
SpanExporter,
|
|
16
|
+
SpanProcessor,
|
|
17
|
+
} from '@opentelemetry/sdk-trace-base';
|
|
18
|
+
|
|
19
|
+
// Re-export commonly used types
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extended SpanOptions with per-span sampler support
|
|
24
|
+
*/
|
|
25
|
+
export interface ExtendedSpanOptions extends SpanOptions {
|
|
26
|
+
sampler?: Sampler;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Trigger types for edge handlers
|
|
31
|
+
* Can be a Request or any vendor-specific trigger type
|
|
32
|
+
*/
|
|
33
|
+
export type Trigger =
|
|
34
|
+
| Request
|
|
35
|
+
| DOConstructorTrigger
|
|
36
|
+
| 'do-alarm'
|
|
37
|
+
| unknown;
|
|
38
|
+
|
|
39
|
+
export interface DOConstructorTrigger {
|
|
40
|
+
id: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Config types
|
|
46
|
+
*/
|
|
47
|
+
export interface OTLPExporterConfig {
|
|
48
|
+
url: string;
|
|
49
|
+
headers?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ExporterConfig = OTLPExporterConfig | SpanExporter;
|
|
53
|
+
|
|
54
|
+
export interface ServiceConfig {
|
|
55
|
+
name: string;
|
|
56
|
+
namespace?: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ParentRatioSamplingConfig {
|
|
61
|
+
acceptRemote?: boolean;
|
|
62
|
+
ratio: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type HeadSamplerConf = Sampler | ParentRatioSamplingConfig;
|
|
66
|
+
|
|
67
|
+
export interface SamplingConfig<HS extends HeadSamplerConf = HeadSamplerConf> {
|
|
68
|
+
headSampler?: HS;
|
|
69
|
+
tailSampler?: TailSampleFn;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface InstrumentationOptions {
|
|
73
|
+
instrumentGlobalFetch?: boolean;
|
|
74
|
+
instrumentGlobalCache?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Disable instrumentation entirely (useful for local development)
|
|
77
|
+
* When enabled, the handler is returned as-is without any instrumentation
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
disabled?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Utility types
|
|
85
|
+
*/
|
|
86
|
+
export type OrPromise<T> = T | Promise<T>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Adapter event types
|
|
90
|
+
*/
|
|
91
|
+
export type FunnelStepStatus =
|
|
92
|
+
| 'started'
|
|
93
|
+
| 'completed'
|
|
94
|
+
| 'abandoned'
|
|
95
|
+
| 'failed'
|
|
96
|
+
| (string & {});
|
|
97
|
+
|
|
98
|
+
export type OutcomeStatus =
|
|
99
|
+
| 'success'
|
|
100
|
+
| 'failure'
|
|
101
|
+
| 'partial'
|
|
102
|
+
| (string & {});
|
|
103
|
+
|
|
104
|
+
export interface EdgeEventBase {
|
|
105
|
+
[key: string]: unknown;
|
|
106
|
+
service: string;
|
|
107
|
+
timestamp: number;
|
|
108
|
+
attributes: Record<string, unknown>;
|
|
109
|
+
traceId?: string;
|
|
110
|
+
spanId?: string;
|
|
111
|
+
correlationId?: string;
|
|
112
|
+
name: string; // Normalized event name for easy access
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface EdgeTrackEvent extends EdgeEventBase {
|
|
116
|
+
type: 'event';
|
|
117
|
+
event: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface EdgeFunnelStepEvent extends EdgeEventBase {
|
|
121
|
+
type: 'funnel-step';
|
|
122
|
+
funnel: string;
|
|
123
|
+
status: FunnelStepStatus;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface EdgeOutcomeEvent extends EdgeEventBase {
|
|
127
|
+
type: 'outcome';
|
|
128
|
+
operation: string;
|
|
129
|
+
outcome: OutcomeStatus;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface EdgeValueEvent extends EdgeEventBase {
|
|
133
|
+
type: 'value';
|
|
134
|
+
metric: string;
|
|
135
|
+
value: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type EdgeEvent =
|
|
139
|
+
| EdgeTrackEvent
|
|
140
|
+
| EdgeFunnelStepEvent
|
|
141
|
+
| EdgeOutcomeEvent
|
|
142
|
+
| EdgeValueEvent;
|
|
143
|
+
|
|
144
|
+
export type EdgeSubscriber = (event: EdgeEvent) => OrPromise<void>;
|
|
145
|
+
|
|
146
|
+
export interface FetcherConfig {
|
|
147
|
+
includeTraceContext?: boolean | ((request: Request) => boolean);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface PostProcessParams {
|
|
151
|
+
/**
|
|
152
|
+
* The request object that was passed to the fetch handler.
|
|
153
|
+
*/
|
|
154
|
+
request: Request;
|
|
155
|
+
/**
|
|
156
|
+
* The generated response object.
|
|
157
|
+
*/
|
|
158
|
+
response: Response;
|
|
159
|
+
/**
|
|
160
|
+
* A readable version of the span object that can be used to access the span's attributes and events.
|
|
161
|
+
*/
|
|
162
|
+
readable: ReadableSpan;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface FetchHandlerConfig {
|
|
166
|
+
/**
|
|
167
|
+
* Whether to enable context propagation for incoming requests to `fetch`.
|
|
168
|
+
* This enables or disables distributed tracing from W3C Trace Context headers.
|
|
169
|
+
* @default true
|
|
170
|
+
*/
|
|
171
|
+
acceptTraceContext?: boolean | ((request: Request) => boolean);
|
|
172
|
+
/**
|
|
173
|
+
* Allows further customization of the generated span, based on the request/response data.
|
|
174
|
+
*/
|
|
175
|
+
postProcess?: (span: Span, ctx: PostProcessParams) => void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface HandlerConfig {
|
|
179
|
+
fetch?: FetchHandlerConfig;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
interface EdgeConfigBase {
|
|
183
|
+
service: ServiceConfig;
|
|
184
|
+
handlers?: HandlerConfig;
|
|
185
|
+
fetch?: FetcherConfig;
|
|
186
|
+
postProcessor?: PostProcessorFn;
|
|
187
|
+
sampling?: SamplingConfig;
|
|
188
|
+
propagator?: TextMapPropagator;
|
|
189
|
+
instrumentation?: InstrumentationOptions;
|
|
190
|
+
subscribers?: EdgeSubscriber[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface EdgeConfigExporter extends EdgeConfigBase {
|
|
194
|
+
exporter: ExporterConfig;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface EdgeConfigSpanProcessors extends EdgeConfigBase {
|
|
198
|
+
spanProcessors: SpanProcessor | SpanProcessor[];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type EdgeConfig = EdgeConfigExporter | EdgeConfigSpanProcessors;
|
|
202
|
+
|
|
203
|
+
export function isSpanProcessorConfig(
|
|
204
|
+
config: EdgeConfig,
|
|
205
|
+
): config is EdgeConfigSpanProcessors {
|
|
206
|
+
return !!(config as EdgeConfigSpanProcessors).spanProcessors;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface ResolvedEdgeConfig extends EdgeConfigBase {
|
|
210
|
+
handlers: Required<HandlerConfig>;
|
|
211
|
+
fetch: Required<FetcherConfig>;
|
|
212
|
+
postProcessor: PostProcessorFn;
|
|
213
|
+
sampling: Required<SamplingConfig<Sampler>>;
|
|
214
|
+
spanProcessors: SpanProcessor[];
|
|
215
|
+
propagator: TextMapPropagator;
|
|
216
|
+
instrumentation: InstrumentationOptions;
|
|
217
|
+
subscribers: EdgeSubscriber[];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Function types
|
|
222
|
+
*/
|
|
223
|
+
export type ResolveConfigFn<Env = any> = (
|
|
224
|
+
env: Env,
|
|
225
|
+
trigger: Trigger,
|
|
226
|
+
) => EdgeConfig;
|
|
227
|
+
export type ConfigurationOption = EdgeConfig | ResolveConfigFn;
|
|
228
|
+
|
|
229
|
+
export type PostProcessorFn = (spans: ReadableSpan[]) => ReadableSpan[];
|
|
230
|
+
export type TailSampleFn = (traceInfo: LocalTrace) => boolean;
|
|
231
|
+
|
|
232
|
+
export interface LocalTrace {
|
|
233
|
+
traceId: string;
|
|
234
|
+
spans: ReadableSpan[];
|
|
235
|
+
localRootSpan: ReadableSpan;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Span processor with flush support
|
|
240
|
+
*/
|
|
241
|
+
export type TraceFlushableSpanProcessor = SpanProcessor & {
|
|
242
|
+
forceFlush: (traceId?: string) => Promise<void>;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Handler instrumentation
|
|
247
|
+
*/
|
|
248
|
+
export interface InitialSpanInfo {
|
|
249
|
+
name: string;
|
|
250
|
+
options: SpanOptions;
|
|
251
|
+
context?: Context;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface HandlerInstrumentation<T extends Trigger, R extends any> {
|
|
255
|
+
getInitialSpanInfo: (trigger: T) => InitialSpanInfo;
|
|
256
|
+
getAttributesFromResult?: (result: Awaited<R>) => Attributes;
|
|
257
|
+
instrumentTrigger?: (trigger: T) => T;
|
|
258
|
+
executionSucces?: (span: Span, trigger: T, result: Awaited<R>) => void;
|
|
259
|
+
executionFailed?: (span: Span, trigger: T, error?: any) => void;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Utility types
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
export {type Attributes, type Context, type Span, type SpanOptions} from '@opentelemetry/api';
|
|
267
|
+
export {type ReadableSpan} from '@opentelemetry/sdk-trace-base';
|