-
Notifications
You must be signed in to change notification settings - Fork 42
/
tracer.ts
75 lines (67 loc) · 2.72 KB
/
tracer.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
import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { ParentBasedSampler, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base'
import { OurSampler } from './ourSampler';
import {W3CBaggagePropagator, W3CTraceContextPropagator, CompositePropagator} from '@opentelemetry/core'
import { OTLPMetricExporter} from '@opentelemetry/exporter-metrics-otlp-proto'
function start(serviceName: string) {
const { endpoint, port } = PrometheusExporter.DEFAULT_OPTIONS;
// const exporter = new PrometheusExporter({}, () => {
// console.log(
// `prometheus scrape endpoint: http://localhost:${port}${endpoint}`,
// );
// });
const meterProvider = new MeterProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
}),
});
const metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url:'http://collector:4318/v1/metrics'
})
})
meterProvider.addMetricReader(metricReader);
const meter = meterProvider.getMeter('my-service-meter');
const traceExporter = new OTLPTraceExporter({
url: 'http://collector:4318/v1/traces',
});
const sdk = new NodeSDK({
traceExporter,
serviceName: serviceName,
instrumentations: [getNodeAutoInstrumentations({
"@opentelemetry/instrumentation-fs":{
enabled:false
},
"@opentelemetry/instrumentation-http":{
headersToSpanAttributes:{
client:{
requestHeaders:['tracestate','traceparent','baggage']
},
server:{
requestHeaders:['tracestate','traceparent','baggage']
}
}
}
})],
autoDetectResources:true,
resource: new Resource({
'team.owner':'core-team',
'deployment':'4'
}),
sampler: new ParentBasedSampler({
root: new OurSampler()
}),
textMapPropagator: new CompositePropagator({
propagators:[new W3CTraceContextPropagator(), new W3CBaggagePropagator()]
})
});
sdk.start();
return meter;
}
export default start