diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index 0415c80082..ee2d8b23d1 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -68,7 +68,7 @@ _filter_semconv_duration_attrs, _get_schema_url, _OpenTelemetrySemanticConventionStability, - _OpenTelemetryStabilityMode, + _HTTPStabilityMode, _OpenTelemetryStabilitySignalType, _report_new, _report_old, @@ -119,7 +119,7 @@ def _instrument( request_hook: _RequestHookT = None, response_hook: _ResponseHookT = None, excluded_urls: ExcludeList = None, - sem_conv_opt_in_mode: _OpenTelemetryStabilityMode = _OpenTelemetryStabilityMode.DEFAULT, + sem_conv_opt_in_mode: _HTTPStabilityMode = _HTTPStabilityMode.DEFAULT, ): """Enables tracing of all requests calls that go through :code:`requests.session.Session.request` (this includes @@ -290,7 +290,7 @@ def get_or_create_headers(): metric_labels, _client_duration_attrs_old, _client_duration_attrs_new, - _OpenTelemetryStabilityMode.DEFAULT + _HTTPStabilityMode.DEFAULT ) duration_histogram_old.record( max(round(elapsed_time * 1000), 0), @@ -301,7 +301,7 @@ def get_or_create_headers(): metric_labels, _client_duration_attrs_old, _client_duration_attrs_new, - _OpenTelemetryStabilityMode.HTTP + _HTTPStabilityMode.HTTP ) duration_histogram_new.record( elapsed_time, attributes=duration_attrs_new diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 11c7232166..021aa60871 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -217,7 +217,7 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he _OpenTelemetrySemanticConventionStability, _OpenTelemetryStabilitySignalType, _METRIC_ATTRIBUTES_SERVER_DURATION_NAME, - _OpenTelemetryStabilityMode, + _HTTPStabilityMode, _SPAN_ATTRIBUTES_ERROR_TYPE, _get_schema_url, _filter_semconv_active_request_count_attr, @@ -305,7 +305,7 @@ def setifnotnone(dic, key, value): def collect_request_attributes( environ, - sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT, + sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT, ): """Collects HTTP request attributes from the PEP3333-conforming WSGI environ and returns a dictionary to be used as span creation attributes. @@ -446,7 +446,7 @@ def _parse_status_code(resp_status): return None -def _parse_active_request_count_attrs(req_attrs, sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT): +def _parse_active_request_count_attrs(req_attrs, sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT): return _filter_semconv_active_request_count_attr( req_attrs, _server_active_requests_count_attrs_old, @@ -455,7 +455,7 @@ def _parse_active_request_count_attrs(req_attrs, sem_conv_opt_in_mode = _OpenTel ) -def _parse_duration_attrs(req_attrs, sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT): +def _parse_duration_attrs(req_attrs, sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT): return _filter_semconv_duration_attrs( req_attrs, _server_duration_attrs_old, @@ -469,7 +469,7 @@ def add_response_attributes( start_response_status, response_headers, duration_attrs = None, - sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT, + sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT, ): # pylint: disable=unused-argument """Adds HTTP response attributes to span using the arguments passed to a PEP3333-conforming start_response callable. @@ -648,7 +648,7 @@ def __call__(self, environ, start_response): if span.is_recording(): if _report_new(self._sem_conv_opt_in_mode): span.set_attribute(_SPAN_ATTRIBUTES_ERROR_TYPE, type(ex).__qualname__ ) - span.set_status(Status(StatusCode.ERROR, str(ex))) + span.set_status(Status(StatusCode.ERROR, str(ex))) span.end() if token is not None: context.detach(token) @@ -656,10 +656,10 @@ def __call__(self, environ, start_response): finally: duration_s = default_timer() - start if self.duration_histogram_old: - duration_attrs_old = _parse_duration_attrs(req_attrs, _OpenTelemetryStabilityMode.DEFAULT) + duration_attrs_old = _parse_duration_attrs(req_attrs, _HTTPStabilityMode.DEFAULT) self.duration_histogram_old.record(max(round(duration_s * 1000), 0), duration_attrs_old) if self.duration_histogram_new: - duration_attrs_new = _parse_duration_attrs(req_attrs, _OpenTelemetryStabilityMode.HTTP) + duration_attrs_new = _parse_duration_attrs(req_attrs, _HTTPStabilityMode.HTTP) self.duration_histogram_new.record(max(round(duration_s * 1000), 0), duration_attrs_new) self.active_requests_counter.add(-1, active_requests_count_attrs) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index 0d2e265e94..73051fa70a 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -26,7 +26,7 @@ _server_duration_attrs_old, _OTEL_SEMCONV_STABILITY_OPT_IN_KEY, _OpenTelemetrySemanticConventionStability, - _OpenTelemetryStabilityMode, + _HTTPStabilityMode, ) from opentelemetry.sdk.metrics.export import ( HistogramDataPoint, @@ -496,7 +496,7 @@ def test_request_attributes_new_semconv(self): attrs = otel_wsgi.collect_request_attributes( self.environ, - _OpenTelemetryStabilityMode.HTTP, + _HTTPStabilityMode.HTTP, ) self.assertDictEqual( attrs, @@ -654,7 +654,7 @@ def test_request_attributes_with_full_request_uri(self): self.assertGreaterEqual( otel_wsgi.collect_request_attributes( self.environ, - _OpenTelemetryStabilityMode.HTTP, + _HTTPStabilityMode.HTTP, ).items(), expected_new.items(), ) @@ -670,7 +670,7 @@ def test_http_user_agent_attribute(self): self.assertGreaterEqual( otel_wsgi.collect_request_attributes( self.environ, - _OpenTelemetryStabilityMode.HTTP, + _HTTPStabilityMode.HTTP, ).items(), expected_new.items(), ) @@ -681,7 +681,7 @@ def test_response_attributes(self): self.span, "404 Not Found", {}, - sem_conv_opt_in_mode=_OpenTelemetryStabilityMode.HTTP, + sem_conv_opt_in_mode=_HTTPStabilityMode.HTTP, ) expected = (mock.call(SpanAttributes.HTTP_STATUS_CODE, 404),) expected_new = (mock.call(SpanAttributes.HTTP_RESPONSE_STATUS_CODE, 404),) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py index 09f4a1c90b..618d8e225e 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py @@ -91,7 +91,7 @@ class _OpenTelemetryStabilitySignalType: HTTP = "http" -class _OpenTelemetryStabilityMode(Enum): +class _HTTPStabilityMode(Enum): # http - emit the new, stable HTTP and networking conventions ONLY HTTP = "http" # http/dup - emit both the old and the stable HTTP and networking conventions @@ -101,11 +101,11 @@ class _OpenTelemetryStabilityMode(Enum): def _report_new(mode): - return mode.name != _OpenTelemetryStabilityMode.DEFAULT.name + return mode.name != _HTTPStabilityMode.DEFAULT.name def _report_old(mode): - return mode.name != _OpenTelemetryStabilityMode.HTTP.name + return mode.name != _HTTPStabilityMode.HTTP.name class _OpenTelemetrySemanticConventionStability: @@ -123,17 +123,17 @@ def _initialize(cls): opt_in_list = [] if opt_in: opt_in_list = [s.strip() for s in opt_in.split(",")] - http_opt_in = _OpenTelemetryStabilityMode.DEFAULT + http_opt_in = _HTTPStabilityMode.DEFAULT if opt_in_list: # Process http opt-in # http/dup takes priority over http if ( - _OpenTelemetryStabilityMode.HTTP_DUP.value + _HTTPStabilityMode.HTTP_DUP.value in opt_in_list ): - http_opt_in = _OpenTelemetryStabilityMode.HTTP_DUP - elif _OpenTelemetryStabilityMode.HTTP.value in opt_in_list: - http_opt_in = _OpenTelemetryStabilityMode.HTTP + http_opt_in = _HTTPStabilityMode.HTTP_DUP + elif _HTTPStabilityMode.HTTP.value in opt_in_list: + http_opt_in = _HTTPStabilityMode.HTTP _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING[ _OpenTelemetryStabilitySignalType.HTTP ] = http_opt_in @@ -144,9 +144,9 @@ def _initialize(cls): def _get_opentelemetry_stability_opt_in_mode( cls, signal_type: _OpenTelemetryStabilitySignalType, - ) -> _OpenTelemetryStabilityMode: + ) -> _HTTPStabilityMode: return _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING.get( - signal_type, _OpenTelemetryStabilityMode.DEFAULT + signal_type, _HTTPStabilityMode.DEFAULT ) @@ -154,13 +154,13 @@ def _filter_semconv_duration_attrs( attrs, old_attrs, new_attrs, - sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT, + sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT, ): filtered_attrs = {} # duration is two different metrics depending on sem_conv_opt_in_mode, so no DUP attributes allowed_attributes = ( new_attrs - if sem_conv_opt_in_mode == _OpenTelemetryStabilityMode.HTTP + if sem_conv_opt_in_mode == _HTTPStabilityMode.HTTP else old_attrs ) for key, val in attrs.items(): @@ -173,7 +173,7 @@ def _filter_semconv_active_request_count_attr( attrs, old_attrs, new_attrs, - sem_conv_opt_in_mode = _OpenTelemetryStabilityMode.DEFAULT, + sem_conv_opt_in_mode = _HTTPStabilityMode.DEFAULT, ): filtered_attrs = {} if _report_old(sem_conv_opt_in_mode): @@ -364,7 +364,7 @@ def _set_status(span, metrics_attributes, status_code_str, status_code, sem_conv # Get schema version based off of opt-in mode -def _get_schema_url(mode: _OpenTelemetryStabilityMode) -> str: - if mode is _OpenTelemetryStabilityMode.DEFAULT: +def _get_schema_url(mode: _HTTPStabilityMode) -> str: + if mode is _HTTPStabilityMode.DEFAULT: return "https://opentelemetry.io/schemas/1.11.0" return SpanAttributes.SCHEMA_URL