datarobot_genai.drmcpbase.datarobot_otel_metrics
datarobot_otel_metrics
Bootstrap an OTel SDK MeterProvider so metrics actually export.
Sibling to datarobot_otel.py (which does the same for traces). genai wires
OTel traces + logs but no metrics provider, so SLI counters/histograms emitted
via opentelemetry.metrics.get_meter(...) go to the default no-op provider
and never leave the process. Call :func:bootstrap_metrics_provider once at
startup to point the global MeterProvider at an OTLP/HTTP collector.
Follows the same safety contract as the trace bootstrap: a no-op when no endpoint is configured, idempotent, and never raises.
bootstrap_metrics_provider
bootstrap_metrics_provider(endpoint: str | None = None, *, headers: dict[str, str] | None = None, export_interval_ms: int | None = None, resource_attributes: dict[str, Any] | None = None) -> bool
Install a global OTLP/HTTP MeterProvider; return whether it installed.
When endpoint is not passed, the exporter resolves it the standard OTLP
way: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT if set, otherwise the shared
OTEL_EXPORTER_OTLP_ENDPOINT collector base URL (the same one traces
and logs use) with /v1/metrics appended. Headers likewise come from
OTEL_EXPORTER_OTLP_HEADERS unless passed explicitly, so a process that
already configured OTel for traces needs nothing extra for metrics.
Returns False (silently) when no endpoint is configured (the local-dev /
CI shape), when already installed in this process, or when setup raises.
resource_attributes are merged over the default service.name so a
host process (e.g. the MCP server) can stamp metrics with the same resource
identity it uses for traces and logs.