File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
ext/opentelemetry-ext-flask
src/opentelemetry/ext/flask Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 1212
1313logger = logging .getLogger (__name__ )
1414
15- _ENVIRON_STARTTIME_KEY = object ()
16- _ENVIRON_SPAN_KEY = object ()
17- _ENVIRON_ACTIVATION_KEY = object ()
15+ _ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key"
16+ _ENVIRON_SPAN_KEY = "opentelemetry-flask.span_key"
17+ _ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key"
1818
1919
2020def instrument_app (flask ):
Original file line number Diff line number Diff line change 1414
1515import unittest
1616
17- from flask import Flask
17+ from flask import Flask , request
1818from werkzeug .test import Client
1919from werkzeug .wrappers import BaseResponse
2020
@@ -57,6 +57,25 @@ def hello_endpoint(helloid):
5757 otel_flask .instrument_app (self .app )
5858 self .client = Client (self .app , BaseResponse )
5959
60+ def test_only_strings_in_environ (self ):
61+ """
62+ Some WSGI servers (such as Gunicorn) expect keys in the environ object
63+ to be strings
64+
65+ OpenTelemetry should adhere to this convention.
66+ """
67+ nonstring_keys = set ()
68+
69+ def assert_environ ():
70+ for key in request .environ :
71+ if not isinstance (key , str ):
72+ nonstring_keys .add (key )
73+ return "hi"
74+
75+ self .app .route ("/assert_environ" )(assert_environ )
76+ self .client .get ("/assert_environ" )
77+ self .assertEqual (nonstring_keys , set ())
78+
6079 def test_simple (self ):
6180 expected_attrs = expected_attributes (
6281 {
You can’t perform that action at this time.
0 commit comments