Skip to content

Commit ca1a204

Browse files
authored
Merge branch 'munir/make-tracer-a-singleton-2' into munir/remove-deprecations-from-pin
2 parents ce46449 + 0b503b9 commit ca1a204

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
lines changed

Diff for: ddtrace/_trace/tracer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(
216216
if Tracer._instance is None:
217217
Tracer._instance = self
218218
else:
219-
raise ValueError(
219+
log.error(
220220
"Multiple Tracer instances can not be initialized. Use ``ddtrace.trace.tracer`` instead.",
221221
)
222222

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---
22
upgrade:
33
- |
4-
tracing: Drops support for multiple Tracer instances in the same process. Use ``ddtrace.trace.tracer`` to access the global tracer instance.
5-
- |
6-
pin: Removes the ``tracer`` parameter from ``ddtrace.trace.Pin`` methods. All Pin objects now use the global tracer instance.
4+
tracing: Drops support for multiple Tracer instances in the same process. Use ``ddtrace.trace.tracer`` to access the global tracer instance.

Diff for: tests/contrib/kafka/test_kafka.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ddtrace.internal.utils.retry import fibonacci_backoff_with_jitter
2323
from ddtrace.trace import Pin
2424
from ddtrace.trace import TraceFilter
25-
from ddtrace.trace import tracer as ddtracer
25+
from ddtrace.trace import Tracer
2626
from tests.contrib.config import KAFKA_CONFIG
2727
from tests.datastreams.test_public_api import MockedTracer
2828
from tests.utils import DummyTracer
@@ -106,16 +106,16 @@ def should_filter_empty_polls():
106106
@pytest.fixture
107107
def tracer(should_filter_empty_polls):
108108
patch()
109+
t = Tracer()
109110
if should_filter_empty_polls:
110-
ddtracer.configure(trace_processors=[KafkaConsumerPollFilter()])
111+
t._configure(trace_processors=[KafkaConsumerPollFilter()])
111112
# disable backoff because it makes these tests less reliable
112-
previous_backoff = ddtracer._writer._send_payload_with_backoff
113-
ddtracer._writer._send_payload_with_backoff = ddtracer._writer._send_payload
113+
t._writer._send_payload_with_backoff = t._writer._send_payload
114114
try:
115-
yield ddtracer
115+
yield t
116116
finally:
117-
ddtracer.flush()
118-
ddtracer._writer._send_payload_with_backoff = previous_backoff
117+
t.flush()
118+
t.shutdown()
119119
unpatch()
120120

121121

@@ -124,8 +124,6 @@ def dsm_processor(tracer):
124124
processor = tracer.data_streams_processor
125125
with mock.patch("ddtrace.internal.datastreams.data_streams_processor", return_value=processor):
126126
yield processor
127-
# flush buckets for the next test run
128-
processor.periodic()
129127

130128

131129
@pytest.fixture
@@ -327,7 +325,6 @@ def test_commit_with_consume_with_multiple_messages(producer, consumer, kafka_to
327325

328326
@pytest.mark.snapshot(ignores=SNAPSHOT_IGNORES)
329327
@pytest.mark.parametrize("should_filter_empty_polls", [False])
330-
@pytest.mark.skip(reason="FIXME: This test requires the initialization of a new tracer. This is not supported")
331328
def test_commit_with_consume_with_error(producer, consumer, kafka_topic):
332329
producer.produce(kafka_topic, PAYLOAD, key=KEY)
333330
producer.flush()

Diff for: tests/tracer/test_memory_leak.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
"""
22
Variety of test cases ensuring that ddtrace does not leak memory.
33
"""
4-
from typing import TYPE_CHECKING
54
from weakref import WeakValueDictionary
65

76
import pytest
87

8+
from ddtrace.trace import Span
9+
from ddtrace.trace import Tracer
910
from tests.utils import DummyTracer
1011

1112

12-
if TYPE_CHECKING: # pragma: no cover
13-
from ddtrace.trace import Span # noqa:F401
14-
15-
1613
@pytest.fixture
1714
def tracer() -> DummyTracer:
1815
return DummyTracer()
1916

2017

21-
def trace(weakdict: WeakValueDictionary, tracer, *args, **kwargs):
22-
# type: (...) -> Span
18+
def trace(weakdict: WeakValueDictionary, tracer: Tracer, *args, **kwargs) -> Span:
2319
"""Return a span created from ``tracer`` and add it to the given weak
2420
dictionary.
2521

Diff for: tests/tracer/test_processors.py

-5
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ def test_trace_top_level_span_processor_same_service_name():
271271
"""Parent span and child span have the same service name"""
272272

273273
tracer = DummyTracer()
274-
tracer._configure(writer=DummyWriter())
275274

276275
with tracer.trace("parent", service="top_level_test") as parent:
277276
with tracer.trace("child") as child:
@@ -285,7 +284,6 @@ def test_trace_top_level_span_processor_different_service_name():
285284
"""Parent span and child span have the different service names"""
286285

287286
tracer = DummyTracer()
288-
tracer._configure(writer=DummyWriter())
289287

290288
with tracer.trace("parent", service="top_level_test_service") as parent:
291289
with tracer.trace("child", service="top_level_test_service2") as child:
@@ -299,7 +297,6 @@ def test_trace_top_level_span_processor_orphan_span():
299297
"""Trace chuck does not contain parent span"""
300298

301299
tracer = DummyTracer()
302-
tracer._configure(writer=DummyWriter())
303300

304301
with tracer.trace("parent") as parent:
305302
pass
@@ -633,7 +630,6 @@ def test_endpoint_call_counter_processor_disabled():
633630
def test_endpoint_call_counter_processor_real_tracer():
634631
tracer = DummyTracer()
635632
tracer._endpoint_call_counter_span_processor.enable()
636-
tracer._configure(writer=DummyWriter())
637633

638634
with tracer.trace("parent", service="top_level_test_service", resource="a", span_type=SpanTypes.WEB):
639635
with tracer.trace("child", service="top_level_test_service2"):
@@ -656,7 +652,6 @@ def test_endpoint_call_counter_processor_real_tracer():
656652

657653
def test_trace_tag_processor_adds_chunk_root_tags():
658654
tracer = DummyTracer()
659-
tracer._configure(writer=DummyWriter())
660655

661656
with tracer.trace("parent") as parent:
662657
with tracer.trace("child") as child:

Diff for: tests/tracer/test_single_span_sampling_rules.py

-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from ddtrace.internal.sampling import _get_file_json
1212
from ddtrace.internal.sampling import get_span_sampling_rules
1313
from tests.utils import DummyTracer
14-
from tests.utils import DummyWriter
1514

1615
from ..utils import override_global_config
1716

@@ -129,7 +128,6 @@ def test_env_rules_cause_matching_span_to_be_sampled():
129128
assert sampling_rules[0]._service_matcher.pattern == "test_service"
130129
assert sampling_rules[0]._name_matcher.pattern == "test_name"
131130
tracer = DummyTracer()
132-
tracer._configure(writer=DummyWriter())
133131
span = traced_function(sampling_rules[0], tracer=tracer)
134132
assert_sampling_decision_tags(span)
135133

@@ -141,7 +139,6 @@ def test_env_rules_dont_cause_non_matching_span_to_be_sampled():
141139
assert sampling_rules[0]._service_matcher.pattern == "test_ser"
142140
assert sampling_rules[0]._name_matcher.pattern == "test_na"
143141
tracer = DummyTracer()
144-
tracer._configure(writer=DummyWriter())
145142
span = traced_function(sampling_rules[0], tracer=tracer)
146143
assert_sampling_decision_tags(span, sample_rate=None, mechanism=None, limit=None)
147144

@@ -153,7 +150,6 @@ def test_single_span_rules_not_applied_when_span_sampled_by_trace_sampling():
153150
assert sampling_rules[0]._service_matcher.pattern == "test_service"
154151
assert sampling_rules[0]._name_matcher.pattern == "test_name"
155152
tracer = DummyTracer()
156-
tracer._configure(writer=DummyWriter())
157153
span = traced_function(sampling_rules[0], tracer=tracer, trace_sampling=True)
158154
assert sampling_rules[0].match(span) is True
159155
assert_sampling_decision_tags(span, sample_rate=None, mechanism=None, limit=None, trace_sampling=True)

Diff for: tests/tracer/test_tracer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1994,10 +1994,13 @@ def mock_os_path_exists(path):
19941994

19951995
@pytest.mark.subprocess()
19961996
def test_multiple_tracer_instances():
1997-
import pytest
1997+
import mock
19981998

19991999
import ddtrace
20002000

20012001
assert ddtrace.trace.tracer is not None
2002-
with pytest.raises(ValueError):
2002+
with mock.patch("ddtrace._trace.tracer.log") as log:
20032003
ddtrace.trace.Tracer()
2004+
log.error.assert_called_once_with(
2005+
"Multiple Tracer instances can not be initialized. " "Use ``ddtrace.trace.tracer`` instead."
2006+
)

0 commit comments

Comments
 (0)