Skip to content

Commit 5d62e06

Browse files
tests(integration): separate snapshot tests into own module (#2209)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 2c4e4ce commit 5d62e06

6 files changed

+194
-191
lines changed

tests/integration/test_integration.py

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,14 @@
99
import ddtrace
1010
from ddtrace import Tracer
1111
from ddtrace import tracer
12-
from ddtrace.constants import MANUAL_DROP_KEY
13-
from ddtrace.constants import MANUAL_KEEP_KEY
1412
from ddtrace.internal import agent
1513
from ddtrace.internal.runtime import container
1614
from ddtrace.internal.writer import AgentWriter
17-
from ddtrace.sampler import DatadogSampler
18-
from ddtrace.sampler import RateSampler
19-
from ddtrace.sampler import SamplingRule
2015
from ddtrace.vendor import six
2116
from tests import AnyFloat
2217
from tests import AnyInt
2318
from tests import AnyStr
24-
from tests import TracerTestCase
2519
from tests import override_global_config
26-
from tests import snapshot
2720

2821

2922
AGENT_VERSION = os.environ.get("AGENT_VERSION")
@@ -400,116 +393,6 @@ def test_span_tags():
400393
log.error.assert_not_called()
401394

402395

403-
@pytest.mark.skipif(AGENT_VERSION != "testagent", reason="Tests only compatible with a testagent")
404-
class TestTraces(TracerTestCase):
405-
"""
406-
These snapshot tests ensure that trace payloads are being sent as expected.
407-
"""
408-
409-
@snapshot(include_tracer=True)
410-
def test_single_trace_single_span(self, tracer):
411-
s = tracer.trace("operation", service="my-svc")
412-
s.set_tag("k", "v")
413-
# numeric tag
414-
s.set_tag("num", 1234)
415-
s.set_metric("float_metric", 12.34)
416-
s.set_metric("int_metric", 4321)
417-
s.finish()
418-
tracer.shutdown()
419-
420-
@snapshot(include_tracer=True)
421-
def test_multiple_traces(self, tracer):
422-
with tracer.trace("operation1", service="my-svc") as s:
423-
s.set_tag("k", "v")
424-
s.set_tag("num", 1234)
425-
s.set_metric("float_metric", 12.34)
426-
s.set_metric("int_metric", 4321)
427-
tracer.trace("child").finish()
428-
429-
with tracer.trace("operation2", service="my-svc") as s:
430-
s.set_tag("k", "v")
431-
s.set_tag("num", 1234)
432-
s.set_metric("float_metric", 12.34)
433-
s.set_metric("int_metric", 4321)
434-
tracer.trace("child").finish()
435-
tracer.shutdown()
436-
437-
@snapshot(include_tracer=True)
438-
def test_filters(self, tracer):
439-
class FilterMutate(object):
440-
def __init__(self, key, value):
441-
self.key = key
442-
self.value = value
443-
444-
def process_trace(self, trace):
445-
for s in trace:
446-
s.set_tag(self.key, self.value)
447-
return trace
448-
449-
tracer.configure(
450-
settings={
451-
"FILTERS": [FilterMutate("boop", "beep")],
452-
},
453-
writer=tracer.writer,
454-
)
455-
456-
with tracer.trace("root"):
457-
with tracer.trace("child"):
458-
pass
459-
tracer.shutdown()
460-
461-
@snapshot(include_tracer=True)
462-
def test_sampling(self, tracer):
463-
with tracer.trace("trace1"):
464-
with tracer.trace("child"):
465-
pass
466-
467-
sampler = DatadogSampler(default_sample_rate=1.0)
468-
tracer.configure(sampler=sampler, writer=tracer.writer)
469-
with tracer.trace("trace2"):
470-
with tracer.trace("child"):
471-
pass
472-
473-
sampler = DatadogSampler(default_sample_rate=0.000001)
474-
tracer.configure(sampler=sampler, writer=tracer.writer)
475-
with tracer.trace("trace3"):
476-
with tracer.trace("child"):
477-
pass
478-
479-
sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(1.0)])
480-
tracer.configure(sampler=sampler, writer=tracer.writer)
481-
with tracer.trace("trace4"):
482-
with tracer.trace("child"):
483-
pass
484-
485-
sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(0)])
486-
tracer.configure(sampler=sampler, writer=tracer.writer)
487-
with tracer.trace("trace5"):
488-
with tracer.trace("child"):
489-
pass
490-
491-
sampler = DatadogSampler(default_sample_rate=1)
492-
tracer.configure(sampler=sampler, writer=tracer.writer)
493-
with tracer.trace("trace6"):
494-
with tracer.trace("child") as span:
495-
span.set_tag(MANUAL_DROP_KEY)
496-
497-
sampler = DatadogSampler(default_sample_rate=1)
498-
tracer.configure(sampler=sampler, writer=tracer.writer)
499-
with tracer.trace("trace7"):
500-
with tracer.trace("child") as span:
501-
span.set_tag(MANUAL_KEEP_KEY)
502-
503-
sampler = RateSampler(0.0000000001)
504-
tracer.configure(sampler=sampler, writer=tracer.writer)
505-
# This trace should not appear in the snapshot
506-
with tracer.trace("trace8"):
507-
with tracer.trace("child"):
508-
pass
509-
510-
tracer.shutdown()
511-
512-
513396
@pytest.mark.skipif(AGENT_VERSION == "testagent", reason="Test agent doesn't support empty trace payloads.")
514397
def test_flush_log(caplog):
515398
caplog.set_level(logging.INFO)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import pytest
2+
3+
from ddtrace.constants import MANUAL_DROP_KEY
4+
from ddtrace.constants import MANUAL_KEEP_KEY
5+
from ddtrace.sampler import DatadogSampler
6+
from ddtrace.sampler import RateSampler
7+
from ddtrace.sampler import SamplingRule
8+
from tests import snapshot
9+
10+
from .test_integration import AGENT_VERSION
11+
12+
13+
pytestmark = pytest.mark.skipif(AGENT_VERSION != "testagent", reason="Tests only compatible with a testagent")
14+
15+
16+
@snapshot(include_tracer=True)
17+
def test_single_trace_single_span(tracer):
18+
s = tracer.trace("operation", service="my-svc")
19+
s.set_tag("k", "v")
20+
# numeric tag
21+
s.set_tag("num", 1234)
22+
s.set_metric("float_metric", 12.34)
23+
s.set_metric("int_metric", 4321)
24+
s.finish()
25+
tracer.shutdown()
26+
27+
28+
@snapshot(include_tracer=True)
29+
def test_multiple_traces(tracer):
30+
with tracer.trace("operation1", service="my-svc") as s:
31+
s.set_tag("k", "v")
32+
s.set_tag("num", 1234)
33+
s.set_metric("float_metric", 12.34)
34+
s.set_metric("int_metric", 4321)
35+
tracer.trace("child").finish()
36+
37+
with tracer.trace("operation2", service="my-svc") as s:
38+
s.set_tag("k", "v")
39+
s.set_tag("num", 1234)
40+
s.set_metric("float_metric", 12.34)
41+
s.set_metric("int_metric", 4321)
42+
tracer.trace("child").finish()
43+
tracer.shutdown()
44+
45+
46+
@snapshot(include_tracer=True)
47+
def test_filters(tracer):
48+
class FilterMutate(object):
49+
def __init__(self, key, value):
50+
self.key = key
51+
self.value = value
52+
53+
def process_trace(self, trace):
54+
for s in trace:
55+
s.set_tag(self.key, self.value)
56+
return trace
57+
58+
tracer.configure(
59+
settings={
60+
"FILTERS": [FilterMutate("boop", "beep")],
61+
},
62+
writer=tracer.writer,
63+
)
64+
65+
with tracer.trace("root"):
66+
with tracer.trace("child"):
67+
pass
68+
tracer.shutdown()
69+
70+
71+
@snapshot(include_tracer=True)
72+
def test_sampling(tracer):
73+
with tracer.trace("trace1"):
74+
with tracer.trace("child"):
75+
pass
76+
77+
sampler = DatadogSampler(default_sample_rate=1.0)
78+
tracer.configure(sampler=sampler, writer=tracer.writer)
79+
with tracer.trace("trace2"):
80+
with tracer.trace("child"):
81+
pass
82+
83+
sampler = DatadogSampler(default_sample_rate=0.000001)
84+
tracer.configure(sampler=sampler, writer=tracer.writer)
85+
with tracer.trace("trace3"):
86+
with tracer.trace("child"):
87+
pass
88+
89+
sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(1.0)])
90+
tracer.configure(sampler=sampler, writer=tracer.writer)
91+
with tracer.trace("trace4"):
92+
with tracer.trace("child"):
93+
pass
94+
95+
sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(0)])
96+
tracer.configure(sampler=sampler, writer=tracer.writer)
97+
with tracer.trace("trace5"):
98+
with tracer.trace("child"):
99+
pass
100+
101+
sampler = DatadogSampler(default_sample_rate=1)
102+
tracer.configure(sampler=sampler, writer=tracer.writer)
103+
with tracer.trace("trace6"):
104+
with tracer.trace("child") as span:
105+
span.set_tag(MANUAL_DROP_KEY)
106+
107+
sampler = DatadogSampler(default_sample_rate=1)
108+
tracer.configure(sampler=sampler, writer=tracer.writer)
109+
with tracer.trace("trace7"):
110+
with tracer.trace("child") as span:
111+
span.set_tag(MANUAL_KEEP_KEY)
112+
113+
sampler = RateSampler(0.0000000001)
114+
tracer.configure(sampler=sampler, writer=tracer.writer)
115+
# This trace should not appear in the snapshot
116+
with tracer.trace("trace8"):
117+
with tracer.trace("child"):
118+
pass
119+
120+
tracer.shutdown()

