Skip to content

Commit acfa2b9

Browse files
authored
chore(context): update_tags only adds tags with new keys (backport #4061) (#4074)
This is an automatic backport of pull request #4061 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
1 parent 2fad8e7 commit acfa2b9

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

ddtrace/context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ def _with_span(self, span):
7070
def _update_tags(self, span):
7171
# type: (Span) -> None
7272
with self._lock:
73-
span._meta.update(self._meta)
74-
span._metrics.update(self._metrics)
73+
for tag in self._meta:
74+
span._meta.setdefault(tag, self._meta[tag])
75+
for metric in self._metrics:
76+
span._metrics.setdefault(metric, self._metrics[metric])
7577

7678
@property
7779
def sampling_priority(self):

tests/integration/test_integration_snapshots.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import pytest
66

77
from ddtrace import Tracer
8+
from ddtrace.constants import AUTO_KEEP
89
from ddtrace.constants import MANUAL_DROP_KEY
910
from ddtrace.constants import MANUAL_KEEP_KEY
11+
from ddtrace.constants import SAMPLING_PRIORITY_KEY
12+
from ddtrace.constants import USER_KEEP
1013
from ddtrace.internal.writer import AgentWriter
1114
from ddtrace.sampler import DatadogSampler
1215
from ddtrace.sampler import RateSampler
@@ -273,3 +276,13 @@ def test_trace_with_wrong_metrics_types_not_sent(metrics):
273276
with tracer.trace("child") as child:
274277
child._metrics = metrics
275278
log.exception.assert_called_once_with("error closing trace")
279+
280+
281+
@snapshot()
282+
def test_tracetagsprocessor_only_adds_new_tags():
283+
tracer = Tracer()
284+
with tracer.trace(name="web.request") as span:
285+
span.context.sampling_priority = AUTO_KEEP
286+
span.set_metric(SAMPLING_PRIORITY_KEY, USER_KEEP)
287+
288+
tracer.shutdown()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[[
2+
{
3+
"name": "web.request",
4+
"service": null,
5+
"resource": "web.request",
6+
"trace_id": 0,
7+
"span_id": 1,
8+
"parent_id": 0,
9+
"meta": {
10+
"_dd.p.dm": "-0",
11+
"runtime-id": "334311a6f22143ff855bbf68dbabac50"
12+
},
13+
"metrics": {
14+
"_dd.agent_psr": 1.0,
15+
"_dd.top_level": 1,
16+
"_dd.tracer_kr": 1.0,
17+
"_sampling_priority_v1": 2,
18+
"system.pid": 15332
19+
},
20+
"duration": 34000,
21+
"start": 1660010337590045000
22+
}]]

0 commit comments

Comments
 (0)