diff --git a/agent/monitoring/otlp_exporter.py b/agent/monitoring/otlp_exporter.py index cde95673ec..17c85cb8b6 100644 --- a/agent/monitoring/otlp_exporter.py +++ b/agent/monitoring/otlp_exporter.py @@ -116,14 +116,12 @@ def build_exporter(config: Dict[str, Any]): def _resource_attributes(config: Dict[str, Any]) -> Dict[str, str]: - from agent.monitoring.gateway_health import _safe_instance_id - from agent.monitoring.policy import ensure_install_id + # Lazy import: gateway_health_export imports this module back (for + # start_streaming), so the dependency must resolve at call time, not + # at module load, to avoid a circular import. + from agent.monitoring.gateway_health_export import _runtime_resource_attributes - return { - "service.name": "hermes-gateway", - "service.instance.id": _safe_instance_id(ensure_install_id(config)), - "telemetry.scope": "gateway_monitoring", - } + return _runtime_resource_attributes(config, telemetry_scope="gateway_monitoring") def _make_provider(config: Dict[str, Any]): diff --git a/tests/monitoring/test_otlp_exporter.py b/tests/monitoring/test_otlp_exporter.py index eebaf48da9..5006b128bf 100644 --- a/tests/monitoring/test_otlp_exporter.py +++ b/tests/monitoring/test_otlp_exporter.py @@ -66,6 +66,20 @@ def test_trace_resource_includes_stable_hashed_instance(): assert attrs["telemetry.scope"] == "gateway_monitoring" +def test_trace_resource_includes_configured_deployment_environment(): + attrs = OE._resource_attributes({ + "monitoring": { + "install_id": "private-install-id", + "gateway_health_export": { + "resource_attributes": {"deployment.environment.name": "production"}, + }, + }, + }) + + assert attrs["deployment.environment.name"] == "production" + assert attrs["service.name"] == "hermes-gateway" + + def test_streamer_receives_events_and_respects_filter(monkeypatch):