import { metrics } from "@opentelemetry/api";

/**
 * Module-level metric instruments for the flights remote component.
 * Safe to declare at module scope — @opentelemetry/api's proxy meter
 * lazy-resolves to the real MeterProvider after initServerOtel/initBrowserOtel runs.
 */
const meter = metrics.getMeter("flights");

/** SSR request duration histogram (seconds). */
export const flightsSsrRequestDuration = meter.createHistogram("flights.ssr.request.duration");

/** Upstream API request duration histogram (seconds). */
export const flightsApiRequestDuration = meter.createHistogram("flights.api.request.duration");

/** Upstream API error counter (by route, status). */
export const flightsApiError = meter.createCounter("flights.api.error");

/** SignalR active connections gauge. */
export const flightsSignalRConnected = meter.createUpDownCounter("flights.signalr.connected");

/** SignalR messages received counter. */
export const flightsSignalRMessageReceived = meter.createCounter("flights.signalr.message.received");

/** SignalR disconnection counter (by reason). */
export const flightsSignalRDisconnect = meter.createCounter("flights.signalr.disconnect");

/** Feature component render counter (by feature name). */
export const flightsFeatureRender = meter.createCounter("flights.feature.render");

/** Unhandled React error counter (caught by ErrorBoundary). */
export const flightsReactError = meter.createCounter("flights.react.error");
