Skip to content

Commit b91ce53

Browse files
committed
Merge branch 'maxday/change-version-detection-mecanism' of github.com:DataDog/dd-trace-py into maxday/change-version-detection-mecanism
2 parents a0f59ff + a1b6ac4 commit b91ce53

File tree

6 files changed

+56
-26
lines changed

6 files changed

+56
-26
lines changed

ddtrace/internal/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from typing import TYPE_CHECKING
99
from typing import Union
1010

11-
import pkg_resources
12-
1311
import ddtrace
1412
from ddtrace.internal.writer import AgentWriter
1513
from ddtrace.internal.writer import LogWriter
@@ -45,6 +43,8 @@ def collect(tracer):
4543
# type: (Tracer) -> Dict[str, Any]
4644
"""Collect system and library information into a serializable dict."""
4745

46+
import pkg_resources
47+
4848
if isinstance(tracer.writer, LogWriter):
4949
agent_url = "AGENTLESS"
5050
agent_error = None

ddtrace/pin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _find(*objs):
9898

9999
@staticmethod
100100
def get_from(obj):
101-
# type: (Any) -> Pin
101+
# type: (Any) -> Optional[Pin]
102102
"""Return the pin associated with the given object. If a pin is attached to
103103
`obj` but the instance is not the owner of the pin, a new pin is cloned and
104104
attached. This ensures that a pin inherited from a class is a copy for the new
@@ -147,7 +147,7 @@ def override(
147147
return
148148

149149
pin = cls.get_from(obj)
150-
if not pin:
150+
if pin is None:
151151
pin = Pin(service)
152152

153153
pin.clone(

ddtrace/tracer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from ddtrace import config
1919
from ddtrace.filters import TraceFilter
20+
from ddtrace.utils.deprecation import deprecation
2021
from ddtrace.vendor import debtcollector
2122

2223
from . import _hooks
@@ -143,10 +144,21 @@ def __init__(
143144
sync_mode=self._use_sync_mode(),
144145
)
145146
self.writer = writer # type: TraceWriter
146-
self._partial_flush_enabled = asbool(get_env("tracer", "partial_flush_enabled", default=False))
147+
148+
# DD_TRACER_... should be deprecated after version 1.0.0 is released
149+
pfe_default_value = False
150+
pfms_default_value = 500
151+
if "DD_TRACER_PARTIAL_FLUSH_ENABLED" in os.environ or "DD_TRACER_PARTIAL_FLUSH_MIN_SPANS" in os.environ:
152+
deprecation("DD_TRACER_... use DD_TRACE_... instead", version="1.0.0")
153+
pfe_default_value = asbool(get_env("tracer", "partial_flush_enabled", default=pfe_default_value))
154+
pfms_default_value = int(
155+
get_env("tracer", "partial_flush_min_spans", default=pfms_default_value) # type: ignore[arg-type]
156+
)
157+
self._partial_flush_enabled = asbool(get_env("trace", "partial_flush_enabled", default=pfe_default_value))
147158
self._partial_flush_min_spans = int(
148-
get_env("tracer", "partial_flush_min_spans", default=500) # type: ignore[arg-type]
159+
get_env("trace", "partial_flush_min_spans", default=pfms_default_value) # type: ignore[arg-type]
149160
)
161+
150162
self._initialize_span_processors()
151163
self._hooks = _hooks.Hooks()
152164
atexit.register(self._atexit)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
upgrade:
3+
- |
4+
Replace DD_TRACER_PARTIAL_FLUSH_ENABLED with DD_TRACE_PARTIAL_FLUSH_ENABLED
5+
Replace DD_TRACER_PARTIAL_FLUSH_MIN_SPANS with DD_TRACE_PARTIAL_FLUSH_MIN_SPANS
6+
deprecations:
7+
- |
8+
The DD_TRACER_PARTIAL_FLUSH_ENABLED and DD_TRACER_PARTIAL_FLUSH_MIN_SPANS environment variables have been deprecated and will be removed in version 1.0 of the library.

tests/integration/test_debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ def test_partial_flush_log(run_python_code_in_subprocess):
391391

392392
partial_flush_min_spans = "2"
393393
env = os.environ.copy()
394-
env["DD_TRACER_PARTIAL_FLUSH_ENABLED"] = "true"
395-
env["DD_TRACER_PARTIAL_FLUSH_MIN_SPANS"] = partial_flush_min_spans
394+
env["DD_TRACE_PARTIAL_FLUSH_ENABLED"] = "true"
395+
env["DD_TRACE_PARTIAL_FLUSH_MIN_SPANS"] = partial_flush_min_spans
396396

397397
out, err, status, pid = run_python_code_in_subprocess(
398398
"""

