MCPcopy
hub / github.com/claude-code-best/claude-code / setMeterState

Function setMeterState

src/entrypoints/init.ts:357–392  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355}
356
357async function setMeterState(): Promise<void> {
358 // Lazy-load instrumentation to defer ~400KB of OpenTelemetry + protobuf
359 const { initializeTelemetry } = await import(
360 '../utils/telemetry/instrumentation.js'
361 )
362 // Initialize customer OTLP telemetry (metrics, logs, traces)
363 const meter = await initializeTelemetry()
364 if (meter) {
365 // Create factory function for attributed counters
366 const createAttributedCounter = (
367 name: string,
368 options: MetricOptions,
369 ): AttributedCounter => {
370 const counter = meter?.createCounter(name, options)
371
372 return {
373 add(value: number, additionalAttributes: Attributes = {}) {
374 // Always fetch fresh telemetry attributes to ensure they're up to date
375 const currentAttributes = getTelemetryAttributes()
376 const mergedAttributes = {
377 ...currentAttributes,
378 ...additionalAttributes,
379 }
380 counter?.add(value, mergedAttributes)
381 },
382 }
383 }
384
385 setMeter(meter, createAttributedCounter)
386
387 // Increment session counter here because the startup telemetry path
388 // runs before this async initialization completes, so the counter
389 // would be null there.
390 getSessionCounter()?.add(1)
391 }
392}

Callers 1

doInitializeTelemetryFunction · 0.85

Calls 4

initializeTelemetryFunction · 0.85
setMeterFunction · 0.85
getSessionCounterFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected