Skip to content

Commit

Permalink
Change to new HTTP_ROUTE semconv & linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzaloGuasch authored and GonzaloGuasch committed Jun 24, 2024
1 parent fc48830 commit b2c8849
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def response_hook(span: Span, status: str, response_headers: List):
)
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
from opentelemetry.metrics import get_meter
from opentelemetry.semconv.attributes.http_attributes import HTTP_ROUTE
from opentelemetry.semconv.metrics import MetricInstruments
from opentelemetry.semconv.metrics.http_metrics import (
HTTP_SERVER_REQUEST_DURATION,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.util.http import (
get_excluded_urls,
parse_excluded_urls,
Expand All @@ -284,7 +284,7 @@ def response_hook(span: Span, status: str, response_headers: List):
_ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key"
_ENVIRON_REQCTX_REF_KEY = "opentelemetry-flask.reqctx_ref_key"
_ENVIRON_TOKEN = "opentelemetry-flask.token"
_ENVIRON_REQUEST_ROUTE_KEY = "request-route_key"
_ENVIRON_REQUEST_ROUTE_KEY = "opentelemetry-flask.request-route_key"

_excluded_urls_from_env = get_excluded_urls("FLASK")

Expand Down Expand Up @@ -396,8 +396,8 @@ def _start_response(status, response_headers, *args, **kwargs):
)

if wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY, None):
duration_attrs_old[SpanAttributes.HTTP_ROUTE] = (
wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY)
duration_attrs_old[HTTP_ROUTE] = wrapped_app_environ.get(
_ENVIRON_REQUEST_ROUTE_KEY
)

duration_histogram_old.record(
Expand All @@ -409,8 +409,8 @@ def _start_response(status, response_headers, *args, **kwargs):
)

if wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY, None):
duration_attrs_new[SpanAttributes.HTTP_ROUTE] = (
wrapped_app_environ.get(_ENVIRON_REQUEST_ROUTE_KEY)
duration_attrs_new[HTTP_ROUTE] = wrapped_app_environ.get(
_ENVIRON_REQUEST_ROUTE_KEY
)

duration_histogram_new.record(
Expand Down Expand Up @@ -443,7 +443,7 @@ def _before_request():
if flask.request.url_rule:
# For 404 that result from no route found, etc, we
# don't have a url_rule.
attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule
attributes[HTTP_ROUTE] = flask.request.url_rule.rule
span, token = _start_internal_or_server_span(
tracer=tracer,
span_name=span_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ def test_basic_metric_success(self):
"http.method": "GET",
"http.host": "localhost",
"http.scheme": "http",

"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.name": "localhost",
Expand Down

0 comments on commit b2c8849

Please sign in to comment.