tests/tracer/test_tracer.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,26 +1140,13 @@ def test_early_exit(tracer, test_spans):
11401140

11411141
class TestPartialFlush(TracerTestCase):
11421142
@TracerTestCase.run_in_subprocess(
1143-
env_overrides=dict(DD_TRACER_PARTIAL_FLUSH_ENABLED="true", DD_TRACER_PARTIAL_FLUSH_MIN_SPANS="5")
1143+
env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="5")
11441144
)
11451145
def test_partial_flush(self):
1146-
root = self.tracer.trace("root")
1147-
for i in range(5):
1148-
self.tracer.trace("child%s" % i).finish()
1149-
1150-
traces = self.pop_traces()
1151-
assert len(traces) == 1
1152-
assert len(traces[0]) == 5
1153-
assert [s.name for s in traces[0]] == ["child0", "child1", "child2", "child3", "child4"]
1154-
1155-
root.finish()
1156-
traces = self.pop_traces()
1157-
assert len(traces) == 1
1158-
assert len(traces[0]) == 1
1159-
assert traces[0][0].name == "root"
1146+
self._test_partial_flush()
11601147

11611148
@TracerTestCase.run_in_subprocess(
1162-
env_overrides=dict(DD_TRACER_PARTIAL_FLUSH_ENABLED="true", DD_TRACER_PARTIAL_FLUSH_MIN_SPANS="1")
1149+
env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="1")
11631150
)
11641151
def test_partial_flush_too_many(self):
11651152
root = self.tracer.trace("root")
@@ -1180,7 +1167,7 @@ def test_partial_flush_too_many(self):
11801167
assert traces[0][0].name == "root"
11811168

11821169
@TracerTestCase.run_in_subprocess(
1183-
env_overrides=dict(DD_TRACER_PARTIAL_FLUSH_ENABLED="true", DD_TRACER_PARTIAL_FLUSH_MIN_SPANS="6")
1170+
env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="true", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="6")
11841171
)
11851172
def test_partial_flush_too_few(self):
11861173
root = self.tracer.trace("root")
@@ -1207,12 +1194,35 @@ def test_partial_flush_too_few_configure(self):
12071194
self.test_partial_flush_too_few()
12081195

12091196
@TracerTestCase.run_in_subprocess(
1210-
env_overrides=dict(DD_TRACER_PARTIAL_FLUSH_ENABLED="false", DD_TRACER_PARTIAL_FLUSH_MIN_SPANS="6")
1197+
env_overrides=dict(DD_TRACE_PARTIAL_FLUSH_ENABLED="false", DD_TRACE_PARTIAL_FLUSH_MIN_SPANS="6")
12111198
)
12121199
def test_partial_flush_configure_precedence(self):
12131200
self.tracer.configure(partial_flush_enabled=True, partial_flush_min_spans=5)
12141201
self.test_partial_flush()
12151202

1203+
@TracerTestCase.run_in_subprocess(
1204+
env_overrides=dict(DD_TRACER_PARTIAL_FLUSH_ENABLED="true", DD_TRACER_PARTIAL_FLUSH_MIN_SPANS="5")
1205+
)
1206+
def test_enable_partial_flush_with_deprecated_config(self):
1207+
# Test tracer with deprecated configs D_TRACER_...
1208+
self._test_partial_flush()
1209+
1210+
def _test_partial_flush(self):
1211+
root = self.tracer.trace("root")
1212+
for i in range(5):
1213+
self.tracer.trace("child%s" % i).finish()
1214+
1215+
traces = self.pop_traces()
1216+
assert len(traces) == 1
1217+
assert len(traces[0]) == 5
1218+
assert [s.name for s in traces[0]] == ["child0", "child1", "child2", "child3", "child4"]
1219+
1220+
root.finish()
1221+
traces = self.pop_traces()
1222+
assert len(traces) == 1
1223+
assert len(traces[0]) == 1
1224+
assert traces[0][0].name == "root"
1225+
12161226

12171227
def test_unicode_config_vals():
12181228
t = ddtrace.Tracer()

0 commit comments

Comments
 (0)