Skip to content

Commit fd8c25a

Browse files
committed
api: simplify _put codepath
The length is always provided and should be included in every request, so make it mandatory. Move the header name variable to the local API class, making it overridable by a subclass — you never know!
1 parent 6321d3c commit fd8c25a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ddtrace/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
log = get_logger(__name__)
1515

16-
TRACE_COUNT_HEADER = 'X-Datadog-Trace-Count'
1716

1817
_VERSIONS = {'v0.4': {'traces': '/v0.4/traces',
1918
'services': '/v0.4/services',
@@ -100,6 +99,9 @@ class API(object):
10099
"""
101100
Send data to the trace agent using the HTTP protocol and JSON format
102101
"""
102+
103+
TRACE_COUNT_HEADER = 'X-Datadog-Trace-Count'
104+
103105
def __init__(self, hostname, port, headers=None, encoder=None, priority_sampling=False):
104106
self.hostname = hostname
105107
self.port = int(port)
@@ -169,14 +171,12 @@ def send_traces(self, traces):
169171
def send_services(self, *args, **kwargs):
170172
return
171173

172-
def _put(self, endpoint, data, count=0):
174+
def _put(self, endpoint, data, count):
175+
headers = self._headers.copy()
176+
headers[self.TRACE_COUNT_HEADER] = str(count)
177+
173178
conn = httplib.HTTPConnection(self.hostname, self.port)
174179
try:
175-
headers = self._headers
176-
if count:
177-
headers = dict(self._headers)
178-
headers[TRACE_COUNT_HEADER] = str(count)
179-
180180
conn.request('PUT', endpoint, data, headers)
181181

182182
# Parse the HTTPResponse into an API.Response

0 commit comments

Comments
 (0)