-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-telemetry.ts
42 lines (38 loc) · 1.59 KB
/
open-telemetry.ts
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
40
41
42
// Import required symbols
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/node";
import {
SimpleSpanProcessor,
ConsoleSpanExporter,
} from "@opentelemetry/tracing";
import { Resource } from "@opentelemetry/resources";
import { GraphQLInstrumentation } from "@opentelemetry/instrumentation-graphql";
import { CollectorTraceExporter } from "@opentelemetry/exporter-collector";
import { AwsLambdaInstrumentation } from "@opentelemetry/instrumentation-aws-lambda";
// Register server-related instrumentation
registerInstrumentations({
instrumentations: [
new HttpInstrumentation(),
new ExpressInstrumentation() as any, // Gives type error without the "as any"
new GraphQLInstrumentation(),
new AwsLambdaInstrumentation(),
],
});
// Initialize provider and identify this particular service
// (in this case, we're implementing a federated gateway)
export const provider = new NodeTracerProvider({
resource: Resource.default().merge(
new Resource({
// Replace with any string to identify this service in your system
"service.name": "demo",
})
),
});
// Configure a test exporter to print all traces to the console
const consoleExporter = new ConsoleSpanExporter();
export const consoleProcessor = new SimpleSpanProcessor(consoleExporter);
provider.addSpanProcessor(consoleProcessor);
// Register the provider to begin tracing
provider.register();