-
Notifications
You must be signed in to change notification settings - Fork 171
/
wrapper.ts
96 lines (86 loc) · 3.59 KB
/
wrapper.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { NodeTracerConfig, NodeTracerProvider } from '@opentelemetry/node';
import {
BatchSpanProcessor,
SDKRegistrationConfig,
} from '@opentelemetry/tracing';
// Use require statements for instrumentation to avoid having to have transitive dependencies on all the typescript
// definitions.
const{ AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');
const { DnsInstrumentation } = require('@opentelemetry/instrumentation-dns');
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
const { GraphQLInstrumentation } = require('@opentelemetry/instrumentation-graphql');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis');
const { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa');
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');
const { MySQLInstrumentation } = require('@opentelemetry/instrumentation-mysql');
const { NetInstrumentation } = require('@opentelemetry/instrumentation-net');
const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');
const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis');
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector-proto';
import { awsLambdaDetector } from '@opentelemetry/resource-detector-aws';
import {
detectResources,
envDetector,
processDetector,
} from '@opentelemetry/resources';
import { AwsInstrumentation } from 'opentelemetry-instrumentation-aws-sdk';
declare global {
function configureTracer(defaultConfig: NodeTracerConfig): NodeTracerConfig;
function configureSdkRegistration(
defaultSdkRegistration: SDKRegistrationConfig
): SDKRegistrationConfig;
}
console.log('Registering OpenTelemetry');
const instrumentations = [
new AwsInstrumentation({
suppressInternalInstrumentation: true,
}),
new AwsLambdaInstrumentation(),
new DnsInstrumentation(),
new ExpressInstrumentation(),
new GraphQLInstrumentation(),
new GrpcInstrumentation(),
new HapiInstrumentation(),
new HttpInstrumentation(),
new IORedisInstrumentation(),
new KoaInstrumentation(),
new MongoDBInstrumentation(),
new MySQLInstrumentation(),
new NetInstrumentation(),
new PgInstrumentation(),
new RedisInstrumentation(),
];
// Register instrumentations synchronously to ensure code is patched even before provider is ready.
registerInstrumentations({
instrumentations,
});
async function initializeProvider() {
const resource = await detectResources({
detectors: [awsLambdaDetector, envDetector, processDetector],
});
let config: NodeTracerConfig = {
resource,
};
if (typeof configureTracer === 'function') {
config = configureTracer(config);
}
const tracerProvider = new NodeTracerProvider(config);
tracerProvider.addSpanProcessor(
new BatchSpanProcessor(new CollectorTraceExporter())
);
let sdkRegistrationConfig: SDKRegistrationConfig = {};
if (typeof configureSdkRegistration === 'function') {
sdkRegistrationConfig = configureSdkRegistration(sdkRegistrationConfig);
}
tracerProvider.register(sdkRegistrationConfig);
// Re-register instrumentation with initialized provider. Patched code will see the update.
registerInstrumentations({
instrumentations,
tracerProvider,
});
}
initializeProvider();