tests/snapshots/tests.integration.test_integration.test_filters.snap renamed to tests/snapshots/tests.integration.test_integration_snapshots.test_filters.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
"span_id" 0
66
"trace_id" 0
77
"parent_id" nil
8-
"start" 1603750872873401000
9-
"duration" 140000
10-
"meta" {"runtime-id" "3069ce0f5ace427ab66cb89c9161a4ae"
8+
"start" 1616457150171098000
9+
"duration" 43000
10+
"meta" {"runtime-id" "ddf562510b004d60bdfaa21911ab1e60"
1111
"boop" "beep"}
1212
"metrics" {"_dd.agent_psr" 1.0
1313
"_sampling_priority_v1" 1
14-
"_dd.tracer_kr" 1.0
15-
"system.pid" 42296}}
14+
"system.pid" 39631
15+
"_dd.tracer_kr" 1.0}}
1616
{"name" "child"
1717
"service" nil
1818
"resource" "child"
1919
"error" 0
2020
"span_id" 1
2121
"trace_id" 0
2222
"parent_id" 0
23-
"start" 1603750872873519000
24-
"duration" 9000
23+
"start" 1616457150171130000
24+
"duration" 7000
2525
"meta" {"boop" "beep"}}]]

tests/snapshots/tests.integration.test_integration.test_multiple_traces.snap renamed to tests/snapshots/tests.integration.test_integration_snapshots.test_multiple_traces.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@
55
"span_id" 0
66
"trace_id" 0
77
"parent_id" nil
8-
"start" 1603750872929188000
9-
"duration" 334000
10-
"meta" {"runtime-id" "3069ce0f5ace427ab66cb89c9161a4ae"
8+
"start" 1616457150152653000
9+
"duration" 54000
10+
"meta" {"runtime-id" "ddf562510b004d60bdfaa21911ab1e60"
1111
"k" "v"}
1212
"metrics" {"_dd.agent_psr" 1.0
1313
"_sampling_priority_v1" 1
14+
"system.pid" 39631
15+
"int_metric" 4321
1416
"_dd.tracer_kr" 1.0
15-
"system.pid" 42296
16-
"num" 1234
1717
"float_metric" 12.34
18-
"int_metric" 4321}}
18+
"num" 1234}}
1919
{"name" "child"
2020
"service" "my-svc"
2121
"resource" "child"
2222
"error" 0
2323
"span_id" 1
2424
"trace_id" 0
2525
"parent_id" 0
26-
"start" 1603750872929503000
27-
"duration" 10000}]
26+
"start" 1616457150152696000
27+
"duration" 7000}]
2828
[{"name" "operation2"
2929
"service" "my-svc"
3030
"resource" "operation2"
3131
"error" 0
3232
"span_id" 0
3333
"trace_id" 1
3434
"parent_id" nil
35-
"start" 1603750872929712000
36-
"duration" 36000
37-
"meta" {"runtime-id" "3069ce0f5ace427ab66cb89c9161a4ae"
35+
"start" 1616457150152832000
36+
"duration" 46000
37+
"meta" {"runtime-id" "ddf562510b004d60bdfaa21911ab1e60"
3838
"k" "v"}
3939
"metrics" {"_dd.agent_psr" 1.0
4040
"_sampling_priority_v1" 1
41+
"system.pid" 39631
42+
"int_metric" 4321
4143
"_dd.tracer_kr" 1.0
42-
"system.pid" 42296
43-
"num" 1234
4444
"float_metric" 12.34
45-
"int_metric" 4321}}
45+
"num" 1234}}
4646
{"name" "child"
4747
"service" "my-svc"
4848
"resource" "child"
4949
"error" 0
5050
"span_id" 1
5151
"trace_id" 1
5252
"parent_id" 0
53-
"start" 1603750872929740000
54-
"duration" 4000}]]
53+
"start" 1616457150152868000
54+
"duration" 6000}]]

0 commit comments

Comments
 (0)