Skip to content

Commit 5f90ab7

Browse files
authored
feat(ddtrace-api): patch tracer.set_tags in the ddtrace-api integration (#13824)
This change adds patching to `Tracer.set_tags` in the ddtrace-api integration to support a common use case in Rapid ## 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 fe4c7ab commit 5f90ab7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

ddtrace/contrib/internal/ddtrace_api/patch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def patch(tracer=None):
9595

9696
DDTraceAPIWrappingContextBase(ddtrace_api.Tracer.start_span).wrap()
9797
DDTraceAPIWrappingContextBase(ddtrace_api.Tracer.trace).wrap()
98+
DDTraceAPIWrappingContextBase(ddtrace_api.Tracer.set_tags).wrap()
9899
DDTraceAPIWrappingContextBase(ddtrace_api.Tracer.current_span).wrap()
99100
DDTraceAPIWrappingContextBase(ddtrace_api.Tracer.current_root_span).wrap()
100101
DDTraceAPIWrappingContextBase(ddtrace_api.Span.finish).wrap()
@@ -115,6 +116,7 @@ def unpatch():
115116

116117
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Tracer.start_span).unwrap()
117118
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Tracer.trace).unwrap()
119+
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Tracer.set_tags).unwrap()
118120
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Tracer.current_span).unwrap()
119121
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Tracer.current_root_span).unwrap()
120122
DDTraceAPIWrappingContextBase.extract(ddtrace_api.Span.finish).unwrap()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
ddtrace-api: Adds patching of ``ddtrace_api.tracer.set_tags`` to the ``ddtrace_api`` integration

tests/contrib/ddtrace_api/test_integration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,11 @@ def test_set_tags(self):
128128
spans = self._assert_real_spans()
129129
assert spans[0]._meta["tag1"] == "value1", "Tag set via API should be applied to the real spans"
130130
assert spans[0]._meta["tag2"] == "value2", "Tag set via API should be applied to the real spans"
131+
132+
@pytest.mark.snapshot()
133+
def test_tracer_set_tags(self):
134+
ddtrace_api.tracer.set_tags({"tag1": "value1", "tag2": "value2"})
135+
ddtrace_api.tracer.trace("web.request").finish()
136+
spans = self._assert_real_spans()
137+
assert spans[0]._meta["tag1"] == "value1", "Tag set via API should be applied to the real spans"
138+
assert spans[0]._meta["tag2"] == "value2", "Tag set via API should be applied to the real spans"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[[
2+
{
3+
"name": "web.request",
4+
"service": "tests.contrib.ddtrace_api",
5+
"resource": "web.request",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"type": "",
10+
"error": 0,
11+
"meta": {
12+
"_dd.p.dm": "-0",
13+
"_dd.p.tid": "6862c99700000000",
14+
"language": "python",
15+
"runtime-id": "189ff080b5004f2186829183a50e3c67",
16+
"tag1": "value1",
17+
"tag2": "value2"
18+
},
19+
"metrics": {
20+
"_dd.top_level": 1,
21+
"_dd.tracer_kr": 1.0,
22+
"_sampling_priority_v1": 1,
23+
"process_id": 1638
24+
},
25+
"duration": 112708,
26+
"start": 1751304599164607503
27+
}]]

0 commit comments

Comments
 (0)