44import msgpack
55import logging
66import mock
7+ import ddtrace
78
89from unittest import TestCase , skipUnless
910from nose .tools import eq_ , ok_
1516from ddtrace .span import Span
1617from ddtrace .tracer import Tracer
1718from ddtrace .encoding import JSONEncoder , MsgpackEncoder , get_encoder
18- from ddtrace .compat import httplib
19+ from ddtrace .compat import httplib , PYTHON_INTERPRETER , PYTHON_VERSION
1920from tests .test_tracer import get_dummy_tracer
2021
2122
22-
2323class MockedLogHandler (logging .Handler ):
2424 """Record log messages to verify error logging logic"""
2525
@@ -257,10 +257,19 @@ def test_send_presampler_headers(self, mocked_http):
257257 eq_ (request_call .call_count , 1 )
258258
259259 # retrieve the headers from the mocked request call
260+ expected_headers = {
261+ 'Datadog-Meta-Lang' : 'python' ,
262+ 'Datadog-Meta-Lang-Interpreter' : PYTHON_INTERPRETER ,
263+ 'Datadog-Meta-Lang-Version' : PYTHON_VERSION ,
264+ 'Datadog-Meta-Tracer-Version' : ddtrace .__version__ ,
265+ 'X-Datadog-Trace-Count' : '1' ,
266+ 'Content-Type' : 'application/msgpack'
267+ }
260268 params , _ = request_call .call_args_list [0 ]
261269 headers = params [3 ]
262- ok_ ('X-Datadog-Trace-Count' in headers .keys ())
263- eq_ (headers ['X-Datadog-Trace-Count' ], '1' )
270+ eq_ (len (expected_headers ), len (headers ))
271+ for k , v in expected_headers .items ():
272+ eq_ (v , headers [k ])
264273
265274 @mock .patch ('ddtrace.api.httplib.HTTPConnection' )
266275 def test_send_presampler_headers_not_in_services (self , mocked_http ):
@@ -277,6 +286,20 @@ def test_send_presampler_headers_not_in_services(self, mocked_http):
277286 request_call = mocked_http .return_value .request
278287 eq_ (request_call .call_count , 1 )
279288
289+ # retrieve the headers from the mocked request call
290+ expected_headers = {
291+ 'Datadog-Meta-Lang' : 'python' ,
292+ 'Datadog-Meta-Lang-Interpreter' : PYTHON_INTERPRETER ,
293+ 'Datadog-Meta-Lang-Version' : PYTHON_VERSION ,
294+ 'Datadog-Meta-Tracer-Version' : ddtrace .__version__ ,
295+ 'Content-Type' : 'application/msgpack'
296+ }
297+ params , _ = request_call .call_args_list [0 ]
298+ headers = params [3 ]
299+ eq_ (len (expected_headers ), len (headers ))
300+ for k , v in expected_headers .items ():
301+ eq_ (v , headers [k ])
302+
280303 # retrieve the headers from the mocked request call
281304 params , _ = request_call .call_args_list [0 ]
282305 headers = params [3 ]
0 commit comments