Skip to content

Commit 3688567

Browse files
chore(writer): add missing metadata to native writer (#14623)
Fix missing metadata in native writer telemetry. The trace exporter needs the tracer to set service and env name to include it in telemetry payloads. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 644ba68 commit 3688567

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ddtrace/internal/native/_native.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ class TraceExporterBuilder:
232232
:param version: The version string of the application.
233233
"""
234234
...
235+
def set_service(self, service: str) -> TraceExporterBuilder:
236+
"""
237+
Set the service name of the TraceExporter.
238+
:param version: The version string of the application.
239+
"""
240+
...
235241
def set_git_commit_sha(self, git_commit_sha: str) -> TraceExporterBuilder:
236242
"""
237243
Set the git commit sha of the TraceExporter.

ddtrace/internal/writer/writer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import ddtrace
1717
from ddtrace import config
18+
from ddtrace.internal.hostname import get_hostname
1819
import ddtrace.internal.native as native
1920
from ddtrace.internal.runtime import get_runtime_id
2021
import ddtrace.internal.utils.http
@@ -796,6 +797,7 @@ def _create_exporter(self) -> native.TraceExporter:
796797
builder = (
797798
native.TraceExporterBuilder()
798799
.set_url(self.intake_url)
800+
.set_hostname(get_hostname())
799801
.set_language("python")
800802
.set_language_version(compat.PYTHON_VERSION)
801803
.set_language_interpreter(compat.PYTHON_INTERPRETER)
@@ -805,6 +807,12 @@ def _create_exporter(self) -> native.TraceExporter:
805807
.set_input_format(self._api_version)
806808
.set_output_format(self._api_version)
807809
)
810+
if config.service:
811+
builder.set_service(config.service)
812+
if config.env:
813+
builder.set_env(config.env)
814+
if config.version:
815+
builder.set_app_version(config.version)
808816
if self._test_session_token is not None:
809817
builder.set_test_session_token(self._test_session_token)
810818
if self._stats_opt_out:

tests/tracer/test_writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ def test_writer_telemetry_enabled_on_linux(
11711171

11721172
for method_name in [
11731173
"set_url",
1174+
"set_hostname",
11741175
"set_language",
11751176
"set_language_version",
11761177
"set_language_interpreter",

0 commit comments

Comments
 (0)