Skip to content

Commit b2c8849

Browse files
GonzaloGuaschGonzaloGuasch
authored and
GonzaloGuasch
committed
Change to new HTTP_ROUTE semconv & linter fix
1 parent fc48830 commit b2c8849

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ def response_hook(span: Span, status: str, response_headers: List):
266266
)
267267
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
268268
from opentelemetry.metrics import get_meter
269+
from opentelemetry.semconv.attributes.http_attributes import HTTP_ROUTE
269270
from opentelemetry.semconv.metrics import MetricInstruments
270271
from opentelemetry.semconv.metrics.http_metrics import (
271272
HTTP_SERVER_REQUEST_DURATION,
272273
)
273-
from opentelemetry.semconv.trace import SpanAttributes
274274
from opentelemetry.util.http import (
275275
get_excluded_urls,
276276
parse_excluded_urls,
@@ -284,7 +284,7 @@ def response_hook(span: Span, status: str, response_headers: List):
284284
_ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key"
285285
_ENVIRON_REQCTX_REF_KEY = "opentelemetry-flask.reqctx_ref_key"
286286
_ENVIRON_TOKEN = "opentelemetry-flask.token"
287-
_ENVIRON_REQUEST_ROUTE_KEY = "request-route_key"
287+
_ENVIRON_REQUEST_ROUTE_KEY = "opentelemetry-flask.request-route_key"
288288

289289
_excluded_urls_from_env = get_excluded_urls("FLASK")
290290

@@ -396,8 +396,8 @@ def _start_response(status, response_headers, *args, **kwargs):
396396
)
397397

398398
if wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY, None):
399-
duration_attrs_old[SpanAttributes.HTTP_ROUTE] = (
400-
wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY)
399+
duration_attrs_old[HTTP_ROUTE] = wrapped_app_environ.get(
400+
_ENVIRON_REQUEST_ROUTE_KEY
401401
)
402402

403403
duration_histogram_old.record(
@@ -409,8 +409,8 @@ def _start_response(status, response_headers, *args, **kwargs):
409409
)
410410

411411
if wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY, None):
412-
duration_attrs_new[SpanAttributes.HTTP_ROUTE] = (
413-
wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY)
412+
duration_attrs_new[HTTP_ROUTE] = wrapped_app_environ.get(
413+
_ENVIRON_REQUEST_ROUTE_KEY
414414
)
415415

416416
duration_histogram_new.record(
@@ -443,7 +443,7 @@ def _before_request():
443443
if flask.request.url_rule:
444444
# For 404 that result from no route found, etc, we
445445
# don't have a url_rule.
446-
attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule
446+
attributes[HTTP_ROUTE] = flask.request.url_rule.rule
447447
span, token = _start_internal_or_server_span(
448448
tracer=tracer,
449449
span_name=span_name,

instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ def test_basic_metric_success(self):
586586
"http.method": "GET",
587587
"http.host": "localhost",
588588
"http.scheme": "http",
589-
590589
"http.flavor": "1.1",
591590
"http.server_name": "localhost",
592591
"net.host.name": "localhost",

0 commit comments

Comments
 (0)