veryfront 0.1.474 → 0.1.475
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/esm/deno.js +1 -1
- package/esm/src/observability/index.d.ts +1 -0
- package/esm/src/observability/index.d.ts.map +1 -1
- package/esm/src/observability/index.js +1 -0
- package/esm/src/observability/tracing/service-tracer.d.ts +73 -0
- package/esm/src/observability/tracing/service-tracer.d.ts.map +1 -0
- package/esm/src/observability/tracing/service-tracer.js +131 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/src/observability/index.ts +18 -0
- package/src/src/observability/tracing/service-tracer.ts +267 -0
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
|
@@ -18,6 +18,7 @@ export { addSpanEvent, createChildSpan, endSpan, extractContext, getActiveContex
|
|
|
18
18
|
export { getMetricsState, initMetrics, isMetricsEnabled, type MetricsConfig, recordBuild, recordBundle, recordCacheGet, recordCacheInvalidate, recordCacheSet, recordCorsRejection, recordDataFetch, recordDataFetchError, recordHttpRequest, recordHttpRequestComplete, recordRender, recordRenderError, recordRSCError, recordRSCRender, recordRSCRequest, recordRSCStream, recordSecurityHeaders, setCacheSize, shutdownMetrics, } from "./metrics/index.js";
|
|
19
19
|
export { type AutoInstrumentConfig, initAutoInstrumentation, instrument, instrumentBatch, instrumentErrorHandler, instrumentFetch, instrumentHttpHandler, instrumentReactRender, instrumentSync, isAutoInstrumentEnabled, } from "./auto-instrument/index.js";
|
|
20
20
|
export { initializeOTLP, isOTLPEnabled, type OTLPConfig, shutdownOTLP, } from "./tracing/otlp-setup.js";
|
|
21
|
+
export { createOpenTelemetryServiceTracer, type CreateOpenTelemetryServiceTracerOptions, type OpenTelemetryContextApi, type OpenTelemetryServiceTracer, type OpenTelemetrySpan, type OpenTelemetrySpanContext, type OpenTelemetryTraceApi, type OpenTelemetryTracer, type ServiceTracer, type ServiceTracerAttributeInput, type ServiceTracerAttributes, type ServiceTracerAttributeValue, type ServiceTracerSpan, type ServiceTracerSpanContext, type ServiceTracerStartSpanOptions, } from "./tracing/service-tracer.js";
|
|
21
22
|
export { type DevError, ErrorCollector, type ErrorFilter, type ErrorSubscriber, type ErrorType, getErrorCollector, parseCompileError, resetErrorCollector, } from "./error-collector.js";
|
|
22
23
|
export { getLogBuffer, interceptConsole, LogBuffer, type LogEntry, type LogFilter as LogBufferFilter, type LogLevel, type LogSubscriber, resetLogBuffer, } from "./log-buffer.js";
|
|
23
24
|
export { createFileLogSubscriber, type FileLogConfig, FileLogSubscriber, parseMaxSize, } from "./file-log-subscriber.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/observability/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,KAAK,WAAW,EAChB,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,QAAQ,EACR,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,KAAK,aAAa,EAClB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,oBAAoB,EACzB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,cAAc,EACd,aAAa,EACb,KAAK,UAAU,EACf,YAAY,GACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,QAAQ,EACb,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,KAAK,QAAQ,EACb,KAAK,SAAS,IAAI,eAAe,EACjC,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,KAAK,aAAa,EAClB,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/observability/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,KAAK,WAAW,EAChB,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,QAAQ,EACR,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,KAAK,aAAa,EAClB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,oBAAoB,EACzB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,cAAc,EACd,aAAa,EACb,KAAK,UAAU,EACf,YAAY,GACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,gCAAgC,EAChC,KAAK,uCAAuC,EAC5C,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,GACnC,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,KAAK,QAAQ,EACb,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,KAAK,QAAQ,EACb,KAAK,SAAS,IAAI,eAAe,EACjC,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,KAAK,aAAa,EAClB,iBAAiB,EACjB,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
|
@@ -18,6 +18,7 @@ export { addSpanEvent, createChildSpan, endSpan, extractContext, getActiveContex
|
|
|
18
18
|
export { getMetricsState, initMetrics, isMetricsEnabled, recordBuild, recordBundle, recordCacheGet, recordCacheInvalidate, recordCacheSet, recordCorsRejection, recordDataFetch, recordDataFetchError, recordHttpRequest, recordHttpRequestComplete, recordRender, recordRenderError, recordRSCError, recordRSCRender, recordRSCRequest, recordRSCStream, recordSecurityHeaders, setCacheSize, shutdownMetrics, } from "./metrics/index.js";
|
|
19
19
|
export { initAutoInstrumentation, instrument, instrumentBatch, instrumentErrorHandler, instrumentFetch, instrumentHttpHandler, instrumentReactRender, instrumentSync, isAutoInstrumentEnabled, } from "./auto-instrument/index.js";
|
|
20
20
|
export { initializeOTLP, isOTLPEnabled, shutdownOTLP, } from "./tracing/otlp-setup.js";
|
|
21
|
+
export { createOpenTelemetryServiceTracer, } from "./tracing/service-tracer.js";
|
|
21
22
|
export { ErrorCollector, getErrorCollector, parseCompileError, resetErrorCollector, } from "./error-collector.js";
|
|
22
23
|
export { getLogBuffer, interceptConsole, LogBuffer, resetLogBuffer, } from "./log-buffer.js";
|
|
23
24
|
export { createFileLogSubscriber, FileLogSubscriber, parseMaxSize, } from "./file-log-subscriber.js";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type OpenTelemetrySpanContext = {
|
|
2
|
+
traceId: string;
|
|
3
|
+
spanId: string;
|
|
4
|
+
};
|
|
5
|
+
export type OpenTelemetrySpan = {
|
|
6
|
+
setAttribute(key: string, value: string | number | boolean): unknown;
|
|
7
|
+
setAttributes(attributes: Record<string, string | number | boolean>): unknown;
|
|
8
|
+
setStatus(status: {
|
|
9
|
+
code: number;
|
|
10
|
+
}): unknown;
|
|
11
|
+
recordException(error: unknown): unknown;
|
|
12
|
+
end(): unknown;
|
|
13
|
+
spanContext(): OpenTelemetrySpanContext;
|
|
14
|
+
};
|
|
15
|
+
export type OpenTelemetryTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
16
|
+
startSpan(name: string, options: TSpanOptions | undefined, context: TContext): TSpan;
|
|
17
|
+
startActiveSpan<T>(name: string, fn: (span: TSpan) => T): T;
|
|
18
|
+
};
|
|
19
|
+
export type OpenTelemetryTraceApi<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
20
|
+
getTracer(serviceName: string): OpenTelemetryTracer<TContext, TSpan, TSpanOptions>;
|
|
21
|
+
getSpan(context: TContext): TSpan | undefined;
|
|
22
|
+
setSpan(context: TContext, span: TSpan): TContext;
|
|
23
|
+
};
|
|
24
|
+
export type OpenTelemetryContextApi<TContext> = {
|
|
25
|
+
active(): TContext;
|
|
26
|
+
with<T>(context: TContext, fn: () => T): T;
|
|
27
|
+
};
|
|
28
|
+
export type ServiceTracerAttributeInput = string | number | boolean | null | undefined | object;
|
|
29
|
+
export type ServiceTracerAttributePrimitive = string | number | boolean;
|
|
30
|
+
export type ServiceTracerAttributeValue = ServiceTracerAttributePrimitive | readonly ServiceTracerAttributePrimitive[] | null | undefined;
|
|
31
|
+
export type ServiceTracerAttributes = Record<string, ServiceTracerAttributeValue>;
|
|
32
|
+
export type ServiceTracerSpanContext = {
|
|
33
|
+
toTraceId(): string;
|
|
34
|
+
toSpanId(): string;
|
|
35
|
+
};
|
|
36
|
+
export type ServiceTracerSpan<TContext, TSpan extends OpenTelemetrySpan> = {
|
|
37
|
+
setTag(key: string, value: ServiceTracerAttributeInput): TSpan;
|
|
38
|
+
setAttributes(attributes: Record<string, ServiceTracerAttributeInput>): TSpan;
|
|
39
|
+
finish(): void;
|
|
40
|
+
withContext<T>(fn: () => T): T;
|
|
41
|
+
context(): ServiceTracerSpanContext | undefined;
|
|
42
|
+
readonly otelSpan: TSpan;
|
|
43
|
+
readonly otelContext: TContext;
|
|
44
|
+
};
|
|
45
|
+
export type ServiceTracerStartSpanOptions<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = TSpanOptions & {
|
|
46
|
+
childOf?: ServiceTracerSpan<TContext, TSpan>;
|
|
47
|
+
};
|
|
48
|
+
export type ServiceTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
49
|
+
init(): void;
|
|
50
|
+
startSpan(name: string, options?: ServiceTracerStartSpanOptions<TContext, TSpan, TSpanOptions>): ServiceTracerSpan<TContext, TSpan>;
|
|
51
|
+
scope(): {
|
|
52
|
+
active(): ServiceTracerSpan<TContext, TSpan> | null;
|
|
53
|
+
};
|
|
54
|
+
wrap<TArgs extends unknown[], TResult>(name: string, fn: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
|
|
55
|
+
trace<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
56
|
+
trace<T>(name: string, fn: () => T): T;
|
|
57
|
+
};
|
|
58
|
+
export type CreateOpenTelemetryServiceTracerOptions<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
59
|
+
serviceName: string;
|
|
60
|
+
context: OpenTelemetryContextApi<TContext>;
|
|
61
|
+
trace: OpenTelemetryTraceApi<TContext, TSpan, TSpanOptions>;
|
|
62
|
+
errorStatusCode: number;
|
|
63
|
+
};
|
|
64
|
+
export type OpenTelemetryServiceTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
65
|
+
tracer: ServiceTracer<TContext, TSpan, TSpanOptions>;
|
|
66
|
+
setActiveSpanAttributes(attributes: ServiceTracerAttributes): void;
|
|
67
|
+
getTraceContext(): {
|
|
68
|
+
traceId?: string;
|
|
69
|
+
spanId?: string;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export declare function createOpenTelemetryServiceTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions>(options: CreateOpenTelemetryServiceTracerOptions<TContext, TSpan, TSpanOptions>): OpenTelemetryServiceTracer<TContext, TSpan, TSpanOptions>;
|
|
73
|
+
//# sourceMappingURL=service-tracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-tracer.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/tracing/service-tracer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,w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EAC/B,YAAY,IACV;IACF,MAAM,EAAE,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IACrD,uBAAuB,CAAC,UAAU,EAAE,uBAAuB,GAAG,IAAI,CAAC;IACnE,eAAe,IAAI;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D,CAAC;AA4DF,wBAAgB,gCAAgC,CAC9C,QAAQ,EACR,KAAK,SAAS,iBAAiB,EAC/B,YAAY,EAEZ,OAAO,EAAE,uCAAuC,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,GAC9E,0BAA0B,CAAC,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC,CAmG3D"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
function toAttributeValue(value) {
|
|
2
|
+
if (value === null || value === undefined) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
if (typeof value === "object") {
|
|
6
|
+
return JSON.stringify(value);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function createTracerSpan(contextApi, span, context) {
|
|
11
|
+
const spanContext = span.spanContext();
|
|
12
|
+
return {
|
|
13
|
+
setTag: (key, value) => {
|
|
14
|
+
span.setAttribute(key, toAttributeValue(value));
|
|
15
|
+
return span;
|
|
16
|
+
},
|
|
17
|
+
setAttributes: (attributes) => {
|
|
18
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
19
|
+
span.setAttribute(key, toAttributeValue(value));
|
|
20
|
+
}
|
|
21
|
+
return span;
|
|
22
|
+
},
|
|
23
|
+
finish: () => {
|
|
24
|
+
span.end();
|
|
25
|
+
},
|
|
26
|
+
withContext: (fn) => contextApi.with(context, fn),
|
|
27
|
+
context: () => ({
|
|
28
|
+
toTraceId: () => spanContext.traceId,
|
|
29
|
+
toSpanId: () => spanContext.spanId,
|
|
30
|
+
}),
|
|
31
|
+
otelSpan: span,
|
|
32
|
+
otelContext: context,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function setSpanErrorStatus(span, errorStatusCode, error) {
|
|
36
|
+
span.setStatus({ code: errorStatusCode });
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
span.recordException(error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isPromise(value) {
|
|
42
|
+
return value instanceof Promise;
|
|
43
|
+
}
|
|
44
|
+
export function createOpenTelemetryServiceTracer(options) {
|
|
45
|
+
const otelTracer = options.trace.getTracer(options.serviceName);
|
|
46
|
+
function wrap(name, fn) {
|
|
47
|
+
return (...args) => {
|
|
48
|
+
const span = otelTracer.startSpan(name, undefined, options.context.active());
|
|
49
|
+
const contextWithSpan = options.trace.setSpan(options.context.active(), span);
|
|
50
|
+
try {
|
|
51
|
+
return options.context.with(contextWithSpan, () => fn(...args));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
span.end();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function trace(name, fn) {
|
|
63
|
+
return otelTracer.startActiveSpan(name, (span) => {
|
|
64
|
+
try {
|
|
65
|
+
const result = fn();
|
|
66
|
+
if (isPromise(result)) {
|
|
67
|
+
return result
|
|
68
|
+
.then((value) => {
|
|
69
|
+
span.end();
|
|
70
|
+
return value;
|
|
71
|
+
})
|
|
72
|
+
.catch((error) => {
|
|
73
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
74
|
+
span.end();
|
|
75
|
+
throw error;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
span.end();
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
83
|
+
span.end();
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const tracer = {
|
|
89
|
+
init: () => { },
|
|
90
|
+
startSpan: (name, startOptions) => {
|
|
91
|
+
let parentContext = options.context.active();
|
|
92
|
+
if (startOptions?.childOf?.otelSpan) {
|
|
93
|
+
parentContext = options.trace.setSpan(options.context.active(), startOptions.childOf.otelSpan);
|
|
94
|
+
}
|
|
95
|
+
const span = otelTracer.startSpan(name, startOptions, parentContext);
|
|
96
|
+
const spanContext = options.trace.setSpan(parentContext, span);
|
|
97
|
+
return createTracerSpan(options.context, span, spanContext);
|
|
98
|
+
},
|
|
99
|
+
scope: () => ({
|
|
100
|
+
active: () => {
|
|
101
|
+
const activeContext = options.context.active();
|
|
102
|
+
const activeSpan = options.trace.getSpan(activeContext);
|
|
103
|
+
if (!activeSpan)
|
|
104
|
+
return null;
|
|
105
|
+
return createTracerSpan(options.context, activeSpan, activeContext);
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
wrap,
|
|
109
|
+
trace,
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
tracer,
|
|
113
|
+
setActiveSpanAttributes(attributes) {
|
|
114
|
+
const activeSpan = tracer.scope().active();
|
|
115
|
+
if (!activeSpan)
|
|
116
|
+
return;
|
|
117
|
+
activeSpan.setAttributes(attributes);
|
|
118
|
+
},
|
|
119
|
+
getTraceContext() {
|
|
120
|
+
const activeSpan = tracer.scope().active();
|
|
121
|
+
if (!activeSpan) {
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
const spanContext = activeSpan.otelSpan.spanContext();
|
|
125
|
+
return {
|
|
126
|
+
traceId: spanContext.traceId,
|
|
127
|
+
spanId: spanContext.spanId,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.475";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
|
@@ -82,6 +82,24 @@ export {
|
|
|
82
82
|
shutdownOTLP,
|
|
83
83
|
} from "./tracing/otlp-setup.js";
|
|
84
84
|
|
|
85
|
+
export {
|
|
86
|
+
createOpenTelemetryServiceTracer,
|
|
87
|
+
type CreateOpenTelemetryServiceTracerOptions,
|
|
88
|
+
type OpenTelemetryContextApi,
|
|
89
|
+
type OpenTelemetryServiceTracer,
|
|
90
|
+
type OpenTelemetrySpan,
|
|
91
|
+
type OpenTelemetrySpanContext,
|
|
92
|
+
type OpenTelemetryTraceApi,
|
|
93
|
+
type OpenTelemetryTracer,
|
|
94
|
+
type ServiceTracer,
|
|
95
|
+
type ServiceTracerAttributeInput,
|
|
96
|
+
type ServiceTracerAttributes,
|
|
97
|
+
type ServiceTracerAttributeValue,
|
|
98
|
+
type ServiceTracerSpan,
|
|
99
|
+
type ServiceTracerSpanContext,
|
|
100
|
+
type ServiceTracerStartSpanOptions,
|
|
101
|
+
} from "./tracing/service-tracer.js";
|
|
102
|
+
|
|
85
103
|
export {
|
|
86
104
|
type DevError,
|
|
87
105
|
ErrorCollector,
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
export type OpenTelemetrySpanContext = {
|
|
2
|
+
traceId: string;
|
|
3
|
+
spanId: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type OpenTelemetrySpan = {
|
|
7
|
+
setAttribute(key: string, value: string | number | boolean): unknown;
|
|
8
|
+
setAttributes(attributes: Record<string, string | number | boolean>): unknown;
|
|
9
|
+
setStatus(status: { code: number }): unknown;
|
|
10
|
+
recordException(error: unknown): unknown;
|
|
11
|
+
end(): unknown;
|
|
12
|
+
spanContext(): OpenTelemetrySpanContext;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type OpenTelemetryTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
16
|
+
startSpan(name: string, options: TSpanOptions | undefined, context: TContext): TSpan;
|
|
17
|
+
startActiveSpan<T>(name: string, fn: (span: TSpan) => T): T;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type OpenTelemetryTraceApi<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
21
|
+
getTracer(serviceName: string): OpenTelemetryTracer<TContext, TSpan, TSpanOptions>;
|
|
22
|
+
getSpan(context: TContext): TSpan | undefined;
|
|
23
|
+
setSpan(context: TContext, span: TSpan): TContext;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type OpenTelemetryContextApi<TContext> = {
|
|
27
|
+
active(): TContext;
|
|
28
|
+
with<T>(context: TContext, fn: () => T): T;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ServiceTracerAttributeInput = string | number | boolean | null | undefined | object;
|
|
32
|
+
export type ServiceTracerAttributePrimitive = string | number | boolean;
|
|
33
|
+
export type ServiceTracerAttributeValue =
|
|
34
|
+
| ServiceTracerAttributePrimitive
|
|
35
|
+
| readonly ServiceTracerAttributePrimitive[]
|
|
36
|
+
| null
|
|
37
|
+
| undefined;
|
|
38
|
+
export type ServiceTracerAttributes = Record<string, ServiceTracerAttributeValue>;
|
|
39
|
+
|
|
40
|
+
export type ServiceTracerSpanContext = {
|
|
41
|
+
toTraceId(): string;
|
|
42
|
+
toSpanId(): string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type ServiceTracerSpan<
|
|
46
|
+
TContext,
|
|
47
|
+
TSpan extends OpenTelemetrySpan,
|
|
48
|
+
> = {
|
|
49
|
+
setTag(key: string, value: ServiceTracerAttributeInput): TSpan;
|
|
50
|
+
setAttributes(attributes: Record<string, ServiceTracerAttributeInput>): TSpan;
|
|
51
|
+
finish(): void;
|
|
52
|
+
withContext<T>(fn: () => T): T;
|
|
53
|
+
context(): ServiceTracerSpanContext | undefined;
|
|
54
|
+
readonly otelSpan: TSpan;
|
|
55
|
+
readonly otelContext: TContext;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type ServiceTracerStartSpanOptions<
|
|
59
|
+
TContext,
|
|
60
|
+
TSpan extends OpenTelemetrySpan,
|
|
61
|
+
TSpanOptions,
|
|
62
|
+
> = TSpanOptions & {
|
|
63
|
+
childOf?: ServiceTracerSpan<TContext, TSpan>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type ServiceTracer<TContext, TSpan extends OpenTelemetrySpan, TSpanOptions> = {
|
|
67
|
+
init(): void;
|
|
68
|
+
startSpan(
|
|
69
|
+
name: string,
|
|
70
|
+
options?: ServiceTracerStartSpanOptions<TContext, TSpan, TSpanOptions>,
|
|
71
|
+
): ServiceTracerSpan<TContext, TSpan>;
|
|
72
|
+
scope(): {
|
|
73
|
+
active(): ServiceTracerSpan<TContext, TSpan> | null;
|
|
74
|
+
};
|
|
75
|
+
wrap<TArgs extends unknown[], TResult>(
|
|
76
|
+
name: string,
|
|
77
|
+
fn: (...args: TArgs) => TResult,
|
|
78
|
+
): (...args: TArgs) => TResult;
|
|
79
|
+
trace<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
80
|
+
trace<T>(name: string, fn: () => T): T;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type CreateOpenTelemetryServiceTracerOptions<
|
|
84
|
+
TContext,
|
|
85
|
+
TSpan extends OpenTelemetrySpan,
|
|
86
|
+
TSpanOptions,
|
|
87
|
+
> = {
|
|
88
|
+
serviceName: string;
|
|
89
|
+
context: OpenTelemetryContextApi<TContext>;
|
|
90
|
+
trace: OpenTelemetryTraceApi<TContext, TSpan, TSpanOptions>;
|
|
91
|
+
errorStatusCode: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type OpenTelemetryServiceTracer<
|
|
95
|
+
TContext,
|
|
96
|
+
TSpan extends OpenTelemetrySpan,
|
|
97
|
+
TSpanOptions,
|
|
98
|
+
> = {
|
|
99
|
+
tracer: ServiceTracer<TContext, TSpan, TSpanOptions>;
|
|
100
|
+
setActiveSpanAttributes(attributes: ServiceTracerAttributes): void;
|
|
101
|
+
getTraceContext(): { traceId?: string; spanId?: string };
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function toAttributeValue(value: ServiceTracerAttributeInput): string | number | boolean {
|
|
105
|
+
if (value === null || value === undefined) {
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (typeof value === "object") {
|
|
110
|
+
return JSON.stringify(value);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function createTracerSpan<TContext, TSpan extends OpenTelemetrySpan>(
|
|
117
|
+
contextApi: OpenTelemetryContextApi<TContext>,
|
|
118
|
+
span: TSpan,
|
|
119
|
+
context: TContext,
|
|
120
|
+
): ServiceTracerSpan<TContext, TSpan> {
|
|
121
|
+
const spanContext = span.spanContext();
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
setTag: (key, value) => {
|
|
125
|
+
span.setAttribute(key, toAttributeValue(value));
|
|
126
|
+
return span;
|
|
127
|
+
},
|
|
128
|
+
setAttributes: (attributes) => {
|
|
129
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
130
|
+
span.setAttribute(key, toAttributeValue(value));
|
|
131
|
+
}
|
|
132
|
+
return span;
|
|
133
|
+
},
|
|
134
|
+
finish: () => {
|
|
135
|
+
span.end();
|
|
136
|
+
},
|
|
137
|
+
withContext: <T>(fn: () => T): T => contextApi.with(context, fn),
|
|
138
|
+
context: () => ({
|
|
139
|
+
toTraceId: () => spanContext.traceId,
|
|
140
|
+
toSpanId: () => spanContext.spanId,
|
|
141
|
+
}),
|
|
142
|
+
otelSpan: span,
|
|
143
|
+
otelContext: context,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function setSpanErrorStatus<TSpan extends OpenTelemetrySpan>(
|
|
148
|
+
span: TSpan,
|
|
149
|
+
errorStatusCode: number,
|
|
150
|
+
error: unknown,
|
|
151
|
+
): void {
|
|
152
|
+
span.setStatus({ code: errorStatusCode });
|
|
153
|
+
if (error instanceof Error) {
|
|
154
|
+
span.recordException(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function isPromise<T>(value: T | Promise<T>): value is Promise<T> {
|
|
159
|
+
return value instanceof Promise;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function createOpenTelemetryServiceTracer<
|
|
163
|
+
TContext,
|
|
164
|
+
TSpan extends OpenTelemetrySpan,
|
|
165
|
+
TSpanOptions,
|
|
166
|
+
>(
|
|
167
|
+
options: CreateOpenTelemetryServiceTracerOptions<TContext, TSpan, TSpanOptions>,
|
|
168
|
+
): OpenTelemetryServiceTracer<TContext, TSpan, TSpanOptions> {
|
|
169
|
+
const otelTracer = options.trace.getTracer(options.serviceName);
|
|
170
|
+
|
|
171
|
+
function wrap<TArgs extends unknown[], TResult>(
|
|
172
|
+
name: string,
|
|
173
|
+
fn: (...args: TArgs) => TResult,
|
|
174
|
+
): (...args: TArgs) => TResult {
|
|
175
|
+
return (...args: TArgs): TResult => {
|
|
176
|
+
const span = otelTracer.startSpan(name, undefined, options.context.active());
|
|
177
|
+
const contextWithSpan = options.trace.setSpan(options.context.active(), span);
|
|
178
|
+
try {
|
|
179
|
+
return options.context.with(contextWithSpan, () => fn(...args));
|
|
180
|
+
} catch (error) {
|
|
181
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
182
|
+
throw error;
|
|
183
|
+
} finally {
|
|
184
|
+
span.end();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function trace<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
190
|
+
function trace<T>(name: string, fn: () => T): T;
|
|
191
|
+
function trace<T>(name: string, fn: () => T | Promise<T>): T | Promise<T> {
|
|
192
|
+
return otelTracer.startActiveSpan(name, (span) => {
|
|
193
|
+
try {
|
|
194
|
+
const result = fn();
|
|
195
|
+
if (isPromise(result)) {
|
|
196
|
+
return result
|
|
197
|
+
.then((value) => {
|
|
198
|
+
span.end();
|
|
199
|
+
return value;
|
|
200
|
+
})
|
|
201
|
+
.catch((error) => {
|
|
202
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
203
|
+
span.end();
|
|
204
|
+
throw error;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
span.end();
|
|
208
|
+
return result;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
setSpanErrorStatus(span, options.errorStatusCode, error);
|
|
211
|
+
span.end();
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const tracer: ServiceTracer<TContext, TSpan, TSpanOptions> = {
|
|
218
|
+
init: () => {},
|
|
219
|
+
startSpan: (name, startOptions) => {
|
|
220
|
+
let parentContext = options.context.active();
|
|
221
|
+
|
|
222
|
+
if (startOptions?.childOf?.otelSpan) {
|
|
223
|
+
parentContext = options.trace.setSpan(
|
|
224
|
+
options.context.active(),
|
|
225
|
+
startOptions.childOf.otelSpan,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const span = otelTracer.startSpan(name, startOptions, parentContext);
|
|
230
|
+
const spanContext = options.trace.setSpan(parentContext, span);
|
|
231
|
+
return createTracerSpan(options.context, span, spanContext);
|
|
232
|
+
},
|
|
233
|
+
scope: () => ({
|
|
234
|
+
active: () => {
|
|
235
|
+
const activeContext = options.context.active();
|
|
236
|
+
const activeSpan = options.trace.getSpan(activeContext);
|
|
237
|
+
if (!activeSpan) return null;
|
|
238
|
+
|
|
239
|
+
return createTracerSpan(options.context, activeSpan, activeContext);
|
|
240
|
+
},
|
|
241
|
+
}),
|
|
242
|
+
wrap,
|
|
243
|
+
trace,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
tracer,
|
|
248
|
+
setActiveSpanAttributes(attributes) {
|
|
249
|
+
const activeSpan = tracer.scope().active();
|
|
250
|
+
if (!activeSpan) return;
|
|
251
|
+
|
|
252
|
+
activeSpan.setAttributes(attributes);
|
|
253
|
+
},
|
|
254
|
+
getTraceContext() {
|
|
255
|
+
const activeSpan = tracer.scope().active();
|
|
256
|
+
if (!activeSpan) {
|
|
257
|
+
return {};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const spanContext = activeSpan.otelSpan.spanContext();
|
|
261
|
+
return {
|
|
262
|
+
traceId: spanContext.traceId,
|
|
263
|
+
spanId: spanContext.spanId,
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|