Skip to content

Commit 48475ba

Browse files
committed
place extract_custom_headers function in a common file
Signed-off-by: Varsha GS <[email protected]>
1 parent d0cb62b commit 48475ba

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

instana/instrumentation/flask/common.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import opentracing.ext.tags as ext
1010

1111
from ...log import logger
12-
from ...singletons import tracer
12+
from ...singletons import tracer, agent
1313

1414

1515
@wrapt.patch_function_wrapper('flask', 'templating._render')
@@ -77,3 +77,17 @@ def handle_user_exception_with_instana(wrapped, instance, argv, kwargs):
7777
logger.debug("handle_user_exception_with_instana:", exc_info=True)
7878

7979
return response
80+
81+
82+
def extract_custom_headers(span, headers, format):
83+
if agent.options.extra_http_headers is None:
84+
return
85+
try:
86+
for custom_header in agent.options.extra_http_headers:
87+
# Headers are available in this format: HTTP_X_CAPTURE_THIS
88+
flask_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header
89+
if flask_header in headers:
90+
span.set_tag("http.header.%s" % custom_header, headers[flask_header])
91+
92+
except Exception:
93+
logger.debug("extract_custom_headers: ", exc_info=True)

instana/instrumentation/flask/vanilla.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@
1313
from ...log import logger
1414
from ...singletons import agent, tracer
1515
from ...util.secrets import strip_secrets_from_query
16+
from common import extract_custom_headers
1617

1718
path_tpl_re = re.compile('<.*>')
1819

1920

20-
def extract_custom_headers(span, headers, format):
21-
if agent.options.extra_http_headers is None:
22-
return
23-
try:
24-
for custom_header in agent.options.extra_http_headers:
25-
# Headers are available in this format: HTTP_X_CAPTURE_THIS
26-
flask_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header
27-
28-
if flask_header in headers:
29-
span.set_tag("http.header.%s" % custom_header, headers[flask_header])
30-
31-
except Exception:
32-
logger.debug("extract_custom_headers: ", exc_info=True)
33-
34-
3521
def before_request_with_instana(*argv, **kwargs):
3622
try:
3723
env = flask.request.environ

instana/instrumentation/flask/with_blinker.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,14 @@
1111
from ...log import logger
1212
from ...util.secrets import strip_secrets_from_query
1313
from ...singletons import agent, tracer
14+
from common import extract_custom_headers
1415

1516
import flask
1617
from flask import request_started, request_finished, got_request_exception
1718

1819
path_tpl_re = re.compile('<.*>')
1920

2021

21-
def extract_custom_headers(span, headers, format):
22-
if agent.options.extra_http_headers is None:
23-
return
24-
try:
25-
for custom_header in agent.options.extra_http_headers:
26-
# Headers are available in this format: HTTP_X_CAPTURE_THIS
27-
flask_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header
28-
29-
if flask_header in headers:
30-
span.set_tag("http.header.%s" % custom_header, headers[flask_header])
31-
32-
except Exception:
33-
logger.debug("extract_custom_headers: ", exc_info=True)
34-
35-
3622
def request_started_with_instana(sender, **extra):
3723
try:
3824
env = flask.request.environ

0 commit comments

Comments
 (0)