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