@mark1russell7/otel-ts 0.3.1 → 0.5.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/README.md +22 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/context-processors.d.ts +48 -0
- package/dist/context-processors.d.ts.map +1 -0
- package/dist/context-processors.js +92 -0
- package/dist/context-processors.js.map +1 -0
- package/dist/context-propagator.d.ts +39 -0
- package/dist/context-propagator.d.ts.map +1 -0
- package/dist/context-propagator.js +88 -0
- package/dist/context-propagator.js.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +13 -0
- package/dist/init.js.map +1 -1
- package/dist/logs.d.ts.map +1 -1
- package/dist/logs.js +2 -0
- package/dist/logs.js.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +5 -2
- package/dist/metrics.js.map +1 -1
- package/dist/node-exporters.d.ts +40 -0
- package/dist/node-exporters.d.ts.map +1 -0
- package/dist/node-exporters.js +86 -0
- package/dist/node-exporters.js.map +1 -0
- package/dist/node.d.ts +28 -10
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +53 -12
- package/dist/node.js.map +1 -1
- package/dist/session-processors.d.ts.map +1 -1
- package/dist/session-processors.js +6 -19
- package/dist/session-processors.js.map +1 -1
- package/dist/tracing.d.ts.map +1 -1
- package/dist/tracing.js +7 -1
- package/dist/tracing.js.map +1 -1
- package/package.json +4 -1
- package/src/context-processors.ts +106 -0
- package/src/context-propagator.ts +96 -0
- package/src/init.ts +13 -0
- package/src/logs.ts +2 -0
- package/src/metrics.ts +5 -2
- package/src/node-exporters.ts +104 -0
- package/src/node.ts +77 -22
- package/src/session-processors.ts +6 -19
- package/src/tracing.ts +7 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The processors of the context keys (docs/CONTEXT-DESIGN.md, section 4).
|
|
3
|
+
*
|
|
4
|
+
* - Each span and each log record gets the value of each defined context key
|
|
5
|
+
* of its context, as an attribute.
|
|
6
|
+
* - A metric gets no attribute of a key with `cardinality: "high"`: one time
|
|
7
|
+
* series for each user id would fill the store.
|
|
8
|
+
*
|
|
9
|
+
* The `session.id` processors (session-processors.ts) are a case of the same
|
|
10
|
+
* two processors. Of the SDK packages, this file loads only sdk-metrics, which
|
|
11
|
+
* each entry that uses it loads already.
|
|
12
|
+
*/
|
|
13
|
+
import { type Context } from "@opentelemetry/api";
|
|
14
|
+
import type { LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
15
|
+
import { type AggregationSelector, type IAttributesProcessor, type ViewOptions } from "@opentelemetry/sdk-metrics";
|
|
16
|
+
import type { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
17
|
+
/** The attributes to add to a record that starts in the context `from` */
|
|
18
|
+
export type ContextAttributesReader = (from: Context) => Readonly<Record<string, string>>;
|
|
19
|
+
/** Sets the attributes of `read` on each span as it starts. An attribute that the caller set is kept. */
|
|
20
|
+
export declare function createAttributesSpanProcessor(read: ContextAttributesReader): SpanProcessor;
|
|
21
|
+
/** Sets the attributes of `read` on each log record as it is emitted. An attribute that the caller set is kept. */
|
|
22
|
+
export declare function createAttributesLogRecordProcessor(read: ContextAttributesReader): LogRecordProcessor;
|
|
23
|
+
/** Sets the value of each defined context key on each span */
|
|
24
|
+
export declare function createContextSpanProcessor(): SpanProcessor;
|
|
25
|
+
/** Sets the value of each defined context key on each log record */
|
|
26
|
+
export declare function createContextLogRecordProcessor(): LogRecordProcessor;
|
|
27
|
+
/**
|
|
28
|
+
* Removes each attribute of a defined key with `cardinality: "high"` from a
|
|
29
|
+
* measurement. It reads the rules at each measurement, so a key defined after
|
|
30
|
+
* the start of the meter provider is removed too.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createContextAttributesProcessor(): IAttributesProcessor;
|
|
33
|
+
/** The default aggregation of each instrument type, as the SDK's default reader */
|
|
34
|
+
export declare const defaultAggregation: AggregationSelector;
|
|
35
|
+
/**
|
|
36
|
+
* The views that remove the keys of high cardinality: one view for each
|
|
37
|
+
* instrument type, so each instrument matches one view.
|
|
38
|
+
*
|
|
39
|
+
* The aggregation of a view replaces the aggregation preference of each
|
|
40
|
+
* reader (sdk-metrics, `MeterSharedState`). So the views take the aggregation
|
|
41
|
+
* of each instrument type from `aggregation`: give the preference that the
|
|
42
|
+
* reader would have, for example base-2 exponential histograms.
|
|
43
|
+
*
|
|
44
|
+
* Give these as the only views of the meter provider: a second view that
|
|
45
|
+
* matches an instrument makes a second stream of it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function contextMetricViews(aggregation?: AggregationSelector): ViewOptions[];
|
|
48
|
+
//# sourceMappingURL=context-processors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-processors.d.ts","sourceRoot":"","sources":["../src/context-processors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,0EAA0E;AAC1E,MAAM,MAAM,uBAAuB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE1F,yGAAyG;AACzG,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,uBAAuB,GAAG,aAAa,CAW1F;AAED,mHAAmH;AACnH,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,uBAAuB,GAAG,kBAAkB,CAUpG;AAED,8DAA8D;AAC9D,wBAAgB,0BAA0B,IAAI,aAAa,CAE1D;AAED,oEAAoE;AACpE,wBAAgB,+BAA+B,IAAI,kBAAkB,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,IAAI,oBAAoB,CAYvE;AAED,mFAAmF;AACnF,eAAO,MAAM,kBAAkB,EAAE,mBAA+D,CAAC;AAEjG;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,mBAAwC,GAAG,WAAW,EAAE,CAOvG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The processors of the context keys (docs/CONTEXT-DESIGN.md, section 4).
|
|
3
|
+
*
|
|
4
|
+
* - Each span and each log record gets the value of each defined context key
|
|
5
|
+
* of its context, as an attribute.
|
|
6
|
+
* - A metric gets no attribute of a key with `cardinality: "high"`: one time
|
|
7
|
+
* series for each user id would fill the store.
|
|
8
|
+
*
|
|
9
|
+
* The `session.id` processors (session-processors.ts) are a case of the same
|
|
10
|
+
* two processors. Of the SDK packages, this file loads only sdk-metrics, which
|
|
11
|
+
* each entry that uses it loads already.
|
|
12
|
+
*/
|
|
13
|
+
import { context } from "@opentelemetry/api";
|
|
14
|
+
import { AggregationType, InstrumentType, } from "@opentelemetry/sdk-metrics";
|
|
15
|
+
import { contextKeyRule, contextValues } from "./context.js";
|
|
16
|
+
/** Sets the attributes of `read` on each span as it starts. An attribute that the caller set is kept. */
|
|
17
|
+
export function createAttributesSpanProcessor(read) {
|
|
18
|
+
return {
|
|
19
|
+
onStart(span, parentContext) {
|
|
20
|
+
for (const [key, value] of Object.entries(read(parentContext))) {
|
|
21
|
+
if (span.attributes[key] === undefined)
|
|
22
|
+
span.setAttribute(key, value);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
onEnd() { },
|
|
26
|
+
forceFlush: () => Promise.resolve(),
|
|
27
|
+
shutdown: () => Promise.resolve(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Sets the attributes of `read` on each log record as it is emitted. An attribute that the caller set is kept. */
|
|
31
|
+
export function createAttributesLogRecordProcessor(read) {
|
|
32
|
+
return {
|
|
33
|
+
onEmit(logRecord, from) {
|
|
34
|
+
for (const [key, value] of Object.entries(read(from ?? context.active()))) {
|
|
35
|
+
if (logRecord.attributes[key] === undefined)
|
|
36
|
+
logRecord.setAttribute(key, value);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
forceFlush: () => Promise.resolve(),
|
|
40
|
+
shutdown: () => Promise.resolve(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Sets the value of each defined context key on each span */
|
|
44
|
+
export function createContextSpanProcessor() {
|
|
45
|
+
return createAttributesSpanProcessor(contextValues);
|
|
46
|
+
}
|
|
47
|
+
/** Sets the value of each defined context key on each log record */
|
|
48
|
+
export function createContextLogRecordProcessor() {
|
|
49
|
+
return createAttributesLogRecordProcessor(contextValues);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Removes each attribute of a defined key with `cardinality: "high"` from a
|
|
53
|
+
* measurement. It reads the rules at each measurement, so a key defined after
|
|
54
|
+
* the start of the meter provider is removed too.
|
|
55
|
+
*/
|
|
56
|
+
export function createContextAttributesProcessor() {
|
|
57
|
+
return {
|
|
58
|
+
process(incoming) {
|
|
59
|
+
let result;
|
|
60
|
+
for (const key of Object.keys(incoming)) {
|
|
61
|
+
if (contextKeyRule(key)?.cardinality !== "high")
|
|
62
|
+
continue;
|
|
63
|
+
result ??= { ...incoming };
|
|
64
|
+
delete result[key];
|
|
65
|
+
}
|
|
66
|
+
return result ?? incoming;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The default aggregation of each instrument type, as the SDK's default reader */
|
|
71
|
+
export const defaultAggregation = () => ({ type: AggregationType.DEFAULT });
|
|
72
|
+
/**
|
|
73
|
+
* The views that remove the keys of high cardinality: one view for each
|
|
74
|
+
* instrument type, so each instrument matches one view.
|
|
75
|
+
*
|
|
76
|
+
* The aggregation of a view replaces the aggregation preference of each
|
|
77
|
+
* reader (sdk-metrics, `MeterSharedState`). So the views take the aggregation
|
|
78
|
+
* of each instrument type from `aggregation`: give the preference that the
|
|
79
|
+
* reader would have, for example base-2 exponential histograms.
|
|
80
|
+
*
|
|
81
|
+
* Give these as the only views of the meter provider: a second view that
|
|
82
|
+
* matches an instrument makes a second stream of it.
|
|
83
|
+
*/
|
|
84
|
+
export function contextMetricViews(aggregation = defaultAggregation) {
|
|
85
|
+
const processor = createContextAttributesProcessor();
|
|
86
|
+
return Object.values(InstrumentType).map((instrumentType) => ({
|
|
87
|
+
instrumentType,
|
|
88
|
+
attributesProcessors: [processor],
|
|
89
|
+
aggregation: aggregation(instrumentType),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=context-processors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-processors.js","sourceRoot":"","sources":["../src/context-processors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,OAAO,EAAiC,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EACL,eAAe,EACf,cAAc,GAIf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7D,yGAAyG;AACzG,MAAM,UAAU,6BAA6B,CAAC,IAA6B;IACzE,OAAO;QACL,OAAO,CAAC,IAAI,EAAE,aAAa;YACzB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;gBAC/D,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS;oBAAE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QACD,KAAK,KAAI,CAAC;QACV,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QACnC,QAAQ,EAAE,GAAG,E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AC;AAED,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAwB,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;AAEjG;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAAmC,kBAAkB;IACtF,MAAM,SAAS,GAAG,gCAAgC,EAAE,CAAC;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAC5D,cAAc;QACd,oBAAoB,EAAE,CAAC,SAAS,CAAC;QACjC,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC;KACzC,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The propagator of the one context (docs/CONTEXT-DESIGN.md, section 5), and
|
|
3
|
+
* the guard that lets only one part of a program register the context.
|
|
4
|
+
*
|
|
5
|
+
* - The W3C trace context (`traceparent`, `tracestate`) goes on each call. It
|
|
6
|
+
* holds only random ids.
|
|
7
|
+
* - The W3C baggage goes only on a call that starts in a context with the
|
|
8
|
+
* internal mark (`withInternalCall` of `/context`), and only with the keys
|
|
9
|
+
* that `defineContextKeys` defined with `propagate: "internal"`. A value
|
|
10
|
+
* longer than the `maxLength` of its key is dropped, not cut.
|
|
11
|
+
* - On extract, the baggage keeps only those keys too, so an entry from
|
|
12
|
+
* outside does not travel on. The W3C limits (180 entries, 8192 bytes) are
|
|
13
|
+
* the limits of the W3C baggage propagator of `@opentelemetry/core`.
|
|
14
|
+
*
|
|
15
|
+
* A server that does not trust its caller removes the extracted baggage with
|
|
16
|
+
* `propagation.deleteBaggage(context)`, and keeps the trace context.
|
|
17
|
+
*/
|
|
18
|
+
import { type Baggage, type Context, type TextMapGetter, type TextMapPropagator, type TextMapSetter } from "@opentelemetry/api";
|
|
19
|
+
/** The baggage with only the defined internal keys, each value in its maxLength; undefined when no entry stays */
|
|
20
|
+
export declare function allowedBaggage(baggage: Baggage): Baggage | undefined;
|
|
21
|
+
/** The W3C trace context on each call, and the allowed baggage on internal calls only */
|
|
22
|
+
export declare class ContextPropagator implements TextMapPropagator {
|
|
23
|
+
private readonly traceContext;
|
|
24
|
+
private readonly baggage;
|
|
25
|
+
inject(context: Context, carrier: unknown, setter: TextMapSetter): void;
|
|
26
|
+
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context;
|
|
27
|
+
fields(): string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Take the registration of the context for `caller` (for example "init()" or
|
|
31
|
+
* "startNodeTelemetry()"), and give the function that gives it back. A second
|
|
32
|
+
* registration while the first holds is an error that names the first caller.
|
|
33
|
+
* The OpenTelemetry API itself keeps the first registration and only writes a
|
|
34
|
+
* diagnostic message.
|
|
35
|
+
*/
|
|
36
|
+
export declare function claimContextRegistration(caller: string): () => void;
|
|
37
|
+
/** The caller that holds the registration of the context, or undefined */
|
|
38
|
+
export declare function contextRegistrationOwner(): string | undefined;
|
|
39
|
+
//# sourceMappingURL=context-propagator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-propagator.d.ts","sourceRoot":"","sources":["../src/context-propagator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAI5B,kHAAkH;AAClH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAOpE;AAED,yFAAyF;AACzF,qBAAa,iBAAkB,YAAW,iBAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IAEtD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI;IAQvE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO;IAQ3E,MAAM,IAAI,MAAM,EAAE;CAGnB;AAQD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,CAanE;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,IAAI,MAAM,GAAG,SAAS,CAE7D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The propagator of the one context (docs/CONTEXT-DESIGN.md, section 5), and
|
|
3
|
+
* the guard that lets only one part of a program register the context.
|
|
4
|
+
*
|
|
5
|
+
* - The W3C trace context (`traceparent`, `tracestate`) goes on each call. It
|
|
6
|
+
* holds only random ids.
|
|
7
|
+
* - The W3C baggage goes only on a call that starts in a context with the
|
|
8
|
+
* internal mark (`withInternalCall` of `/context`), and only with the keys
|
|
9
|
+
* that `defineContextKeys` defined with `propagate: "internal"`. A value
|
|
10
|
+
* longer than the `maxLength` of its key is dropped, not cut.
|
|
11
|
+
* - On extract, the baggage keeps only those keys too, so an entry from
|
|
12
|
+
* outside does not travel on. The W3C limits (180 entries, 8192 bytes) are
|
|
13
|
+
* the limits of the W3C baggage propagator of `@opentelemetry/core`.
|
|
14
|
+
*
|
|
15
|
+
* A server that does not trust its caller removes the extracted baggage with
|
|
16
|
+
* `propagation.deleteBaggage(context)`, and keeps the trace context.
|
|
17
|
+
*/
|
|
18
|
+
import { propagation, } from "@opentelemetry/api";
|
|
19
|
+
import { W3CBaggagePropagator, W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
20
|
+
import { contextKeyRule, isInternalCall } from "./context.js";
|
|
21
|
+
/** The baggage with only the defined internal keys, each value in its maxLength; undefined when no entry stays */
|
|
22
|
+
export function allowedBaggage(baggage) {
|
|
23
|
+
let kept = baggage;
|
|
24
|
+
for (const [key, entry] of baggage.getAllEntries()) {
|
|
25
|
+
const rule = contextKeyRule(key);
|
|
26
|
+
if (rule?.propagate !== "internal" || entry.value.length > rule.maxLength)
|
|
27
|
+
kept = kept.removeEntry(key);
|
|
28
|
+
}
|
|
29
|
+
return kept.getAllEntries().length > 0 ? kept : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** The W3C trace context on each call, and the allowed baggage on internal calls only */
|
|
32
|
+
export class ContextPropagator {
|
|
33
|
+
traceContext = new W3CTraceContextPropagator();
|
|
34
|
+
baggage = new W3CBaggagePropagator();
|
|
35
|
+
inject(context, carrier, setter) {
|
|
36
|
+
this.traceContext.inject(context, carrier, setter);
|
|
37
|
+
if (!isInternalCall(context))
|
|
38
|
+
return;
|
|
39
|
+
const baggage = propagation.getBaggage(context);
|
|
40
|
+
const allowed = baggage && allowedBaggage(baggage);
|
|
41
|
+
if (allowed)
|
|
42
|
+
this.baggage.inject(propagation.setBaggage(context, allowed), carrier, setter);
|
|
43
|
+
}
|
|
44
|
+
extract(context, carrier, getter) {
|
|
45
|
+
const next = this.baggage.extract(this.traceContext.extract(context, carrier, getter), carrier, getter);
|
|
46
|
+
const baggage = propagation.getBaggage(next);
|
|
47
|
+
if (!baggage)
|
|
48
|
+
return next;
|
|
49
|
+
const allowed = allowedBaggage(baggage);
|
|
50
|
+
return allowed ? propagation.setBaggage(next, allowed) : propagation.deleteBaggage(next);
|
|
51
|
+
}
|
|
52
|
+
fields() {
|
|
53
|
+
return [...this.traceContext.fields(), ...this.baggage.fields()];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/*
|
|
57
|
+
* The owner of the registration is on globalThis, so two copies of otel-ts in
|
|
58
|
+
* one program also refuse each other.
|
|
59
|
+
*/
|
|
60
|
+
const OWNER = Symbol.for("@mark1russell7/otel-ts/context owner");
|
|
61
|
+
/**
|
|
62
|
+
* Take the registration of the context for `caller` (for example "init()" or
|
|
63
|
+
* "startNodeTelemetry()"), and give the function that gives it back. A second
|
|
64
|
+
* registration while the first holds is an error that names the first caller.
|
|
65
|
+
* The OpenTelemetry API itself keeps the first registration and only writes a
|
|
66
|
+
* diagnostic message.
|
|
67
|
+
*/
|
|
68
|
+
export function claimContextRegistration(caller) {
|
|
69
|
+
const holder = globalThis;
|
|
70
|
+
const owner = holder[OWNER];
|
|
71
|
+
if (owner !== undefined) {
|
|
72
|
+
throw new Error(`The context is registered already by ${owner}. Only one part of a program registers it: call the shutdown() of ${owner} first.`);
|
|
73
|
+
}
|
|
74
|
+
holder[OWNER] = caller;
|
|
75
|
+
let released = false;
|
|
76
|
+
return () => {
|
|
77
|
+
if (released)
|
|
78
|
+
return;
|
|
79
|
+
released = true;
|
|
80
|
+
if (holder[OWNER] === caller)
|
|
81
|
+
delete holder[OWNER];
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** The caller that holds the registration of the context, or undefined */
|
|
85
|
+
export function contextRegistrationOwner() {
|
|
86
|
+
return globalThis[OWNER];
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=context-propagator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-propagator.js","sourceRoot":"","sources":["../src/context-propagator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,WAAW,GAMZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9D,kHAAkH;AAClH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,IAAI,IAAI,GAAG,OAAO,CAAC;IACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,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ources":["../src/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAc,YAAY,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AAO3F,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AA6D9B;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,CAAC,EAAE,YAAY,GACpB,cAAc,CA+GhB"}
|
package/dist/init.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { context, propagation, trace } from "@opentelemetry/api";
|
|
1
2
|
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
2
3
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
3
4
|
import { buildResource } from "./resource.js";
|
|
4
5
|
import { createSessionTracker } from "./session.js";
|
|
5
6
|
import { createInstanceId, randomUuid } from "./id.js";
|
|
6
7
|
import { setupTracing } from "./tracing.js";
|
|
8
|
+
import { claimContextRegistration } from "./context-propagator.js";
|
|
7
9
|
import { createContextManager, } from "./context-manager.js";
|
|
8
10
|
import { setupMetrics } from "./metrics.js";
|
|
9
11
|
import { setupLogs } from "./logs.js";
|
|
@@ -63,6 +65,11 @@ export function initWith(managers, config) {
|
|
|
63
65
|
const contextManager = resolved.tracing
|
|
64
66
|
? createContextManager(resolved.contextManager, managers)
|
|
65
67
|
: undefined;
|
|
68
|
+
// Tracing registers the globals of the context: only one part of a program
|
|
69
|
+
// does that. A second init() before the shutdown() of the first throws here.
|
|
70
|
+
const releaseRegistration = contextManager
|
|
71
|
+
? claimContextRegistration("init()")
|
|
72
|
+
: undefined;
|
|
66
73
|
// Read again for every log record and span, so they follow rotations
|
|
67
74
|
const getSessionId = createSessionIdReader(resolved.sessionTracking);
|
|
68
75
|
// Start or resume the session now: a page load counts as activity
|
|
@@ -105,6 +112,12 @@ export function initWith(managers, config) {
|
|
|
105
112
|
shutdownPromise ??= (async () => {
|
|
106
113
|
removeLifecycleHandlers();
|
|
107
114
|
await Promise.allSettled(providers.map((p) => p.shutdown()));
|
|
115
|
+
if (releaseRegistration) {
|
|
116
|
+
// Remove the globals of the context, so a next init() registers its own
|
|
117
|
+
for (const api of [trace, propagation, context])
|
|
118
|
+
api.disable();
|
|
119
|
+
releaseRegistration();
|
|
120
|
+
}
|
|
108
121
|
})();
|
|
109
122
|
}
|
|
110
123
|
return shutdownPromise;
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,kCAAkC,EAClC,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,SAAS,aAAa,CACp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oot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,cAAc,EAEf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAGjC,wBAAgB,SAAS,CACvB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,eAAe,GAC5B,cAAc,CAchB"}
|
package/dist/logs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LoggerProvider, BatchLogRecordProcessor, } from "@opentelemetry/sdk-logs";
|
|
2
2
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
3
3
|
import { createSessionLogRecordProcessor, } from "./session-processors.js";
|
|
4
|
+
import { createContextLogRecordProcessor } from "./context-processors.js";
|
|
4
5
|
export function setupLogs(resource, config, getSessionId) {
|
|
5
6
|
const exporter = new OTLPLogExporter({
|
|
6
7
|
url: `${config.endpoint}/v1/logs`,
|
|
@@ -10,6 +11,7 @@ export function setupLogs(resource, config, getSessionId) {
|
|
|
10
11
|
processors: [
|
|
11
12
|
// Before the exporting processor, so every exported record has it
|
|
12
13
|
createSessionLogRecordProcessor(getSessionId),
|
|
14
|
+
createContextLogRecordProcessor(),
|
|
13
15
|
new BatchLogRecordProcessor(exporter),
|
|
14
16
|
],
|
|
15
17
|
});
|
package/dist/logs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,OAAO,EACL,+BAA+B,GAEhC,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"logs.js","sourceRoot":"","sources":["../src/logs.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,OAAO,EACL,+BAA+B,GAEhC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,MAAM,UAAU,SAAS,CACvB,QAAkB,EAClB,MAAsB,EACtB,YAA6B;IAE7B,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC;QACnC,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,UAAU;KAClC,CAAC,CAAC;IAEH,OAAO,IAAI,cAAc,CAAC;QACxB,QAAQ;QACR,UAAU,EAAE;YACV,kEAAkE;YAClE,+BAA+B,CAAC,YAAY,CAAC;YAC7C,+BAA+B,EAAE;YACjC,IAAI,uBAAuB,CAAC,QAAQ,CAAC;SACtC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/metrics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAGL,aAAa,EAGd,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,YAAY,CAAC;AAyBrE,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,cAAc,GACrB,aAAa,CAuBf"}
|
package/dist/metrics.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { contextMetricViews } from "./context-processors.js";
|
|
1
2
|
import { AggregationType, InstrumentType, MeterProvider, PeriodicExportingMetricReader, } from "@opentelemetry/sdk-metrics";
|
|
2
3
|
import { AggregationTemporalityPreference, OTLPMetricExporter, } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
3
4
|
const TEMPORALITY_PREFERENCES = {
|
|
@@ -9,8 +10,8 @@ const TEMPORALITY_PREFERENCES = {
|
|
|
9
10
|
* instrument keeps its default aggregation. Used as the exporter's
|
|
10
11
|
* aggregation preference — the SDK's equivalent of
|
|
11
12
|
* OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION=base2_exponential_bucket_histogram —
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* The context views (contextMetricViews) replace the preference of the
|
|
14
|
+
* exporter, so they take the same selector.
|
|
14
15
|
*/
|
|
15
16
|
const selectExponentialHistograms = (instrumentType) => instrumentType === InstrumentType.HISTOGRAM
|
|
16
17
|
? { type: AggregationType.EXPONENTIAL_HISTOGRAM }
|
|
@@ -26,6 +27,8 @@ export function setupMetrics(resource, config) {
|
|
|
26
27
|
const exporter = new OTLPMetricExporter(options);
|
|
27
28
|
return new MeterProvider({
|
|
28
29
|
resource,
|
|
30
|
+
// Removes each context key of high cardinality from each metric
|
|
31
|
+
views: contextMetricViews(options.aggregationPreference),
|
|
29
32
|
readers: [
|
|
30
33
|
new PeriodicExportingMetricReader({
|
|
31
34
|
exporter,
|
package/dist/metrics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gCAAgC,EAChC,kBAAkB,GAEnB,MAAM,2CAA2C,CAAC;AAGnD,MAAM,uBAAuB,GAGzB;IACF,UAAU,EAAE,gCAAgC,CAAC,UAAU;IACvD,KAAK,EAAE,gCAAgC,CAAC,KAAK;CAC9C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAwB,CACvD,cAAc,EACd,EAAE,CACF,cAAc,KAAK,cAAc,CAAC,SAAS;IACzC,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,qBAAqB,EAAE;IACjD,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,OAAO,EAAE,CAAC;AAExC,MAAM,UAAU,YAAY,CAC1B,QAAkB,EAClB,MAAsB;IAEtB,MAAM,OAAO,GAA8B;QACzC,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,aAAa;QACpC,qBAAqB,EAAE,uBAAuB,CAAC,MAAM,CAAC,kBAAkB,CAAC;KAC1E,CAAC;IAEF,IAAI,MAAM,CAAC,oBAAoB,KAAK,aAAa,EAAE,CAAC;QAClD,OAAO,CAAC,qBAAqB,GAAG,2BAA2B,CAAC;IAC9D,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAEjD,OAAO,IAAI,aAAa,CAAC;QACvB,QAAQ;QACR,gEAAgE;QAChE,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACxD,OAAO,EAAE;YACP,IAAI,6BAA6B,CAAC;gBAChC,QAAQ;gBACR,oBAAoB,EAAE,MAAM,CAAC,uBAAuB;aACrD,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type LogRecordExporter, type LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import { type AggregationSelector } from "@opentelemetry/sdk-metrics";
|
|
3
|
+
import { type SpanExporter, type SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
4
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
5
|
+
/** A signal that has processors */
|
|
6
|
+
export type OtlpSignal = "traces" | "logs";
|
|
7
|
+
/** An exporter name of `OTEL_TRACES_EXPORTER` and `OTEL_LOGS_EXPORTER` that otel-ts makes */
|
|
8
|
+
export type ExporterName = "otlp" | "console";
|
|
9
|
+
/** An OTLP protocol that otel-ts sends */
|
|
10
|
+
export type OtlpProtocol = "http/protobuf" | "http/json";
|
|
11
|
+
/**
|
|
12
|
+
* The exporters of `OTEL_<SIGNAL>_EXPORTER`, a list with commas. Default:
|
|
13
|
+
* `otlp`. With `none` in the list: no exporter. Another name is an error.
|
|
14
|
+
*/
|
|
15
|
+
export declare function exporterNames(signal: OtlpSignal, env: Env): ExporterName[];
|
|
16
|
+
/**
|
|
17
|
+
* The protocol of `OTEL_EXPORTER_OTLP_<SIGNAL>_PROTOCOL`, else of
|
|
18
|
+
* `OTEL_EXPORTER_OTLP_PROTOCOL`. Default: `http/protobuf`, as the SDK.
|
|
19
|
+
*/
|
|
20
|
+
export declare function otlpProtocol(signal: OtlpSignal, env: Env): OtlpProtocol;
|
|
21
|
+
/**
|
|
22
|
+
* The aggregation of `OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION`:
|
|
23
|
+
* `explicit_bucket_histogram` (default) or `base2_exponential_bucket_histogram`.
|
|
24
|
+
* Another value is an error.
|
|
25
|
+
*/
|
|
26
|
+
export declare function histogramAggregation(env: Env): AggregationSelector;
|
|
27
|
+
/**
|
|
28
|
+
* The span processors: the context processor, then a processor for `exporter`,
|
|
29
|
+
* or for each exporter of the variables. No exporter gives no processor.
|
|
30
|
+
* An OTLP exporter reads its endpoint, headers and timeout from `process.env`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function nodeSpanProcessors(env: Env, exporter?: SpanExporter): SpanProcessor[];
|
|
33
|
+
/**
|
|
34
|
+
* The log record processors: the context processor, then a processor for
|
|
35
|
+
* `exporter`, or for each exporter of the variables. No exporter gives no processor.
|
|
36
|
+
* An OTLP exporter reads its endpoint, headers and timeout from `process.env`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function nodeLogRecordProcessors(env: Env, exporter?: LogRecordExporter): LogRecordProcessor[];
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=node-exporters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-exporters.d.ts","sourceRoot":"","sources":["../src/node-exporters.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAmC,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACvG,OAAO,EAAgE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGpJ,KAAK,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAExD,mCAAmC;AACnC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC3C,6FAA6F;AAC7F,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;AAC9C,0CAA0C;AAC1C,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,WAAW,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,YAAY,EAAE,CAS1E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,YAAY,CAKvE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,mBAAmB,CAQlE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,aAAa,EAAE,CASrF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,EAAE,CASpG"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The span and log processors of a Node service (docs/CONTEXT-DESIGN.md, section 4).
|
|
3
|
+
*
|
|
4
|
+
* The NodeSDK makes its processors from the `OTEL_*` variables, but it has no
|
|
5
|
+
* public way to add a processor to them. So otel-ts makes them: the context
|
|
6
|
+
* processor of C3 first, then one processor for each exporter that the
|
|
7
|
+
* variables name. The sampler and the metric readers stay those of the SDK.
|
|
8
|
+
*/
|
|
9
|
+
import { OTLPLogExporter as JsonLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
10
|
+
import { OTLPLogExporter as ProtobufLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
11
|
+
import { OTLPTraceExporter as JsonTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
12
|
+
import { OTLPTraceExporter as ProtobufTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
13
|
+
import { BatchLogRecordProcessor, ConsoleLogRecordExporter, SimpleLogRecordProcessor, } from "@opentelemetry/sdk-logs";
|
|
14
|
+
import { AggregationType, InstrumentType } from "@opentelemetry/sdk-metrics";
|
|
15
|
+
import { BatchSpanProcessor, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
16
|
+
import { createContextLogRecordProcessor, createContextSpanProcessor, defaultAggregation } from "./context-processors.js";
|
|
17
|
+
/**
|
|
18
|
+
* The exporters of `OTEL_<SIGNAL>_EXPORTER`, a list with commas. Default:
|
|
19
|
+
* `otlp`. With `none` in the list: no exporter. Another name is an error.
|
|
20
|
+
*/
|
|
21
|
+
export function exporterNames(signal, env) {
|
|
22
|
+
const variable = `OTEL_${signal.toUpperCase()}_EXPORTER`;
|
|
23
|
+
const names = [...new Set((env[variable] ?? "").split(",").map((name) => name.trim().toLowerCase()).filter(Boolean))];
|
|
24
|
+
if (names.length === 0)
|
|
25
|
+
return ["otlp"];
|
|
26
|
+
if (names.includes("none"))
|
|
27
|
+
return [];
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
if (name !== "otlp" && name !== "console")
|
|
30
|
+
throw new RangeError(`${variable} has "${name}": otel-ts makes "otlp", "console" or "none"`);
|
|
31
|
+
}
|
|
32
|
+
return names;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The protocol of `OTEL_EXPORTER_OTLP_<SIGNAL>_PROTOCOL`, else of
|
|
36
|
+
* `OTEL_EXPORTER_OTLP_PROTOCOL`. Default: `http/protobuf`, as the SDK.
|
|
37
|
+
*/
|
|
38
|
+
export function otlpProtocol(signal, env) {
|
|
39
|
+
const variable = `OTEL_EXPORTER_OTLP_${signal.toUpperCase()}_PROTOCOL`;
|
|
40
|
+
const value = (env[variable] ?? env["OTEL_EXPORTER_OTLP_PROTOCOL"] ?? "http/protobuf").trim();
|
|
41
|
+
if (value === "http/protobuf" || value === "http/json")
|
|
42
|
+
return value;
|
|
43
|
+
throw new RangeError(`the OTLP protocol of ${signal} is "${value}": otel-ts sends "http/protobuf" or "http/json". For grpc, give the exporter in the options.`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The aggregation of `OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION`:
|
|
47
|
+
* `explicit_bucket_histogram` (default) or `base2_exponential_bucket_histogram`.
|
|
48
|
+
* Another value is an error.
|
|
49
|
+
*/
|
|
50
|
+
export function histogramAggregation(env) {
|
|
51
|
+
const variable = "OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION";
|
|
52
|
+
const value = (env[variable] ?? "").trim().toLowerCase();
|
|
53
|
+
if (value === "" || value === "explicit_bucket_histogram")
|
|
54
|
+
return defaultAggregation;
|
|
55
|
+
if (value === "base2_exponential_bucket_histogram") {
|
|
56
|
+
return (type) => (type === InstrumentType.HISTOGRAM ? { type: AggregationType.EXPONENTIAL_HISTOGRAM } : { type: AggregationType.DEFAULT });
|
|
57
|
+
}
|
|
58
|
+
throw new RangeError(`${variable} has "${value}": otel-ts makes "explicit_bucket_histogram" or "base2_exponential_bucket_histogram"`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The span processors: the context processor, then a processor for `exporter`,
|
|
62
|
+
* or for each exporter of the variables. No exporter gives no processor.
|
|
63
|
+
* An OTLP exporter reads its endpoint, headers and timeout from `process.env`.
|
|
64
|
+
*/
|
|
65
|
+
export function nodeSpanProcessors(env, exporter) {
|
|
66
|
+
const exporting = exporter
|
|
67
|
+
? [new BatchSpanProcessor(exporter)]
|
|
68
|
+
: exporterNames("traces", env).map((name) => name === "console"
|
|
69
|
+
? new SimpleSpanProcessor(new ConsoleSpanExporter())
|
|
70
|
+
: new BatchSpanProcessor(otlpProtocol("traces", env) === "http/json" ? new JsonTraceExporter() : new ProtobufTraceExporter()));
|
|
71
|
+
return exporting.length > 0 ? [createContextSpanProcessor(), ...exporting] : [];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The log record processors: the context processor, then a processor for
|
|
75
|
+
* `exporter`, or for each exporter of the variables. No exporter gives no processor.
|
|
76
|
+
* An OTLP exporter reads its endpoint, headers and timeout from `process.env`.
|
|
77
|
+
*/
|
|
78
|
+
export function nodeLogRecordProcessors(env, exporter) {
|
|
79
|
+
const exporting = exporter
|
|
80
|
+
? [new BatchLogRecordProcessor(exporter)]
|
|
81
|
+
: exporterNames("logs", env).map((name) => name === "console"
|
|
82
|
+
? new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
|
|
83
|
+
: new BatchLogRecordProcessor(otlpProtocol("logs", env) === "http/json" ? new JsonLogExporter() : new ProtobufLogExporter()));
|
|
84
|
+
return exporting.length > 0 ? [createContextLogRecordProcessor(), ...exporting] : [];
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=node-exporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-exporters.js","sourceRoot":"","sources":["../src/node-exporters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,IAAI,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC5F,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AACjG,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AACjG,OAAO,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACtG,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,GAGzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,cAAc,EAA4B,MAAM,4BAA4B,CAAC;AACvG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAyC,MAAM,+BAA+B,CAAC;AACpJ,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAW1H;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,GAAQ;IACxD,MAAM,QAAQ,GAAG,QAAQ,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC;IACzD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC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