(config: Config)
| 75 | } |
| 76 | |
| 77 | export 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 | }), |
no test coverage detected