Skip to content

Commit 19a1625

Browse files
authored
chore(otel): make snapshots less flaky (#13016)
## 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 f4eb1f5 commit 19a1625

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

tests/opentelemetry/test_context.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ddtrace.constants import MANUAL_KEEP_KEY
1414

1515

16-
@pytest.mark.snapshot
16+
@pytest.mark.snapshot(wait_for_num_traces=1)
1717
def test_otel_span_parenting(oteltracer):
1818
with oteltracer.start_as_current_span("otel-root") as root:
1919
time.sleep(0.02)
@@ -36,7 +36,7 @@ def test_otel_span_parenting(oteltracer):
3636
orphan1.end()
3737

3838

39-
@pytest.mark.snapshot
39+
@pytest.mark.snapshot(wait_for_num_traces=1)
4040
def test_otel_ddtrace_mixed_parenting(oteltracer):
4141
with oteltracer.start_as_current_span("otel-top-level"):
4242
with ddtrace.tracer.trace("ddtrace-top-level"):
@@ -51,7 +51,7 @@ def test_otel_ddtrace_mixed_parenting(oteltracer):
5151
time.sleep(0.02)
5252

5353

54-
@pytest.mark.snapshot
54+
@pytest.mark.snapshot(wait_for_num_traces=1)
5555
def test_otel_multithreading(oteltracer):
5656
def target(parent_context):
5757
ctx = opentelemetry.trace.set_span_in_context(opentelemetry.trace.NonRecordingSpan(parent_context))
@@ -92,7 +92,7 @@ def _subprocess_task(parent_span_context, errors):
9292
ot_tracer._tracer.flush()
9393

9494

95-
@pytest.mark.snapshot(ignores=["meta.tracestate"])
95+
@pytest.mark.snapshot(wait_for_num_traces=1, ignores=["meta.tracestate"])
9696
@pytest.mark.subprocess(env={"DD_TRACE_OTEL_ENABLED": "true"}, ddtrace_run=True, err=None)
9797
def test_otel_trace_across_fork():
9898
import multiprocessing
@@ -146,7 +146,7 @@ def test_sampling_decisions_across_processes():
146146

147147

148148
@pytest.mark.asyncio
149-
@pytest.mark.snapshot
149+
@pytest.mark.snapshot(wait_for_num_traces=1)
150150
async def test_otel_trace_multiple_coroutines(oteltracer):
151151
async def coro(i):
152152
with oteltracer.start_as_current_span("corountine %s" % (i,)):

tests/opentelemetry/test_span.py

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

1616
from ddtrace.constants import MANUAL_DROP_KEY
1717
from ddtrace.internal.opentelemetry.span import Span
18-
from tests.utils import flaky
1918

2019

2120
@pytest.mark.snapshot(wait_for_num_traces=3)
@@ -47,7 +46,7 @@ def test_otel_span_attributes(oteltracer):
4746
span.set_attribute("should_not_be_set", "attributes can not be added after a span is ended")
4847

4948

50-
@pytest.mark.snapshot(wait_for_num_traces=1)
49+
@pytest.mark.snapshot(wait_for_num_traces=2)
5150
def test_otel_span_events(oteltracer):
5251
with oteltracer.start_span("webpage.load") as span1:
5352
span1.add_event(
@@ -64,7 +63,7 @@ def test_otel_span_events(oteltracer):
6463
span2.add_event("Event on finished span, event won't be added")
6564

6665

67-
@pytest.mark.snapshot
66+
@pytest.mark.snapshot(wait_for_num_traces=1)
6867
@pytest.mark.parametrize(
6968
"override",
7069
[
@@ -82,8 +81,7 @@ def test_otel_span_attributes_overrides(oteltracer, override):
8281
span.set_attribute(otel, value)
8382

8483

85-
@pytest.mark.snapshot
86-
@flaky(1741838400, reason="Did not receive expected traces: 'client','server','producer','consumer','internal'")
84+
@pytest.mark.snapshot(wait_for_num_traces=5)
8785
def test_otel_span_kind(oteltracer):
8886
with oteltracer.start_span("otel-client", kind=OtelSpanKind.CLIENT):
8987
pass

tests/opentelemetry/test_trace.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_otel_compatible_tracer_is_returned_by_tracer_provider():
1919
assert isinstance(otel_compatible_tracer, opentelemetry.trace.Tracer)
2020

2121

22-
@pytest.mark.snapshot(wait_for_num_traces=1, ignores=["meta.error.stack"])
22+
@pytest.mark.snapshot(wait_for_num_traces=2, ignores=["meta.error.stack"])
2323
def test_otel_start_span_record_exception(oteltracer):
2424
# Avoid mocking time_ns when Span is created. This is a workaround to resolve a rate limit bug.
2525
raised_span = oteltracer.start_span("test-raised-exception")
@@ -104,21 +104,21 @@ def test_otel_start_span_with_span_links(oteltracer):
104104
span2.end()
105105

106106

107-
@pytest.mark.snapshot(ignores=["meta.error.stack"])
107+
@pytest.mark.snapshot(wait_for_num_traces=1, ignores=["meta.error.stack"])
108108
def test_otel_start_span_ignore_exceptions(caplog, oteltracer):
109109
with pytest.raises(Exception, match="Sorry Otel Span, I failed you"):
110110
with oteltracer.start_span("otel-error-span", record_exception=False, set_status_on_exception=False):
111111
raise Exception("Sorry Otel Span, I failed you")
112112

113113

114-
@pytest.mark.snapshot
114+
@pytest.mark.snapshot(wait_for_num_traces=1)
115115
def test_otel_start_current_span_with_default_args(oteltracer):
116116
with oteltracer.start_as_current_span("test-start-current-span-defaults") as otel_span:
117117
assert otel_span.is_recording()
118118
otel_span.update_name("rename-start-current-span")
119119

120120

121-
@pytest.mark.snapshot
121+
@pytest.mark.snapshot(wait_for_num_traces=1)
122122
def test_otel_start_current_span_without_default_args(oteltracer):
123123
with oteltracer.start_as_current_span("root-span") as root:
124124
with oteltracer.start_as_current_span(
@@ -219,7 +219,10 @@ def otel_flask_app_env(flask_wsgi_application):
219219
"with_opentelemetry_instrument",
220220
],
221221
)
222-
@pytest.mark.snapshot(ignores=["metrics.net.peer.port", "meta.traceparent", "meta.tracestate", "meta.flask.version"])
222+
@pytest.mark.snapshot(
223+
wait_for_num_traces=1,
224+
ignores=["metrics.net.peer.port", "meta.traceparent", "meta.tracestate", "meta.flask.version"],
225+
)
223226
def test_distributed_trace_with_flask_app(flask_client, oteltracer): # noqa:F811
224227
with oteltracer.start_as_current_span("test-otel-distributed-trace") as span:
225228
headers = {}

0 commit comments

Comments
 (0)