Skip to content

Commit 8093e9d

Browse files
author
Peter Giacomo Lombardo
authored
Custom Headers: Fix report format (#290)
* Custom Headers: Fix report format * Update tests and fix key name * Remove debug remnants; Fix long tail
1 parent 65eadeb commit 8093e9d

21 files changed

+59
-50
lines changed

instana/instrumentation/aiohttp/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def stan_request_end(session, trace_config_ctx, params):
4444
if agent.options.extra_http_headers is not None:
4545
for custom_header in agent.options.extra_http_headers:
4646
if custom_header in params.response.headers:
47-
scope.span.set_tag("http.%s" % custom_header, params.response.headers[custom_header])
47+
scope.span.set_tag("http.header.%s" % custom_header, params.response.headers[custom_header])
4848

4949
if 500 <= params.response.status <= 599:
5050
scope.span.mark_as_errored({"http.error": params.response.reason})

instana/instrumentation/aiohttp/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def stan_middleware(request, handler):
3737
if agent.options.extra_http_headers is not None:
3838
for custom_header in agent.options.extra_http_headers:
3939
if custom_header in request.headers:
40-
scope.span.set_tag("http.%s" % custom_header, request.headers[custom_header])
40+
scope.span.set_tag("http.header.%s" % custom_header, request.headers[custom_header])
4141

4242
response = None
4343
try:

instana/instrumentation/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _extract_custom_headers(self, span, headers):
2020
# Headers are in the following format: b'x-header-1'
2121
for header_pair in headers:
2222
if header_pair[0].decode('utf-8').lower() == custom_header.lower():
23-
span.set_tag("http.%s" % custom_header, header_pair[1].decode('utf-8'))
23+
span.set_tag("http.header.%s" % custom_header, header_pair[1].decode('utf-8'))
2424
except Exception:
2525
logger.debug("extract_custom_headers: ", exc_info=True)
2626

instana/instrumentation/aws/triggers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def capture_extra_headers(event, span, extra_headers):
125125
for custom_header in extra_headers:
126126
for key in event_headers:
127127
if key.lower() == custom_header.lower():
128-
span.set_tag("http.%s" % custom_header, event_headers[key])
128+
span.set_tag("http.header.%s" % custom_header, event_headers[key])
129129
except Exception:
130130
logger.debug("capture_extra_headers: ", exc_info=True)
131131

instana/instrumentation/django/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def process_request(self, request):
3737
# Headers are available in this format: HTTP_X_CAPTURE_THIS
3838
django_header = ('HTTP_' + custom_header.upper()).replace('-', '_')
3939
if django_header in env:
40-
request.iscope.span.set_tag("http.%s" % custom_header, env[django_header])
40+
request.iscope.span.set_tag("http.header.%s" % custom_header, env[django_header])
4141

4242
request.iscope.span.set_tag(ext.HTTP_METHOD, request.method)
4343
if 'PATH_INFO' in env:

instana/instrumentation/flask/vanilla.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def before_request_with_instana(*argv, **kwargs):
3030
# Headers are available in this format: HTTP_X_CAPTURE_THIS
3131
header = ('HTTP_' + custom_header.upper()).replace('-', '_')
3232
if header in env:
33-
span.set_tag("http.%s" % custom_header, env[header])
33+
span.set_tag("http.header.%s" % custom_header, env[header])
3434

3535
span.set_tag(ext.HTTP_METHOD, flask.request.method)
3636
if 'PATH_INFO' in env:

instana/instrumentation/flask/with_blinker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def request_started_with_instana(sender, **extra):
3131
# Headers are available in this format: HTTP_X_CAPTURE_THIS
3232
header = ('HTTP_' + custom_header.upper()).replace('-', '_')
3333
if header in env:
34-
span.set_tag("http.%s" % custom_header, env[header])
34+
span.set_tag("http.header.%s" % custom_header, env[header])
3535

3636
span.set_tag(ext.HTTP_METHOD, flask.request.method)
3737
if 'PATH_INFO' in env:

instana/instrumentation/pyramid/tweens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __call__(self, request):
3333
# Headers are available in this format: HTTP_X_CAPTURE_THIS
3434
h = ('HTTP_' + custom_header.upper()).replace('-', '_')
3535
if h in request.headers:
36-
scope.span.set_tag("http.%s" % custom_header, request.headers[h])
36+
scope.span.set_tag("http.header.%s" % custom_header, request.headers[h])
3737

3838
if len(request.query_string):
3939
scrubbed_params = strip_secrets_from_query(request.query_string, agent.options.secrets_matcher, agent.options.secrets_list)

instana/instrumentation/tornado/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def execute_with_instana(wrapped, instance, argv, kwargs):
4444
if agent.options.extra_http_headers is not None:
4545
for custom_header in agent.options.extra_http_headers:
4646
if custom_header in instance.request.headers:
47-
scope.span.set_tag("http.%s" % custom_header, instance.request.headers[custom_header])
47+
scope.span.set_tag("http.header.%s" % custom_header, instance.request.headers[custom_header])
4848

4949
setattr(instance.request, "_instana", scope)
5050

instana/instrumentation/urllib3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def collect_response(scope, response):
5151
if agent.options.extra_http_headers is not None:
5252
for custom_header in agent.options.extra_http_headers:
5353
if custom_header in response.headers:
54-
scope.span.set_tag("http.%s" % custom_header, response.headers[custom_header])
54+
scope.span.set_tag("http.header.%s" % custom_header, response.headers[custom_header])
5555

5656
if 500 <= response.status <= 599:
5757
scope.span.mark_as_errored()

instana/instrumentation/webapp2_inst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def new_start_response(status, headers, exc_info=None):
4646
# Headers are available in this format: HTTP_X_CAPTURE_THIS
4747
wsgi_header = ('HTTP_' + custom_header.upper()).replace('-', '_')
4848
if wsgi_header in env:
49-
scope.span.set_tag("http.%s" % custom_header, env[wsgi_header])
49+
scope.span.set_tag("http.header.%s" % custom_header, env[wsgi_header])
5050

5151
if 'PATH_INFO' in env:
5252
scope.span.set_tag('http.path', env['PATH_INFO'])

instana/instrumentation/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def new_start_response(status, headers, exc_info=None):
4040
# Headers are available in this format: HTTP_X_CAPTURE_THIS
4141
wsgi_header = ('HTTP_' + custom_header.upper()).replace('-', '_')
4242
if wsgi_header in env:
43-
self.scope.span.set_tag("http.%s" % custom_header, env[wsgi_header])
43+
self.scope.span.set_tag("http.header.%s" % custom_header, env[wsgi_header])
4444

4545
if 'PATH_INFO' in env:
4646
self.scope.span.set_tag('http.path', env['PATH_INFO'])

instana/span.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,15 @@ def _collect_http_tags(self, span):
467467
self.data["http"]["path_tpl"] = span.tags.pop("http.path_tpl", None)
468468
self.data["http"]["error"] = span.tags.pop('http.error', None)
469469

470-
if span.operation_name == "soap":
471-
self.data["soap"]["action"] = span.tags.pop('soap.action', None)
470+
if len(span.tags) > 0:
471+
if span.operation_name == "soap":
472+
self.data["soap"]["action"] = span.tags.pop('soap.action', None)
473+
474+
custom_headers = []
475+
for key in span.tags:
476+
if key[0:12] == "http.header.":
477+
custom_headers.append(key)
478+
479+
for key in custom_headers:
480+
trimmed_key = key[12:]
481+
self.data["http"]["header"][trimmed_key] = span.tags.pop(key)

tests/clients/test_urllib3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def test_client_error(self):
510510

511511
def test_requestspkg_get(self):
512512
self.recorder.clear_spans()
513-
513+
514514
with tracer.start_active_span('test'):
515515
r = requests.get(testenv["wsgi_server"] + '/', timeout=2)
516516

@@ -706,7 +706,9 @@ def test_response_header_capture(self):
706706
self.assertIsNotNone(urllib3_span.stack)
707707
self.assertTrue(type(urllib3_span.stack) is list)
708708
self.assertTrue(len(urllib3_span.stack) > 1)
709-
self.assertTrue('http.X-Capture-This' in urllib3_span.data["custom"]["tags"])
709+
710+
assert "X-Capture-This" in urllib3_span.data["http"]["header"]
711+
self.assertEqual("Ok", urllib3_span.data["http"]["header"]["X-Capture-This"])
710712

711713
agent.options.extra_http_headers = original_extra_http_headers
712714

tests/frameworks/test_aiohttp_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,14 @@ async def test():
377377

378378
self.assertEqual("aiohttp-client", aiohttp_span.n)
379379
self.assertEqual(200, aiohttp_span.data["http"]["status"])
380-
self.assertEqual(
381-
testenv["wsgi_server"] + "/response_headers", aiohttp_span.data["http"]["url"])
380+
self.assertEqual(testenv["wsgi_server"] + "/response_headers", aiohttp_span.data["http"]["url"])
382381
self.assertEqual("GET", aiohttp_span.data["http"]["method"])
383382
self.assertIsNotNone(aiohttp_span.stack)
384383
self.assertTrue(type(aiohttp_span.stack) is list)
385384
self.assertTrue(len(aiohttp_span.stack) > 1)
386-
self.assertTrue(
387-
'http.X-Capture-This' in aiohttp_span.data["custom"]["tags"])
385+
386+
assert "X-Capture-This" in aiohttp_span.data["http"]["header"]
387+
self.assertEqual("Ok", aiohttp_span.data["http"]["header"]["X-Capture-This"])
388388

389389
assert "X-Instana-T" in response.headers
390390
self.assertEqual(response.headers["X-Instana-T"], traceId)
@@ -393,8 +393,7 @@ async def test():
393393
assert "X-Instana-L" in response.headers
394394
self.assertEqual(response.headers["X-Instana-L"], '1')
395395
assert "Server-Timing" in response.headers
396-
self.assertEqual(
397-
response.headers["Server-Timing"], "intid;desc=%s" % traceId)
396+
self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
398397

399398
agent.options.extra_http_headers = original_extra_http_headers
400399

tests/frameworks/test_aiohttp_server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,10 @@ async def test():
316316
self.assertEqual(
317317
response.headers["Server-Timing"], "intid;desc=%s" % traceId)
318318

319-
assert("http.X-Capture-This" in aioserver_span.data["custom"]["tags"])
320-
self.assertEqual(
321-
'this', aioserver_span.data["custom"]["tags"]['http.X-Capture-This'])
322-
assert("http.X-Capture-That" in aioserver_span.data["custom"]["tags"])
323-
self.assertEqual(
324-
'that', aioserver_span.data["custom"]["tags"]['http.X-Capture-That'])
319+
assert "X-Capture-This" in aioserver_span.data["http"]["header"]
320+
self.assertEqual("this", aioserver_span.data["http"]["header"]["X-Capture-This"])
321+
assert "X-Capture-That" in aioserver_span.data["http"]["header"]
322+
self.assertEqual("that", aioserver_span.data["http"]["header"]["X-Capture-That"])
325323

326324
def test_server_get_401(self):
327325
async def test():

tests/frameworks/test_django.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ def test_custom_header_capture(self):
251251
self.assertEqual('GET', django_span.data["http"]["method"])
252252
self.assertEqual(200, django_span.data["http"]["status"])
253253

254-
self.assertEqual(True, "http.X-Capture-This" in django_span.data["custom"]['tags'])
255-
self.assertEqual("this", django_span.data["custom"]['tags']["http.X-Capture-This"])
256-
self.assertEqual(True, "http.X-Capture-That" in django_span.data["custom"]['tags'])
257-
self.assertEqual("that", django_span.data["custom"]['tags']["http.X-Capture-That"])
254+
assert "X-Capture-This" in django_span.data["http"]["header"]
255+
self.assertEqual("this", django_span.data["http"]["header"]["X-Capture-This"])
256+
assert "X-Capture-That" in django_span.data["http"]["header"]
257+
self.assertEqual("that", django_span.data["http"]["header"]["X-Capture-That"])
258258

259259
def test_with_incoming_context(self):
260260
request_headers = dict()

tests/frameworks/test_fastapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_custom_header_capture(server):
355355
assert('http.error' not in asgi_span.data['sdk']['custom']['tags'])
356356
assert('http.params' not in asgi_span.data['sdk']['custom']['tags'])
357357

358-
assert("http.X-Capture-This" in asgi_span.data["sdk"]["custom"]['tags'])
359-
assert("this" == asgi_span.data["sdk"]["custom"]['tags']["http.X-Capture-This"])
360-
assert("http.X-Capture-That" in asgi_span.data["sdk"]["custom"]['tags'])
361-
assert("that" == asgi_span.data["sdk"]["custom"]['tags']["http.X-Capture-That"])
358+
assert("http.header.X-Capture-This" in asgi_span.data["sdk"]["custom"]['tags'])
359+
assert("this" == asgi_span.data["sdk"]["custom"]['tags']["http.header.X-Capture-This"])
360+
assert("http.header.X-Capture-That" in asgi_span.data["sdk"]["custom"]['tags'])
361+
assert("that" == asgi_span.data["sdk"]["custom"]['tags']["http.header.X-Capture-That"])

tests/frameworks/test_starlette.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def test_custom_header_capture(server):
264264
assert('http.error' not in asgi_span.data['sdk']['custom']['tags'])
265265
assert('http.params' not in asgi_span.data['sdk']['custom']['tags'])
266266

267-
assert("http.X-Capture-This" in asgi_span.data["sdk"]["custom"]['tags'])
268-
assert("this" == asgi_span.data["sdk"]["custom"]['tags']["http.X-Capture-This"])
269-
assert("http.X-Capture-That" in asgi_span.data["sdk"]["custom"]['tags'])
270-
assert("that" == asgi_span.data["sdk"]["custom"]['tags']["http.X-Capture-That"])
267+
assert("http.header.X-Capture-This" in asgi_span.data["sdk"]["custom"]['tags'])
268+
assert("this" == asgi_span.data["sdk"]["custom"]['tags']["http.header.X-Capture-This"])
269+
assert("http.header.X-Capture-That" in asgi_span.data["sdk"]["custom"]['tags'])
270+
assert("that" == asgi_span.data["sdk"]["custom"]['tags']["http.header.X-Capture-That"])

tests/frameworks/test_tornado_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def test():
115115
return await self.post(session, testenv["tornado_server"] + "/")
116116

117117
response = tornado.ioloop.IOLoop.current().run_sync(test)
118-
118+
119119
spans = self.recorder.queued_spans()
120120
self.assertEqual(3, len(spans))
121121

@@ -176,7 +176,7 @@ async def test():
176176
headers = {
177177
'X-Instana-Synthetic': '1'
178178
}
179-
179+
180180
with async_tracer.start_active_span('test'):
181181
async with aiohttp.ClientSession() as session:
182182
return await self.fetch(session, testenv["tornado_server"] + "/", headers=headers)
@@ -598,7 +598,7 @@ async def test():
598598
self.assertTrue("Server-Timing" in response.headers)
599599
self.assertEqual(response.headers["Server-Timing"], "intid;desc=%s" % traceId)
600600

601-
self.assertTrue("http.X-Capture-This" in tornado_span.data["custom"]["tags"])
602-
self.assertEqual('this', tornado_span.data["custom"]["tags"]['http.X-Capture-This'])
603-
self.assertTrue("http.X-Capture-That" in tornado_span.data["custom"]["tags"])
604-
self.assertEqual('that', tornado_span.data["custom"]["tags"]['http.X-Capture-That'])
601+
assert "X-Capture-This" in tornado_span.data["http"]["header"]
602+
self.assertEqual("this", tornado_span.data["http"]["header"]["X-Capture-This"])
603+
assert "X-Capture-That" in tornado_span.data["http"]["header"]
604+
self.assertEqual("that", tornado_span.data["http"]["header"]["X-Capture-That"])

tests/frameworks/test_wsgi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ def test_custom_header_capture(self):
230230
self.assertIsNotNone(wsgi_span.stack)
231231
self.assertEqual(2, len(wsgi_span.stack))
232232

233-
self.assertEqual(True, "http.X-Capture-This" in wsgi_span.data["custom"]['tags'])
234-
self.assertEqual("this", wsgi_span.data["custom"]['tags']["http.X-Capture-This"])
235-
self.assertEqual(True, "http.X-Capture-That" in wsgi_span.data["custom"]['tags'])
236-
self.assertEqual("that", wsgi_span.data["custom"]['tags']["http.X-Capture-That"])
233+
assert "X-Capture-This" in wsgi_span.data["http"]["header"]
234+
self.assertEqual("this", wsgi_span.data["http"]["header"]["X-Capture-This"])
235+
assert "X-Capture-That" in wsgi_span.data["http"]["header"]
236+
self.assertEqual("that", wsgi_span.data["http"]["header"]["X-Capture-That"])
237237

238238
def test_secret_scrubbing(self):
239239
with tracer.start_active_span('test'):

0 commit comments

Comments
 (0)