-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtracing.js
More file actions
39 lines (35 loc) · 1.31 KB
/
tracing.js
File metadata and controls
39 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { SimpleSpanProcessor, ConsoleSpanExporter } = require("@opentelemetry/sdk-trace-base");
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
const { OTLPTraceExporter } = require("@opentelemetry/exporter-otlp-http");
const provider = new NodeTracerProvider();
// Send to the Baselime Otel Collector if you have an account
if (process.env.BASELIME_API_KEY) {
provider.addSpanProcessor(
new SimpleSpanProcessor(
new OTLPTraceExporter({
url: 'https://otel.baselime.io/',
headers: {
Authorization: process.env.BASELIME_API_KEY
}
})
)
);
} else {
// Otherwise, send to the console
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
}
provider.register();
registerInstrumentations({
instrumentations: [
getNodeAutoInstrumentations(),
new AwsLambdaInstrumentation({
requestHook: (span, { event, context }) => {
span.setAttribute('cloud.region', process.env.AWS_REGION);
},
disableAwsContextPropagation: true
})
],
});