MCPcopy Create free account
hub / github.com/anus-dev/ANUS / initializeTelemetry

Function initializeTelemetry

packages/core/src/telemetry/sdk.ts:77–179  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

75}
76
77export function initializeTelemetry(config: Config): void {
78 if (telemetryInitialized || !config.getTelemetryEnabled()) {
79 return;
80 }
81
82 const resource = new Resource({
83 [SemanticResourceAttributes.SERVICE_NAME]: SERVICE_NAME,
84 [SemanticResourceAttributes.SERVICE_VERSION]: process.version,
85 'session.id': config.getSessionId(),
86 });
87
88 const otlpEndpoint = config.getTelemetryOtlpEndpoint();
89 const otlpProtocol = config.getTelemetryOtlpProtocol();
90 const parsedEndpoint = parseOtlpEndpoint(otlpEndpoint, otlpProtocol);
91 const useOtlp = !!parsedEndpoint;
92 const telemetryOutfile = config.getTelemetryOutfile();
93
94 let spanExporter:
95 | OTLPTraceExporter
96 | OTLPTraceExporterHttp
97 | FileSpanExporter
98 | ConsoleSpanExporter;
99 let logExporter:
100 | OTLPLogExporter
101 | OTLPLogExporterHttp
102 | FileLogExporter
103 | ConsoleLogRecordExporter;
104 let metricReader: PeriodicExportingMetricReader;
105
106 if (useOtlp) {
107 if (otlpProtocol === 'http') {
108 spanExporter = new OTLPTraceExporterHttp({
109 url: parsedEndpoint,
110 });
111 logExporter = new OTLPLogExporterHttp({
112 url: parsedEndpoint,
113 });
114 metricReader = new PeriodicExportingMetricReader({
115 exporter: new OTLPMetricExporterHttp({
116 url: parsedEndpoint,
117 }),
118 exportIntervalMillis: 10000,
119 });
120 } else {
121 // grpc
122 spanExporter = new OTLPTraceExporter({
123 url: parsedEndpoint,
124 compression: CompressionAlgorithm.GZIP,
125 });
126 logExporter = new OTLPLogExporter({
127 url: parsedEndpoint,
128 compression: CompressionAlgorithm.GZIP,
129 });
130 metricReader = new PeriodicExportingMetricReader({
131 exporter: new OTLPMetricExporter({
132 url: parsedEndpoint,
133 compression: CompressionAlgorithm.GZIP,
134 }),

Callers 3

telemetry.test.tsFile · 0.85
sdk.test.tsFile · 0.85
constructorMethod · 0.85

Calls 10

parseOtlpEndpointFunction · 0.85
initializeMetricsFunction · 0.85
shutdownTelemetryFunction · 0.85
getTelemetryEnabledMethod · 0.80
getSessionIdMethod · 0.80
getTelemetryOutfileMethod · 0.80
getDebugModeMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected