Skip to content

Commit e8469b1

Browse files
fix(tracer): downgrade default trace api from v05 to v04 [backport 1.20] (#6954)
Backport 107ee1f from #6947 to 1.20. ## Description Encoding traces in the v05 format has known issues for applications generating spans at a high frequency. Although this issue impacts 1/1000000 spans, these misformated payloads have the potential to degrade internal servoces. ## Motivation Resolves an incident. ## Risk This change may introduce a small performance regression in some applications: 1c12c0a#diff-0b32c6cdae8bdd01786317bcabebf73dbb57e535adab74c94858fda05da411ef ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. Co-authored-by: Munir Abdinur <[email protected]>
1 parent 4e0c33c commit e8469b1

File tree

515 files changed

+309
-3144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

515 files changed

+309
-3144
lines changed

ddtrace/internal/writer/writer.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
from ..encoding import JSONEncoderV2
3636
from ..logger import get_logger
3737
from ..runtime import container
38-
from ..serverless import in_azure_function_consumption_plan
39-
from ..serverless import in_gcp_function
4038
from ..sma import SimpleMovingAverage
4139
from .writer_client import AgentWriterClientV3
4240
from .writer_client import AgentWriterClientV4
@@ -500,11 +498,8 @@ def __init__(
500498
# as a safety precaution.
501499
# https://docs.python.org/3/library/sys.html#sys.platform
502500
is_windows = sys.platform.startswith("win") or sys.platform.startswith("cygwin")
503-
default_api_version = (
504-
"v0.4" if (is_windows or in_gcp_function() or in_azure_function_consumption_plan()) else "v0.5"
505-
)
506501

507-
self._api_version = api_version or config._trace_api or (default_api_version if priority_sampling else "v0.3")
502+
self._api_version = api_version or config._trace_api or ("v0.4" if priority_sampling else "v0.3")
508503
if is_windows and self._api_version == "v0.5":
509504
raise RuntimeError(
510505
"There is a known compatibility issue with v0.5 API and Windows, "

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ metadata
135135
microservices
136136
middleware
137137
middlewares
138+
misencoded
138139
moderations
139140
mongoengine
140141
multiline
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
tracing: Encoding traces in the v05 format has a known issue for
5+
applications generating spans at a high frequency, causing approximately
6+
1/10000000 spans to be misencoded.
7+
This change sets ``DD_TRACE_API_VERSION`` to ``v04`` by default.

tests/integration/test_integration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_uds_wrong_socket_path():
124124
mock.call(
125125
"failed to send, dropping %d traces to intake at %s after %d retries",
126126
1,
127-
"unix:///tmp/ddagent/nosockethere/{}/traces".format(encoding if encoding else "v0.5"),
127+
"unix:///tmp/ddagent/nosockethere/{}/traces".format(encoding if encoding else "v0.4"),
128128
3,
129129
)
130130
]
@@ -382,7 +382,7 @@ def test_trace_generates_error_logs_when_hostname_invalid():
382382
mock.call(
383383
"failed to send, dropping %d traces to intake at %s after %d retries",
384384
1,
385-
"http://bad:1111/{}/traces".format(encoding if encoding else "v0.5"),
385+
"http://bad:1111/{}/traces".format(encoding if encoding else "v0.4"),
386386
3,
387387
)
388388
]
@@ -471,7 +471,7 @@ def test_trace_with_invalid_payload_generates_error_log():
471471
[
472472
mock.call(
473473
"failed to send traces to intake at %s: HTTP error status %s, reason %s",
474-
"http://localhost:8126/v0.5/traces",
474+
"http://localhost:8126/v0.4/traces",
475475
400,
476476
"Bad Request",
477477
)
@@ -550,9 +550,9 @@ def test_api_version_downgrade_generates_no_warning_logs():
550550

551551
from ddtrace import tracer as t
552552

553-
encoding = os.environ["DD_TRACE_API_VERSION"]
553+
encoding = os.environ["DD_TRACE_API_VERSION"] or "v0.4"
554554
t._writer._downgrade(None, None, t._writer._clients[0])
555-
assert t._writer._endpoint == {"v0.5": "v0.4/traces", "v0.4": "v0.3/traces"}[encoding or "v0.5"]
555+
assert t._writer._endpoint == {"v0.5": "v0.4/traces", "v0.4": "v0.3/traces"}[encoding]
556556
with mock.patch("ddtrace.internal.writer.writer.log") as log:
557557
t.trace("operation", service="my-svc").finish()
558558
t.shutdown()

tests/snapshots/test_extended_sampling_resource.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "should_not_send",
4-
"service": "",
4+
"service": null,
55
"resource": "mycoolre$ource",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-3",
1311
"language": "python",
@@ -26,13 +24,11 @@
2624
[
2725
{
2826
"name": "should_send",
29-
"service": "",
27+
"service": null,
3028
"resource": "something else",
3129
"trace_id": 1,
3230
"span_id": 1,
3331
"parent_id": 0,
34-
"type": "",
35-
"error": 0,
3632
"meta": {
3733
"_dd.p.dm": "-0",
3834
"language": "python",

tests/snapshots/test_extended_sampling_tags.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "should_not_send",
4-
"service": "",
4+
"service": null,
55
"resource": "should_not_send",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-3",
1311
"language": "python",
@@ -27,13 +25,11 @@
2725
[
2826
{
2927
"name": "should_send",
30-
"service": "",
28+
"service": null,
3129
"resource": "should_send",
3230
"trace_id": 1,
3331
"span_id": 1,
3432
"parent_id": 0,
35-
"type": "",
36-
"error": 0,
3733
"meta": {
3834
"_dd.p.dm": "-0",
3935
"banana": "True",

tests/snapshots/test_extended_sampling_tags_and_resource.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "should_not_send",
4-
"service": "",
4+
"service": null,
55
"resource": "mycoolre$ource",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-3",
1311
"language": "python",
@@ -27,13 +25,11 @@
2725
[
2826
{
2927
"name": "should_send1",
30-
"service": "",
28+
"service": null,
3129
"resource": "should_send1",
3230
"trace_id": 1,
3331
"span_id": 1,
3432
"parent_id": 0,
35-
"type": "",
36-
"error": 0,
3733
"meta": {
3834
"_dd.p.dm": "-0",
3935
"banana": "True",
@@ -52,13 +48,11 @@
5248
[
5349
{
5450
"name": "should_send2",
55-
"service": "",
51+
"service": null,
5652
"resource": "banana",
5753
"trace_id": 2,
5854
"span_id": 1,
5955
"parent_id": 0,
60-
"type": "",
61-
"error": 0,
6256
"meta": {
6357
"_dd.p.dm": "-0",
6458
"language": "python",
@@ -77,13 +71,11 @@
7771
[
7872
{
7973
"name": "should_send3",
80-
"service": "",
74+
"service": null,
8175
"resource": "mycoolre$ource",
8276
"trace_id": 3,
8377
"span_id": 1,
8478
"parent_id": 0,
85-
"type": "",
86-
"error": 0,
8779
"meta": {
8880
"_dd.p.dm": "-0",
8981
"banana": "True",

tests/snapshots/test_extended_sampling_tags_glob.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "should_not_send",
4-
"service": "",
4+
"service": null,
55
"resource": "should_not_send",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-3",
1311
"language": "python",
@@ -27,13 +25,11 @@
2725
[
2826
{
2927
"name": "should_send",
30-
"service": "",
28+
"service": null,
3129
"resource": "should_send",
3230
"trace_id": 1,
3331
"span_id": 1,
3432
"parent_id": 0,
35-
"type": "",
36-
"error": 0,
3733
"meta": {
3834
"_dd.p.dm": "-0",
3935
"language": "python",

tests/snapshots/test_sampling_with_default_sample_rate_1.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "trace2",
4-
"service": "",
4+
"service": null,
55
"resource": "trace2",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-3",
1311
"language": "python",
@@ -25,13 +23,11 @@
2523
},
2624
{
2725
"name": "child",
28-
"service": "",
26+
"service": null,
2927
"resource": "child",
3028
"trace_id": 0,
3129
"span_id": 2,
3230
"parent_id": 1,
33-
"type": "",
34-
"error": 0,
3531
"duration": 11602,
3632
"start": 1692637140104307759
3733
}]]

tests/snapshots/test_sampling_with_default_sample_rate_1_and_manual_drop.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
[[
22
{
33
"name": "trace6",
4-
"service": "",
4+
"service": null,
55
"resource": "trace6",
66
"trace_id": 0,
77
"span_id": 1,
88
"parent_id": 0,
9-
"type": "",
10-
"error": 0,
119
"meta": {
1210
"_dd.p.dm": "-4",
1311
"language": "python",
@@ -24,13 +22,11 @@
2422
},
2523
{
2624
"name": "child",
27-
"service": "",
25+
"service": null,
2826
"resource": "child",
2927
"trace_id": 0,
3028
"span_id": 2,
3129
"parent_id": 1,
32-
"type": "",
33-
"error": 0,
3430
"duration": 16195,
3531
"start": 1691163616781394547
3632
}]]

0 commit comments

Comments
 (0)