MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getOtlpReaders

Function getOtlpReaders

src/utils/telemetry/instrumentation.ts:130–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

128}
129
130async function getOtlpReaders() {
131 const exporterTypes = parseExporterTypes(process.env.OTEL_METRICS_EXPORTER)
132 const exportInterval = parseInt(
133 process.env.OTEL_METRIC_EXPORT_INTERVAL ||
134 DEFAULT_METRICS_EXPORT_INTERVAL_MS.toString(),
135 )
136
137 const exporters = []
138 for (const exporterType of exporterTypes) {
139 if (exporterType === 'console') {
140 // Custom console exporter that shows resource attributes
141 const consoleExporter = new ConsoleMetricExporter()
142 const originalExport = consoleExporter.export.bind(consoleExporter)
143
144 consoleExporter.export = (metrics, callback) => {
145 // Log resource attributes once at the start
146 if (metrics.resource && metrics.resource.attributes) {
147 // The console exporter is for debugging, so console output is intentional here
148
149 logForDebugging('\n=== Resource Attributes ===')
150 logForDebugging(jsonStringify(metrics.resource.attributes))
151 logForDebugging('===========================\n')
152 }
153
154 return originalExport(metrics, callback)
155 }
156
157 exporters.push(consoleExporter)
158 } else if (exporterType === 'otlp') {
159 const protocol =
160 process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL?.trim() ||
161 process.env.OTEL_EXPORTER_OTLP_PROTOCOL?.trim()
162
163 const httpConfig = getOTLPExporterConfig()
164
165 switch (protocol) {
166 case 'grpc': {
167 // Lazy-import to keep @grpc/grpc-js (~700KB) out of the telemetry chunk
168 // when the protocol is http/protobuf (ant default) or http/json.
169 const { OTLPMetricExporter } = await import(
170 '@opentelemetry/exporter-metrics-otlp-grpc'
171 )
172 exporters.push(new OTLPMetricExporter())
173 break
174 }
175 case 'http/json': {
176 const { OTLPMetricExporter } = await import(
177 '@opentelemetry/exporter-metrics-otlp-http'
178 )
179 exporters.push(new OTLPMetricExporter(httpConfig))
180 break
181 }
182 case 'http/protobuf': {
183 const { OTLPMetricExporter } = await import(
184 '@opentelemetry/exporter-metrics-otlp-proto'
185 )
186 exporters.push(new OTLPMetricExporter(httpConfig))
187 break

Callers 1

initializeTelemetryFunction · 0.85

Calls 6

parseExporterTypesFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85
getOTLPExporterConfigFunction · 0.85
toStringMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected