22import time
33import os
44from blackfire_conprof .profiler import Profiler
5- from ddtrace .settings .profiling import config as profiling_config
65
76from contextlib import contextmanager
87
@@ -34,7 +33,6 @@ def test_profiler_dd_envvars(self):
3433 # ensure os.environ is preserved
3534 self .assertEqual (os .environ ['DD_PROFILING_ENABLED' ], '1' )
3635
37- @unittest .skip (not profiling_config .export .libdd_enabled )
3836 def test_profiler_basic_lib_dd (self ):
3937 class _context :
4038 nexportcalls = 0
@@ -48,24 +46,17 @@ def _upload(*args, **kwargs):
4846 prof .stop ()
4947 self .assertTrue (_context .nexportcalls >= 1 )
5048
51- @unittest .skip (profiling_config .export .libdd_enabled )
5249 def test_profiler_basic (self ):
5350 def foo (t ):
5451 time .sleep (t )
5552
5653 class _context :
5754 nexportcalls = 0
58- def _export (instance , events , start_time_ns , end_time_ns ):
59- from ddtrace .profiling .collector import stack_event
60-
61- stack_events = events .get (stack_event .StackSampleEvent , [])
62-
63- self .assertTrue (len (stack_events ) > 0 )
64- self .assertTrue ('foo' in str (stack_events ))
55+ def _upload (* args , ** kwargs ):
6556 _context .nexportcalls += 1
66-
67- from ddtrace .profiling . exporter import http as dd_http_exporter
68- with _patch (dd_http_exporter . PprofHTTPExporter , "export " , _export ):
57+
58+ from ddtrace .internal . datadog . profiling import ddup
59+ with _patch (ddup , "upload " , _upload ):
6960 prof = Profiler (period = 0.1 )
7061 prof .start ()
7162 foo (0.3 + 0.2 )
@@ -96,24 +87,26 @@ def test_profiler_params(self):
9687 self .assertTrue ('probe_version' in prof ._profiler .tags )
9788 self .assertTrue (prof ._profiler .tags .get ('project_id' ) == 'id-1' )
9889
99- @unittest .skip (profiling_config .export .libdd_enabled )
10090 def test_profiler_creds (self ):
101- def _upload (instance , client , path , body , headers ):
102- self .assertTrue (headers .get ('DD-API-KEY' ).decode ()== 'id-1:token-1' )
91+ class _context :
92+ upload_calls = 0
93+
94+ def _upload (* args , ** kwargs ):
95+ _context .upload_calls += 1
96+
97+ from ddtrace .internal .datadog .profiling import ddup
10398
104- from ddtrace . profiling . exporter import http as dd_http_exporter
105- with _patch (dd_http_exporter . PprofHTTPExporter , "_upload " , _upload ):
99+ # Test with credentials
100+ with _patch (ddup , "upload " , _upload ):
106101 prof = Profiler (server_id = 'id-1' , server_token = 'token-1' , period = 0.1 )
102+ self .assertEqual (prof ._profiler .api_key , 'id-1:token-1' )
107103 prof .start ()
108104 time .sleep (0.2 )
109105 prof .stop ()
110106
111- def _upload2 (instance , client , path , body , headers ):
112- self .assertEqual (headers .get ('DD-API-KEY' ), None )
107+ self .assertGreater (_context .upload_calls , 0 )
113108
114- # no token
115- with _patch (dd_http_exporter .PprofHTTPExporter , "_upload" , _upload2 ):
116- prof = Profiler (server_id = 'id-1' , period = 0.1 )
117- prof .start ()
118- time .sleep (0.2 )
119- prof .stop ()
109+ # Test without token (server_id only)
110+ prof2 = Profiler (server_id = 'id-1' , period = 0.1 )
111+ self .assertEqual (prof2 ._profiler .api_key , '' )
112+ prof2 .stop ()
0 commit comments