Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddtrace/internal/opentelemetry/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _build_resource() -> Optional[Any]:
**config.tags,
"service.name": config.service,
"service.version": config.version,
"deployment.environment": config.env,
"deployment.environment.name": config.env,
Comment thread
mabdinur marked this conversation as resolved.
}

if config._report_hostname and "host.name" not in resource_attributes:
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/opentelemetry/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _build_resource() -> Optional[Any]:
**config.tags,
"service.name": config.service,
"service.version": config.version,
"deployment.environment": config.env,
"deployment.environment.name": config.env,
}

if config._report_hostname and "host.name" not in resource_attributes:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
tracing: Fixes an issue where OTLP log and metric resources use the deprecated
``deployment.environment`` attribute instead of ``deployment.environment.name`` for ``DD_ENV``.
15 changes: 11 additions & 4 deletions tests/opentelemetry/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def extract_resource_attributes(log_record, resource) -> dict:
for attr in resource.attributes:
if attr.key == "service.name":
attributes["service"] = attr.value.string_value
elif attr.key == "deployment.environment":
elif attr.key == "deployment.environment.name":
attributes["env"] = attr.value.string_value
elif attr.key == "service.version":
attributes["version"] = attr.value.string_value
Expand Down Expand Up @@ -226,13 +226,20 @@ def test_otel_logs_exporter_auto_configured_http():

captured_logs = decode_logs_request(request_body)
assert len(captured_logs.resource_logs) > 0, "Expected at least one resource log in the OpenTelemetry logs request"
assert all(
attr.key != "deployment.environment"
for resource_logs in captured_logs.resource_logs
for attr in resource_logs.resource.attributes
)

attributes = extract_log_correlation_attributes(captured_logs, "test_otel_logs_exporter_auto_configured_http")
assert len(attributes) == 6, f"Expected 6 log correlation attributes but found: {attributes}"
assert attributes["service"] == "ddservice", (
f"Expected service.name to be 'ddservice' but found: {attributes['service']}"
)
assert attributes["env"] == "ddenv", f"Expected deployment.environment to be 'ddenv' but found: {attributes['env']}"
assert attributes["env"] == "ddenv", (
f"Expected deployment.environment.name to be 'ddenv' but found: {attributes['env']}"
)
assert attributes["version"] == "ddv1", f"Expected service.version to be 'ddv1' but found: {attributes['version']}"
assert attributes["host_name"] == "ddhost", (
f"Expected host.name to be 'ddhost' but found: {attributes['host_name']}"
Expand Down Expand Up @@ -423,7 +430,7 @@ def test_ddtrace_log_correlation():
f"Expected service.name to be 'test_service' but found: {attributes['service']}"
)
assert attributes["env"] == "test_env", (
f"Expected deployment.environment to be 'test_env' but found: {attributes['env']}"
f"Expected deployment.environment.name to be 'test_env' but found: {attributes['env']}"
)
assert attributes["version"] == "1.0", f"Expected service.version to be '1.0' but found: {attributes['version']}"
assert attributes["host_name"] == "test_host2", (
Expand Down Expand Up @@ -490,7 +497,7 @@ def test_otel_trace_log_correlation():
f"Expected service.name to be 'test_service' but found: {attributes['service']}"
)
assert attributes["env"] == "test_env", (
f"Expected deployment.environment to be 'test_env' but found: {attributes['env']}"
f"Expected deployment.environment.name to be 'test_env' but found: {attributes['env']}"
)
assert attributes["version"] == "1.0", f"Expected service.version to be '1.0' but found: {attributes['version']}"
assert attributes["host_name"] == "test_host", (
Expand Down
11 changes: 11 additions & 0 deletions tests/opentelemetry/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ def test_otel_metrics_enabled():
assert meter_provider, "OpenTelemetry metrics exporter should be configured automatically."


@skipif(exporter_not_installed=True, unsupported_otel_version=True)
@pytest.mark.subprocess(ddtrace_run=True, env={"DD_ENV": "test_env"})
def test_otel_metrics_resource_uses_stable_environment_attribute():
from ddtrace.internal.opentelemetry.metrics import _build_resource

resource = _build_resource()
assert resource is not None
assert resource.attributes["deployment.environment.name"] == "test_env"
assert "deployment.environment" not in resource.attributes


@skipif(exporter_not_installed=True, unsupported_otel_version=True)
@pytest.mark.subprocess(ddtrace_run=True, parametrize={"DD_METRICS_OTEL_ENABLED": [None, "false"]})
def test_otel_metrics_disabled_and_unset():
Expand Down
Loading