MCPcopy Create free account
hub / github.com/Noumena-Network/code / setMeterState

Function setMeterState

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

Source from the content-addressed store, hash-verified

306}
307
308async function setMeterState(): Promise<void> {
309 // Lazy-load instrumentation to defer ~400KB of OpenTelemetry + protobuf
310 const { initializeTelemetry } = await import(
311 '../utils/telemetry/instrumentation.js'
312 )
313 // Initialize customer OTLP telemetry (metrics, logs, traces)
314 const meter = await initializeTelemetry()
315 if (meter) {
316 // Create factory function for attributed counters
317 const createAttributedCounter = (
318 name: string,
319 options: MetricOptions,
320 ): AttributedCounter => {
321 const counter = meter?.createCounter(name, options)
322
323 return {
324 add(value: number, additionalAttributes: Attributes = {}) {
325 // Always fetch fresh telemetry attributes to ensure they're up to date
326 const currentAttributes = getTelemetryAttributes()
327 const mergedAttributes = {
328 ...currentAttributes,
329 ...additionalAttributes,
330 }
331 counter?.add(value, mergedAttributes)
332 },
333 }
334 }
335
336 setMeter(meter, createAttributedCounter)
337
338 // Increment session counter here because the startup telemetry path
339 // runs before this async initialization completes, so the counter
340 // would be null there.
341 getSessionCounter()?.add(1)
342 }
343}

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