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,587 @@
|
|
|
1
|
+
import { TailSamplingSpanProcessor } from './chunk-X4RMFFMR.js';
|
|
2
|
+
import { __require } from './chunk-Z6ZWNWWR.js';
|
|
3
|
+
import { propagation, context } from '@opentelemetry/api';
|
|
4
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
5
|
+
import { BatchSpanProcessor, SimpleSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
6
|
+
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
7
|
+
import { ATTR_SERVICE_VERSION, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
8
|
+
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
|
9
|
+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
|
10
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
11
|
+
import { resolve } from 'node-env-resolver';
|
|
12
|
+
import { optional, string, url } from 'node-env-resolver/validators';
|
|
13
|
+
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
|
|
14
|
+
import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';
|
|
15
|
+
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
16
|
+
|
|
17
|
+
var BaggageSpanProcessor = class {
|
|
18
|
+
prefix;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.prefix = options.prefix ?? "baggage.";
|
|
21
|
+
}
|
|
22
|
+
onStart(span, parentContext) {
|
|
23
|
+
let baggage = propagation.getBaggage(parentContext);
|
|
24
|
+
if (!baggage) {
|
|
25
|
+
baggage = propagation.getBaggage(context.active());
|
|
26
|
+
}
|
|
27
|
+
if (!baggage) {
|
|
28
|
+
try {
|
|
29
|
+
const { getActiveContextWithBaggage } = __require("../trace-context");
|
|
30
|
+
const storedContext = getActiveContextWithBaggage();
|
|
31
|
+
baggage = propagation.getBaggage(storedContext);
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!baggage) return;
|
|
36
|
+
for (const [key, entry] of baggage.getAllEntries()) {
|
|
37
|
+
span.setAttribute(`${this.prefix}${key}`, entry.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
+
onEnd(_span) {
|
|
42
|
+
}
|
|
43
|
+
async shutdown() {
|
|
44
|
+
}
|
|
45
|
+
async forceFlush() {
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function resolveOtelEnv() {
|
|
49
|
+
return resolve({
|
|
50
|
+
OTEL_SERVICE_NAME: string({ optional: true }),
|
|
51
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: url({ optional: true }),
|
|
52
|
+
OTEL_EXPORTER_OTLP_HEADERS: string({ optional: true }),
|
|
53
|
+
OTEL_RESOURCE_ATTRIBUTES: string({ optional: true }),
|
|
54
|
+
OTEL_EXPORTER_OTLP_PROTOCOL: optional(["http", "grpc"])
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function parseResourceAttributes(input) {
|
|
58
|
+
if (!input || input.trim() === "") {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
const attributes = {};
|
|
62
|
+
const pairs = input.split(",");
|
|
63
|
+
for (const pair of pairs) {
|
|
64
|
+
const trimmedPair = pair.trim();
|
|
65
|
+
if (!trimmedPair) continue;
|
|
66
|
+
const equalIndex = trimmedPair.indexOf("=");
|
|
67
|
+
if (equalIndex === -1) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const key = trimmedPair.slice(0, equalIndex).trim();
|
|
71
|
+
const value = trimmedPair.slice(equalIndex + 1).trim();
|
|
72
|
+
if (key && value) {
|
|
73
|
+
attributes[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return attributes;
|
|
77
|
+
}
|
|
78
|
+
function parseOtlpHeaders(input) {
|
|
79
|
+
if (!input || input.trim() === "") {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
const headers = {};
|
|
83
|
+
const pairs = input.split(",");
|
|
84
|
+
for (const pair of pairs) {
|
|
85
|
+
const trimmedPair = pair.trim();
|
|
86
|
+
if (!trimmedPair) continue;
|
|
87
|
+
const equalIndex = trimmedPair.indexOf("=");
|
|
88
|
+
if (equalIndex === -1) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const key = trimmedPair.slice(0, equalIndex).trim();
|
|
92
|
+
const value = trimmedPair.slice(equalIndex + 1).trim();
|
|
93
|
+
if (key && value) {
|
|
94
|
+
headers[key] = value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return headers;
|
|
98
|
+
}
|
|
99
|
+
function envToConfig(env) {
|
|
100
|
+
const config2 = {};
|
|
101
|
+
if (env.OTEL_SERVICE_NAME) {
|
|
102
|
+
config2.service = env.OTEL_SERVICE_NAME;
|
|
103
|
+
}
|
|
104
|
+
if (env.OTEL_EXPORTER_OTLP_ENDPOINT) {
|
|
105
|
+
config2.endpoint = env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
106
|
+
}
|
|
107
|
+
if (env.OTEL_EXPORTER_OTLP_PROTOCOL) {
|
|
108
|
+
config2.protocol = env.OTEL_EXPORTER_OTLP_PROTOCOL;
|
|
109
|
+
}
|
|
110
|
+
if (env.OTEL_EXPORTER_OTLP_HEADERS) {
|
|
111
|
+
config2.otlpHeaders = parseOtlpHeaders(env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
112
|
+
}
|
|
113
|
+
const resourceAttrs = parseResourceAttributes(env.OTEL_RESOURCE_ATTRIBUTES);
|
|
114
|
+
if (Object.keys(resourceAttrs).length > 0) {
|
|
115
|
+
config2.resourceAttributes = resourceAttrs;
|
|
116
|
+
}
|
|
117
|
+
return config2;
|
|
118
|
+
}
|
|
119
|
+
function resolveConfigFromEnv() {
|
|
120
|
+
const env = resolveOtelEnv();
|
|
121
|
+
return envToConfig(env);
|
|
122
|
+
}
|
|
123
|
+
var OTLPTraceExporterGRPC;
|
|
124
|
+
var OTLPMetricExporterGRPC;
|
|
125
|
+
function loadGRPCTraceExporter() {
|
|
126
|
+
if (OTLPTraceExporterGRPC) return OTLPTraceExporterGRPC;
|
|
127
|
+
try {
|
|
128
|
+
const grpcModule = __require("@opentelemetry/exporter-trace-otlp-grpc");
|
|
129
|
+
OTLPTraceExporterGRPC = grpcModule.OTLPTraceExporter;
|
|
130
|
+
return OTLPTraceExporterGRPC;
|
|
131
|
+
} catch {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"gRPC trace exporter not found. Install with: pnpm add @opentelemetry/exporter-trace-otlp-grpc"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function loadGRPCMetricExporter() {
|
|
138
|
+
if (OTLPMetricExporterGRPC) return OTLPMetricExporterGRPC;
|
|
139
|
+
try {
|
|
140
|
+
const grpcModule = __require("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
141
|
+
OTLPMetricExporterGRPC = grpcModule.OTLPMetricExporter;
|
|
142
|
+
return OTLPMetricExporterGRPC;
|
|
143
|
+
} catch {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"gRPC metric exporter not found. Install with: pnpm add @opentelemetry/exporter-metrics-otlp-grpc"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function createTraceExporter(protocol, config2) {
|
|
150
|
+
if (protocol === "grpc") {
|
|
151
|
+
const Exporter = loadGRPCTraceExporter();
|
|
152
|
+
return new Exporter(config2);
|
|
153
|
+
}
|
|
154
|
+
return new OTLPTraceExporter(config2);
|
|
155
|
+
}
|
|
156
|
+
function createMetricExporter(protocol, config2) {
|
|
157
|
+
if (protocol === "grpc") {
|
|
158
|
+
const Exporter = loadGRPCMetricExporter();
|
|
159
|
+
return new Exporter(config2);
|
|
160
|
+
}
|
|
161
|
+
return new OTLPMetricExporter(config2);
|
|
162
|
+
}
|
|
163
|
+
function resolveProtocol(configProtocol) {
|
|
164
|
+
if (configProtocol === "grpc" || configProtocol === "http") {
|
|
165
|
+
return configProtocol;
|
|
166
|
+
}
|
|
167
|
+
const envProtocol = process.env.OTEL_EXPORTER_OTLP_PROTOCOL;
|
|
168
|
+
if (envProtocol === "grpc") return "grpc";
|
|
169
|
+
if (envProtocol === "http/protobuf" || envProtocol === "http") return "http";
|
|
170
|
+
return "http";
|
|
171
|
+
}
|
|
172
|
+
function formatEndpointUrl(endpoint, signal, protocol) {
|
|
173
|
+
if (protocol === "grpc") {
|
|
174
|
+
return endpoint.replace(/\/(v1\/)?(traces|metrics|logs)$/, "");
|
|
175
|
+
}
|
|
176
|
+
if (!endpoint.endsWith(`/v1/${signal}`)) {
|
|
177
|
+
return `${endpoint}/v1/${signal}`;
|
|
178
|
+
}
|
|
179
|
+
return endpoint;
|
|
180
|
+
}
|
|
181
|
+
var silentLogger = {
|
|
182
|
+
info: () => {
|
|
183
|
+
},
|
|
184
|
+
warn: () => {
|
|
185
|
+
},
|
|
186
|
+
error: () => {
|
|
187
|
+
},
|
|
188
|
+
debug: () => {
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var initialized = false;
|
|
192
|
+
var config = null;
|
|
193
|
+
var sdk = null;
|
|
194
|
+
var warnedOnce = false;
|
|
195
|
+
var logger = silentLogger;
|
|
196
|
+
var validationConfig = null;
|
|
197
|
+
function resolveMetricsFlag(configFlag = "auto") {
|
|
198
|
+
const envFlag = process.env.AUTOTELEMETRY_METRICS;
|
|
199
|
+
if (envFlag === "on" || envFlag === "true") return true;
|
|
200
|
+
if (envFlag === "off" || envFlag === "false") return false;
|
|
201
|
+
if (configFlag === true) return true;
|
|
202
|
+
if (configFlag === false) return false;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
function resolveDebugFlag(configFlag) {
|
|
206
|
+
const envFlag = process.env.AUTOLEMETRY_DEBUG;
|
|
207
|
+
if (envFlag === "true" || envFlag === "1") return true;
|
|
208
|
+
if (envFlag === "false" || envFlag === "0") return false;
|
|
209
|
+
return configFlag ?? false;
|
|
210
|
+
}
|
|
211
|
+
function normalizeOtlpHeaders(headers) {
|
|
212
|
+
if (!headers) return void 0;
|
|
213
|
+
if (typeof headers !== "string") return headers;
|
|
214
|
+
const parsed = {};
|
|
215
|
+
for (const pair of headers.split(",")) {
|
|
216
|
+
const [key, ...valueParts] = pair.split("=");
|
|
217
|
+
if (!key || valueParts.length === 0) continue;
|
|
218
|
+
parsed[key.trim()] = valueParts.join("=").trim();
|
|
219
|
+
}
|
|
220
|
+
return parsed;
|
|
221
|
+
}
|
|
222
|
+
function createLoggerInstrumentation(logger2) {
|
|
223
|
+
if ("child" in logger2 && "bindings" in logger2 && typeof logger2.child === "function") {
|
|
224
|
+
return new PinoInstrumentation();
|
|
225
|
+
}
|
|
226
|
+
if ("transports" in logger2 || "defaultMeta" in logger2) {
|
|
227
|
+
return new WinstonInstrumentation();
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
function init(cfg) {
|
|
232
|
+
const envConfig = resolveConfigFromEnv();
|
|
233
|
+
const mergedConfig = {
|
|
234
|
+
...envConfig,
|
|
235
|
+
...cfg,
|
|
236
|
+
// Deep merge for resourceAttributes
|
|
237
|
+
resourceAttributes: {
|
|
238
|
+
...envConfig.resourceAttributes,
|
|
239
|
+
...cfg.resourceAttributes
|
|
240
|
+
},
|
|
241
|
+
// Handle otlpHeaders merge (can be string or object)
|
|
242
|
+
otlpHeaders: cfg.otlpHeaders === void 0 ? envConfig.otlpHeaders === void 0 ? void 0 : envConfig.otlpHeaders : cfg.otlpHeaders
|
|
243
|
+
};
|
|
244
|
+
logger = mergedConfig.logger || silentLogger;
|
|
245
|
+
if (initialized) {
|
|
246
|
+
logger.warn(
|
|
247
|
+
"[autotel] init() called again - last config wins. This may cause unexpected behavior."
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
config = mergedConfig;
|
|
251
|
+
validationConfig = mergedConfig.validation || null;
|
|
252
|
+
const endpoint = mergedConfig.endpoint;
|
|
253
|
+
const otlpHeaders = normalizeOtlpHeaders(mergedConfig.otlpHeaders);
|
|
254
|
+
const version = mergedConfig.version || detectVersion();
|
|
255
|
+
const environment = mergedConfig.environment || process.env.NODE_ENV || "development";
|
|
256
|
+
const metricsEnabled = resolveMetricsFlag(mergedConfig.metrics);
|
|
257
|
+
const hostname = detectHostname();
|
|
258
|
+
let resource = resourceFromAttributes({
|
|
259
|
+
[ATTR_SERVICE_NAME]: cfg.service,
|
|
260
|
+
[ATTR_SERVICE_VERSION]: version,
|
|
261
|
+
// Support both old and new OpenTelemetry semantic conventions for environment
|
|
262
|
+
"deployment.environment": environment,
|
|
263
|
+
// Deprecated but widely supported
|
|
264
|
+
"deployment.environment.name": environment
|
|
265
|
+
// OTel v1.27.0+ standard
|
|
266
|
+
});
|
|
267
|
+
if (hostname) {
|
|
268
|
+
resource = resource.merge(
|
|
269
|
+
resourceFromAttributes({
|
|
270
|
+
"host.name": hostname,
|
|
271
|
+
// OpenTelemetry standard
|
|
272
|
+
"datadog.host.name": hostname
|
|
273
|
+
// Datadog-specific, highest priority for Datadog
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
if (cfg.resource) {
|
|
278
|
+
resource = resource.merge(cfg.resource);
|
|
279
|
+
}
|
|
280
|
+
if (cfg.resourceAttributes) {
|
|
281
|
+
resource = resource.merge(resourceFromAttributes(cfg.resourceAttributes));
|
|
282
|
+
}
|
|
283
|
+
const protocol = resolveProtocol(cfg.protocol);
|
|
284
|
+
const spanProcessors = [];
|
|
285
|
+
if (cfg.spanProcessors && cfg.spanProcessors.length > 0) {
|
|
286
|
+
spanProcessors.push(...cfg.spanProcessors);
|
|
287
|
+
} else if (cfg.spanExporters && cfg.spanExporters.length > 0) {
|
|
288
|
+
for (const exporter of cfg.spanExporters) {
|
|
289
|
+
spanProcessors.push(
|
|
290
|
+
new TailSamplingSpanProcessor(new BatchSpanProcessor(exporter))
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
} else if (endpoint) {
|
|
294
|
+
const traceExporter = createTraceExporter(protocol, {
|
|
295
|
+
url: formatEndpointUrl(endpoint, "traces", protocol),
|
|
296
|
+
headers: otlpHeaders
|
|
297
|
+
});
|
|
298
|
+
spanProcessors.push(
|
|
299
|
+
new TailSamplingSpanProcessor(new BatchSpanProcessor(traceExporter))
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (cfg.baggage) {
|
|
303
|
+
const prefix = typeof cfg.baggage === "string" ? cfg.baggage ? `${cfg.baggage}.` : "" : "baggage.";
|
|
304
|
+
spanProcessors.push(new BaggageSpanProcessor({ prefix }));
|
|
305
|
+
}
|
|
306
|
+
const debugMode = resolveDebugFlag(cfg.debug);
|
|
307
|
+
if (debugMode) {
|
|
308
|
+
spanProcessors.push(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
|
309
|
+
}
|
|
310
|
+
const metricReaders = [];
|
|
311
|
+
if (cfg.metricReaders && cfg.metricReaders.length > 0) {
|
|
312
|
+
metricReaders.push(...cfg.metricReaders);
|
|
313
|
+
} else if (metricsEnabled && endpoint) {
|
|
314
|
+
const metricExporter = createMetricExporter(protocol, {
|
|
315
|
+
url: formatEndpointUrl(endpoint, "metrics", protocol),
|
|
316
|
+
headers: otlpHeaders
|
|
317
|
+
});
|
|
318
|
+
metricReaders.push(
|
|
319
|
+
new PeriodicExportingMetricReader({
|
|
320
|
+
exporter: metricExporter
|
|
321
|
+
})
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
let logRecordProcessors;
|
|
325
|
+
if (cfg.logRecordProcessors && cfg.logRecordProcessors.length > 0) {
|
|
326
|
+
logRecordProcessors = [...cfg.logRecordProcessors];
|
|
327
|
+
}
|
|
328
|
+
let finalInstrumentations = cfg.instrumentations ? [...cfg.instrumentations] : [];
|
|
329
|
+
if (cfg.logger) {
|
|
330
|
+
const loggerInstrumentation = createLoggerInstrumentation(cfg.logger);
|
|
331
|
+
if (loggerInstrumentation) {
|
|
332
|
+
finalInstrumentations = [...finalInstrumentations, loggerInstrumentation];
|
|
333
|
+
logger.debug(
|
|
334
|
+
`[autotel] Auto-enabled ${loggerInstrumentation.constructor.name} for logger`
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (cfg.integrations !== void 0) {
|
|
339
|
+
try {
|
|
340
|
+
const manualInstrumentationNames = getInstrumentationNames(
|
|
341
|
+
cfg.instrumentations ?? []
|
|
342
|
+
);
|
|
343
|
+
if (manualInstrumentationNames.size > 0 && cfg.integrations !== false && cfg.integrations !== void 0) {
|
|
344
|
+
const manualNames = [...manualInstrumentationNames].join(", ");
|
|
345
|
+
logger.info(
|
|
346
|
+
`[autotel] Detected manual instrumentations (${manualNames}). These will take precedence over auto-instrumentations. Tip: Set integrations:false if you want full manual control, or remove manual configs to use auto-instrumentations.`
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const autoInstrumentations = getAutoInstrumentations(
|
|
350
|
+
cfg.integrations,
|
|
351
|
+
manualInstrumentationNames
|
|
352
|
+
);
|
|
353
|
+
if (autoInstrumentations && autoInstrumentations.length > 0) {
|
|
354
|
+
finalInstrumentations = [
|
|
355
|
+
...finalInstrumentations,
|
|
356
|
+
...autoInstrumentations
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
} catch (error) {
|
|
360
|
+
logger.warn(
|
|
361
|
+
`[autotel] Failed to configure auto-instrumentations: ${error instanceof Error ? error.message : String(error)}`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const sdkOptions = {
|
|
366
|
+
resource,
|
|
367
|
+
instrumentations: finalInstrumentations
|
|
368
|
+
};
|
|
369
|
+
if (spanProcessors.length > 0) {
|
|
370
|
+
sdkOptions.spanProcessors = spanProcessors;
|
|
371
|
+
}
|
|
372
|
+
if (metricReaders.length > 0) {
|
|
373
|
+
sdkOptions.metricReaders = metricReaders;
|
|
374
|
+
}
|
|
375
|
+
if (logRecordProcessors && logRecordProcessors.length > 0) {
|
|
376
|
+
sdkOptions.logRecordProcessors = logRecordProcessors;
|
|
377
|
+
}
|
|
378
|
+
sdk = cfg.sdkFactory ? cfg.sdkFactory(sdkOptions) : new NodeSDK(sdkOptions);
|
|
379
|
+
if (!sdk) {
|
|
380
|
+
throw new Error("[autotel] sdkFactory must return a NodeSDK instance");
|
|
381
|
+
}
|
|
382
|
+
sdk.start();
|
|
383
|
+
if (cfg.openllmetry?.enabled) {
|
|
384
|
+
let initializedSync = false;
|
|
385
|
+
try {
|
|
386
|
+
const traceloop = __require("@traceloop/node-server-sdk");
|
|
387
|
+
const initOptions = {
|
|
388
|
+
...cfg.openllmetry.options
|
|
389
|
+
};
|
|
390
|
+
try {
|
|
391
|
+
const tracerProvider = sdk.getTracerProvider();
|
|
392
|
+
initOptions.tracerProvider = tracerProvider;
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
if (typeof traceloop.initialize === "function") {
|
|
396
|
+
traceloop.initialize(initOptions);
|
|
397
|
+
logger.info("[autotel] OpenLLMetry initialized successfully");
|
|
398
|
+
initializedSync = true;
|
|
399
|
+
}
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (error instanceof Error && (error.message.includes("Cannot find module") || error.message.includes("Module not found") || error.message.includes("Cannot resolve module") || error.message.includes("Dynamic require"))) {
|
|
402
|
+
initializeOpenLLMetry(
|
|
403
|
+
cfg.openllmetry.options,
|
|
404
|
+
sdk,
|
|
405
|
+
cfg.spanExporters?.[0]
|
|
406
|
+
// Pass first exporter if available
|
|
407
|
+
).catch((error_) => {
|
|
408
|
+
logger.warn(
|
|
409
|
+
`[autotel] OpenLLMetry initialization error: ${error_ instanceof Error ? error_.message : String(error_)}`
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
} else if (!initializedSync) {
|
|
413
|
+
logger.warn(
|
|
414
|
+
`[autotel] Failed to initialize OpenLLMetry: ${error instanceof Error ? error.message : String(error)}`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
initialized = true;
|
|
420
|
+
}
|
|
421
|
+
async function initializeOpenLLMetry(options, sdkInstance, spanExporter) {
|
|
422
|
+
try {
|
|
423
|
+
let traceloop;
|
|
424
|
+
try {
|
|
425
|
+
traceloop = __require("@traceloop/node-server-sdk");
|
|
426
|
+
} catch {
|
|
427
|
+
traceloop = await import('@traceloop/node-server-sdk');
|
|
428
|
+
}
|
|
429
|
+
const initOptions = {
|
|
430
|
+
...options
|
|
431
|
+
};
|
|
432
|
+
if (spanExporter) {
|
|
433
|
+
initOptions.exporter = spanExporter;
|
|
434
|
+
}
|
|
435
|
+
if (sdkInstance) {
|
|
436
|
+
try {
|
|
437
|
+
const tracerProvider = sdkInstance.getTracerProvider();
|
|
438
|
+
initOptions.tracerProvider = tracerProvider;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
logger.debug(
|
|
441
|
+
`[autotel] Could not get tracer provider for OpenLLMetry: ${error instanceof Error ? error.message : String(error)}`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (typeof traceloop.initialize === "function") {
|
|
446
|
+
traceloop.initialize(initOptions);
|
|
447
|
+
logger.info("[autotel] OpenLLMetry initialized successfully");
|
|
448
|
+
} else {
|
|
449
|
+
logger.warn(
|
|
450
|
+
"[autotel] OpenLLMetry initialize function not found. Check @traceloop/node-server-sdk version."
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (error instanceof Error && (error.message.includes("Cannot find module") || error.message.includes("Module not found") || error.message.includes("Cannot resolve module"))) {
|
|
455
|
+
logger.warn(
|
|
456
|
+
"[autotel] OpenLLMetry enabled but @traceloop/node-server-sdk is not installed. Install it as a peer dependency to use OpenLLMetry integration."
|
|
457
|
+
);
|
|
458
|
+
} else {
|
|
459
|
+
logger.warn(
|
|
460
|
+
`[autotel] Failed to initialize OpenLLMetry: ${error instanceof Error ? error.message : String(error)}`
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function getInstrumentationNames(instrumentations) {
|
|
466
|
+
const names = /* @__PURE__ */ new Set();
|
|
467
|
+
if (!instrumentations) return names;
|
|
468
|
+
for (const instrumentation of instrumentations) {
|
|
469
|
+
if (instrumentation && typeof instrumentation === "object") {
|
|
470
|
+
names.add(instrumentation.constructor.name);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return names;
|
|
474
|
+
}
|
|
475
|
+
var INSTRUMENTATION_CLASS_TO_PACKAGE = {
|
|
476
|
+
HttpInstrumentation: "@opentelemetry/instrumentation-http",
|
|
477
|
+
HttpsInstrumentation: "@opentelemetry/instrumentation-http",
|
|
478
|
+
ExpressInstrumentation: "@opentelemetry/instrumentation-express",
|
|
479
|
+
FastifyInstrumentation: "@opentelemetry/instrumentation-fastify",
|
|
480
|
+
MongoDBInstrumentation: "@opentelemetry/instrumentation-mongodb",
|
|
481
|
+
MongooseInstrumentation: "@opentelemetry/instrumentation-mongoose",
|
|
482
|
+
PrismaInstrumentation: "@opentelemetry/instrumentation-prisma",
|
|
483
|
+
PinoInstrumentation: "@opentelemetry/instrumentation-pino",
|
|
484
|
+
WinstonInstrumentation: "@opentelemetry/instrumentation-winston",
|
|
485
|
+
RedisInstrumentation: "@opentelemetry/instrumentation-redis",
|
|
486
|
+
GraphQLInstrumentation: "@opentelemetry/instrumentation-graphql",
|
|
487
|
+
GrpcInstrumentation: "@opentelemetry/instrumentation-grpc",
|
|
488
|
+
IORedisInstrumentation: "@opentelemetry/instrumentation-ioredis",
|
|
489
|
+
KnexInstrumentation: "@opentelemetry/instrumentation-knex",
|
|
490
|
+
NestJsInstrumentation: "@opentelemetry/instrumentation-nestjs-core",
|
|
491
|
+
PgInstrumentation: "@opentelemetry/instrumentation-pg",
|
|
492
|
+
MySQLInstrumentation: "@opentelemetry/instrumentation-mysql",
|
|
493
|
+
MySQL2Instrumentation: "@opentelemetry/instrumentation-mysql2"
|
|
494
|
+
};
|
|
495
|
+
function getAutoInstrumentations(integrations, manualInstrumentationNames = /* @__PURE__ */ new Set()) {
|
|
496
|
+
if (integrations === false) {
|
|
497
|
+
return [];
|
|
498
|
+
}
|
|
499
|
+
const exclusionConfig = {};
|
|
500
|
+
for (const className of manualInstrumentationNames) {
|
|
501
|
+
const packageName = INSTRUMENTATION_CLASS_TO_PACKAGE[className];
|
|
502
|
+
if (packageName) {
|
|
503
|
+
exclusionConfig[packageName] = { enabled: false };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (integrations === true) {
|
|
507
|
+
if (Object.keys(exclusionConfig).length > 0) {
|
|
508
|
+
return getNodeAutoInstrumentations(exclusionConfig);
|
|
509
|
+
}
|
|
510
|
+
return getNodeAutoInstrumentations();
|
|
511
|
+
}
|
|
512
|
+
if (Array.isArray(integrations)) {
|
|
513
|
+
const config3 = { ...exclusionConfig };
|
|
514
|
+
for (const name of integrations) {
|
|
515
|
+
const packageName = `@opentelemetry/instrumentation-${name}`;
|
|
516
|
+
if (!exclusionConfig[packageName]) {
|
|
517
|
+
config3[packageName] = { enabled: true };
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return getNodeAutoInstrumentations(config3);
|
|
521
|
+
}
|
|
522
|
+
const config2 = {
|
|
523
|
+
...exclusionConfig,
|
|
524
|
+
...integrations
|
|
525
|
+
};
|
|
526
|
+
for (const packageName of Object.keys(exclusionConfig)) {
|
|
527
|
+
const integrationsKey = Object.keys(integrations).find(
|
|
528
|
+
(key) => packageName.includes(key)
|
|
529
|
+
);
|
|
530
|
+
if (integrationsKey) {
|
|
531
|
+
config2[packageName] = { enabled: false };
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return getNodeAutoInstrumentations(config2);
|
|
535
|
+
}
|
|
536
|
+
function isInitialized() {
|
|
537
|
+
return initialized;
|
|
538
|
+
}
|
|
539
|
+
function getConfig() {
|
|
540
|
+
return config;
|
|
541
|
+
}
|
|
542
|
+
function getLogger() {
|
|
543
|
+
return logger;
|
|
544
|
+
}
|
|
545
|
+
function getValidationConfig() {
|
|
546
|
+
return validationConfig;
|
|
547
|
+
}
|
|
548
|
+
function warnIfNotInitialized(context) {
|
|
549
|
+
if (!initialized && !warnedOnce) {
|
|
550
|
+
logger.warn(
|
|
551
|
+
`[autotel] ${context} used before init() called. Call init({ service: "..." }) first. See: https://docs.autotel.dev/quickstart`
|
|
552
|
+
);
|
|
553
|
+
warnedOnce = true;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function detectVersion() {
|
|
557
|
+
try {
|
|
558
|
+
const fs = __require("fs");
|
|
559
|
+
const pkg = JSON.parse(
|
|
560
|
+
fs.readFileSync(`${process.cwd()}/package.json`, "utf8")
|
|
561
|
+
);
|
|
562
|
+
return pkg.version || "1.0.0";
|
|
563
|
+
} catch {
|
|
564
|
+
return "1.0.0";
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function detectHostname() {
|
|
568
|
+
if (process.env.DD_HOSTNAME) {
|
|
569
|
+
return process.env.DD_HOSTNAME;
|
|
570
|
+
}
|
|
571
|
+
if (process.env.HOSTNAME) {
|
|
572
|
+
return process.env.HOSTNAME;
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
const os = __require("os");
|
|
576
|
+
return os.hostname();
|
|
577
|
+
} catch {
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function getSdk() {
|
|
582
|
+
return sdk;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export { BaggageSpanProcessor, getConfig, getLogger, getSdk, getValidationConfig, init, isInitialized, warnIfNotInitialized };
|
|
586
|
+
//# sourceMappingURL=chunk-3HENGDW2.js.map
|
|
587
|
+
//# sourceMappingURL=chunk-3HENGDW2.js.map
|