Skip to content

Commit b93c547

Browse files
committed
refactor(flask): replace SpanAttributes with semconv attributes (fix ruff linting)
1 parent efd599f commit b93c547

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ def response_hook(span: Span, status: str, response_headers: List):
273273
)
274274
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
275275
from opentelemetry.metrics import get_meter
276+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
277+
HTTP_ROUTE,
278+
HTTP_TARGET,
279+
)
276280
from opentelemetry.semconv.metrics import MetricInstruments
277281
from opentelemetry.semconv.metrics.http_metrics import (
278282
HTTP_SERVER_REQUEST_DURATION,
279283
)
280-
from opentelemetry.semconv._incubating.attributes.http_attributes import (
281-
HTTP_TARGET,
282-
HTTP_ROUTE
283-
)
284284
from opentelemetry.util._importlib_metadata import version
285285
from opentelemetry.util.http import (
286286
get_excluded_urls,
@@ -406,9 +406,7 @@ def _start_response(status, response_headers, *args, **kwargs):
406406

407407
if request_route:
408408
# http.target to be included in old semantic conventions
409-
duration_attrs_old[HTTP_TARGET] = str(
410-
request_route
411-
)
409+
duration_attrs_old[HTTP_TARGET] = str(request_route)
412410

413411
duration_histogram_old.record(
414412
max(round(duration_s * 1000), 0), duration_attrs_old

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,34 @@
4040
NumberDataPoint,
4141
)
4242
from opentelemetry.sdk.resources import Resource
43-
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
4443
from opentelemetry.semconv._incubating.attributes.http_attributes import (
45-
HTTP_METHOD,
46-
HTTP_SERVER_NAME,
47-
HTTP_SCHEME,
48-
HTTP_HOST,
49-
HTTP_TARGET,
5044
HTTP_FLAVOR,
51-
HTTP_STATUS_CODE,
45+
HTTP_HOST,
46+
HTTP_METHOD,
5247
HTTP_REQUEST_METHOD,
5348
HTTP_RESPONSE_STATUS_CODE,
5449
HTTP_ROUTE,
55-
56-
50+
HTTP_SCHEME,
51+
HTTP_SERVER_NAME,
52+
HTTP_STATUS_CODE,
53+
HTTP_TARGET,
5754
)
5855
from opentelemetry.semconv._incubating.attributes.net_attributes import (
59-
NET_HOST_PORT,
6056
NET_HOST_NAME,
61-
57+
NET_HOST_PORT,
58+
)
59+
from opentelemetry.semconv._incubating.attributes.network_attributes import (
60+
NETWORK_PROTOCOL_VERSION,
6261
)
6362
from opentelemetry.semconv._incubating.attributes.server_attributes import (
64-
SERVER_PORT,
6563
SERVER_ADDRESS,
64+
SERVER_PORT,
6665
)
6766
from opentelemetry.semconv._incubating.attributes.url_attributes import (
6867
URL_PATH,
6968
URL_SCHEME,
7069
)
71-
from opentelemetry.semconv._incubating.attributes.network_attributes import (
72-
NETWORK_PROTOCOL_VERSION
73-
)
70+
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
7471
from opentelemetry.test.wsgitestutil import WsgiTestBase
7572
from opentelemetry.util.http import (
7673
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS,

0 commit comments

Comments
 (0)