diff --git a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py index ce11b18d635..4bf0cc8c681 100644 --- a/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py +++ b/ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py @@ -12,9 +12,9 @@ logger = logging.getLogger(__name__) -_ENVIRON_STARTTIME_KEY = object() -_ENVIRON_SPAN_KEY = object() -_ENVIRON_ACTIVATION_KEY = object() +_ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key" +_ENVIRON_SPAN_KEY = "opentelemetry-flask.span_key" +_ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key" def instrument_app(flask): diff --git a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py index 09e62b7ba19..9d2f2560118 100644 --- a/ext/opentelemetry-ext-flask/tests/test_flask_integration.py +++ b/ext/opentelemetry-ext-flask/tests/test_flask_integration.py @@ -14,7 +14,7 @@ import unittest -from flask import Flask +from flask import Flask, request from werkzeug.test import Client from werkzeug.wrappers import BaseResponse @@ -57,6 +57,25 @@ def hello_endpoint(helloid): otel_flask.instrument_app(self.app) self.client = Client(self.app, BaseResponse) + def test_only_strings_in_environ(self): + """ + Some WSGI servers (such as Gunicorn) expect keys in the environ object + to be strings + + OpenTelemetry should adhere to this convention. + """ + nonstring_keys = set() + + def assert_environ(): + for key in request.environ: + if not isinstance(key, str): + nonstring_keys.add(key) + return "hi" + + self.app.route("/assert_environ")(assert_environ) + self.client.get("/assert_environ") + self.assertEqual(nonstring_keys, set()) + def test_simple(self): expected_attrs = expected_attributes( {