Skip to content

Commit ee70598

Browse files
committed
[python-conprof] Upgrade to ddtrace 3.2.1 for Python 3.13
1 parent 1ba5139 commit ee70598

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Diff for: blackfire_conprof/profiler.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
from blackfire_conprof import log
66
from .version import __version__
77

8-
from ddtrace.profiling import Profiler as DDProfiler
9-
log.bridge_ddtrace_logging()
10-
118
_DEFAULT_PERIOD = 45 # secs
129
_DEFAULT_UPLOAD_TIMEOUT = 10 # secs
1310

14-
logger = log.get_logger(__name__)
15-
1611
def _get_default_agent_socket():
1712
plat = platform.system()
1813
if plat == 'Windows':
@@ -81,27 +76,33 @@ def __init__(self, application_name=None, agent_socket=None,
8176
os.environ["DD_PROFILING_UPLOAD_INTERVAL"] = str(period)
8277
os.environ["DD_PROFILING_API_TIMEOUT"] = str(upload_timeout)
8378
os.environ["DD_INSTRUMENTATION_TELEMETRY_ENABLED"] = "False"
79+
os.environ["DD_TRACE_AGENT_URL"] = agent_socket
8480

8581
api_key = ''
8682
if server_id and server_token:
8783
api_key = '%s:%s' % (server_id, server_token)
8884

8985
# if application_name(service) is still None here, DD fills with the
9086
# current running module name
87+
from ddtrace.profiling import Profiler as DDProfiler
9188
self._profiler = DDProfiler(
9289
service=application_name,
9390
tags=labels,
94-
url=agent_socket,
9591
api_key=api_key,
9692
enable_code_provenance=False,
9793
)
9894

95+
# needs to be done after DDProfiler import
96+
log.bridge_ddtrace_logging()
97+
98+
self.logger = log.get_logger(__name__)
99+
99100
def start(self, *args, **kwargs):
100101
self._profiler.start(*args, **kwargs)
101102

102-
logger.info("Started profiling")
103+
self.logger.info("Started profiling")
103104

104105
def stop(self):
105106
self._profiler.stop()
106107

107-
logger.info("Profiling stopped")
108+
self.logger.info("Profiling stopped")

Diff for: setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
author="Blackfire.io",
1616
packages=['blackfire_conprof', 'blackfire_conprof.bootstrap'],
1717
author_email="[email protected]",
18-
install_requires=["ddtrace==2.9.1"],
18+
install_requires=["ddtrace==3.2.1"],
1919
description="Blackfire Continuous Profiler",
2020
long_description=long_description,
2121
long_description_content_type="text/markdown",
@@ -27,7 +27,6 @@
2727
url=HOMEPAGE,
2828
classifiers=[
2929
"Programming Language :: Python",
30-
"Programming Language :: Python :: 3.7",
3130
"Programming Language :: Python :: 3.8",
3231
"Programming Language :: Python :: 3.9",
3332
"Programming Language :: Python :: 3.10",

Diff for: tests/test_profiler.py

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import os
44
from blackfire_conprof.profiler import Profiler
5+
from ddtrace.settings.profiling import config as profiling_config
56

67
from contextlib import contextmanager
78

@@ -33,6 +34,21 @@ def test_profiler_dd_envvars(self):
3334
# ensure os.environ is preserved
3435
self.assertEqual(os.environ['DD_PROFILING_ENABLED'], '1')
3536

37+
@unittest.skip(not profiling_config.export.libdd_enabled)
38+
def test_profiler_basic_lib_dd(self):
39+
class _context:
40+
nexportcalls = 0
41+
def _upload(*args, **kwargs):
42+
_context.nexportcalls += 1
43+
44+
from ddtrace.internal.datadog.profiling import ddup as dd_ddup_exporter
45+
with _patch(dd_ddup_exporter, "upload", _upload):
46+
prof = Profiler(period=0.1)
47+
prof.start()
48+
prof.stop()
49+
self.assertTrue(_context.nexportcalls >= 1)
50+
51+
@unittest.skip(profiling_config.export.libdd_enabled)
3652
def test_profiler_basic(self):
3753
def foo(t):
3854
time.sleep(t)
@@ -80,6 +96,7 @@ def test_profiler_params(self):
8096
self.assertTrue('probe_version' in prof._profiler.tags)
8197
self.assertTrue(prof._profiler.tags.get('project_id') == 'id-1')
8298

99+
@unittest.skip(profiling_config.export.libdd_enabled)
83100
def test_profiler_creds(self):
84101
def _upload(instance, client, path, body, headers):
85102
self.assertTrue(headers.get('DD-API-KEY').decode()=='id-1:token-1')

0 commit comments

Comments
 (0)