Skip to content

Commit 174e144

Browse files
author
Filip Nikolovski
committed
resolve conflicts
2 parents 7702a59 + 3d5935f commit 174e144

File tree

8 files changed

+40
-22
lines changed
  • instrumentation
    • opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda
    • opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3
    • opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics
    • opentelemetry-instrumentation-wsgi
  • opentelemetry-instrumentation/src/opentelemetry/instrumentation

8 files changed

+40
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3100](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3100))
1818
- Add support to database stability opt-in in `_semconv` utilities and add tests
1919
([#3111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3111))
20+
- `opentelemetry-instrumentation-system-metrics` Add `py.typed` file to enable PEP 561
21+
([#3132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3132))
22+
- `opentelemetry-opentelemetry-sqlite3` Add `py.typed` file to enable PEP 561
23+
([#3133](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3133))
2024
- `opentelemetry-instrumentation-falcon` add support version to v4
2125
([#3086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3086))
2226
- `opentelemetry-instrumentation-falcon` Implement new HTTP semantic convention opt-in for Falcon
2327
([#2790](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2790))
28+
- `opentelemetry-instrumentation-wsgi` always record span status code to have it available in metrics
29+
([#3148](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3148))
2430
- add support to Python 3.13
2531
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))
2632

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def lambda_handler(event, context):
5555
.. code:: python
5656
5757
from opentelemetry.instrumentation.aws_lambda import AwsLambdaInstrumentor
58+
from opentelemetry.propagate import get_global_textmap
5859
5960
def custom_event_context_extractor(lambda_event):
6061
# If the `TraceContextTextMapPropagator` is the global propagator, we

instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/py.typed

Whitespace-only changes.

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@
7676
---
7777
"""
7878

79+
from __future__ import annotations
80+
7981
import gc
8082
import logging
8183
import os
8284
import sys
8385
import threading
8486
from platform import python_implementation
85-
from typing import Collection, Dict, Iterable, List, Optional
87+
from typing import Any, Collection, Iterable
8688

8789
import psutil
8890

89-
# FIXME Remove this pylint disabling line when Github issue is cleared
90-
# pylint: disable=no-name-in-module
9191
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
9292
from opentelemetry.instrumentation.system_metrics.package import _instruments
9393
from opentelemetry.instrumentation.system_metrics.version import __version__
@@ -96,7 +96,7 @@
9696
_logger = logging.getLogger(__name__)
9797

9898

99-
_DEFAULT_CONFIG = {
99+
_DEFAULT_CONFIG: dict[str, list[str] | None] = {
100100
"system.cpu.time": ["idle", "user", "system", "irq"],
101101
"system.cpu.utilization": ["idle", "user", "system", "irq"],
102102
"system.memory.usage": ["used", "free", "cached"],
@@ -129,8 +129,8 @@
129129
class SystemMetricsInstrumentor(BaseInstrumentor):
130130
def __init__(
131131
self,
132-
labels: Optional[Dict[str, str]] = None,
133-
config: Optional[Dict[str, List[str]]] = None,
132+
labels: dict[str, str] | None = None,
133+
config: dict[str, list[str] | None] | None = None,
134134
):
135135
super().__init__()
136136
if config is None:
@@ -176,7 +176,7 @@ def __init__(
176176
def instrumentation_dependencies(self) -> Collection[str]:
177177
return _instruments
178178

179-
def _instrument(self, **kwargs):
179+
def _instrument(self, **kwargs: Any):
180180
# pylint: disable=too-many-branches
181181
meter_provider = kwargs.get("meter_provider")
182182
self._meter = get_meter(
@@ -408,7 +408,7 @@ def _instrument(self, **kwargs):
408408
description="Number of file descriptors in use by the process.",
409409
)
410410

411-
def _uninstrument(self, **__):
411+
def _uninstrument(self, **kwargs: Any):
412412
pass
413413

414414
def _get_open_file_descriptors(

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/py.typed

Whitespace-only changes.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,7 @@ def add_response_attributes(
480480
"""Adds HTTP response attributes to span using the arguments
481481
passed to a PEP3333-conforming start_response callable.
482482
"""
483-
if not span.is_recording():
484-
return
485483
status_code_str, _ = start_response_status.split(" ", 1)
486-
487-
status_code = 0
488484
try:
489485
status_code = int(status_code_str)
490486
except ValueError:

instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,19 @@ def test_response_attributes(self):
779779
self.span.set_attribute.assert_has_calls(expected, any_order=True)
780780
self.span.set_attribute.assert_has_calls(expected_new, any_order=True)
781781

782+
def test_response_attributes_noop(self):
783+
mock_span = mock.Mock()
784+
mock_span.is_recording.return_value = False
785+
786+
attrs = {}
787+
otel_wsgi.add_response_attributes(
788+
mock_span, "404 Not Found", {}, duration_attrs=attrs
789+
)
790+
791+
self.assertEqual(mock_span.set_attribute.call_count, 0)
792+
self.assertEqual(mock_span.is_recording.call_count, 2)
793+
self.assertEqual(attrs[SpanAttributes.HTTP_STATUS_CODE], 404)
794+
782795
def test_credential_removal(self):
783796
self.environ["HTTP_HOST"] = "username:password@mock"
784797
self.environ["PATH_INFO"] = "/status/200"

opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import urllib.parse
1618
from contextlib import contextmanager
1719
from importlib import import_module
1820
from re import escape, sub
19-
from typing import Dict, Iterable, Sequence, Union
21+
from typing import Any, Dict, Generator, Sequence
2022

2123
from wrapt import ObjectProxy
2224

@@ -44,9 +46,9 @@
4446

4547

4648
def extract_attributes_from_object(
47-
obj: any, attributes: Sequence[str], existing: Dict[str, str] = None
49+
obj: Any, attributes: Sequence[str], existing: Dict[str, str] | None = None
4850
) -> Dict[str, str]:
49-
extracted = {}
51+
extracted: dict[str, str] = {}
5052
if existing:
5153
extracted.update(existing)
5254
for attr in attributes:
@@ -81,7 +83,7 @@ def http_status_to_status_code(
8183
return StatusCode.ERROR
8284

8385

84-
def unwrap(obj: Union[object, str], attr: str):
86+
def unwrap(obj: object, attr: str):
8587
"""Given a function that was wrapped by wrapt.wrap_function_wrapper, unwrap it
8688
8789
The object containing the function to unwrap may be passed as dotted module path string.
@@ -152,7 +154,7 @@ def _start_internal_or_server_span(
152154
return span, token
153155

154156

155-
def _url_quote(s) -> str: # pylint: disable=invalid-name
157+
def _url_quote(s: Any) -> str: # pylint: disable=invalid-name
156158
if not isinstance(s, (str, bytes)):
157159
return s
158160
quoted = urllib.parse.quote(s)
@@ -163,13 +165,13 @@ def _url_quote(s) -> str: # pylint: disable=invalid-name
163165
return quoted.replace("%", "%%")
164166

165167

166-
def _get_opentelemetry_values() -> dict:
168+
def _get_opentelemetry_values() -> dict[str, Any]:
167169
"""
168170
Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
169171
OpenTelemetry execution context.
170172
"""
171173
# Insert the W3C TraceContext generated
172-
_headers = {}
174+
_headers: dict[str, Any] = {}
173175
propagator.inject(_headers)
174176
return _headers
175177

@@ -196,7 +198,7 @@ def is_http_instrumentation_enabled() -> bool:
196198

197199

198200
@contextmanager
199-
def _suppress_instrumentation(*keys: str) -> Iterable[None]:
201+
def _suppress_instrumentation(*keys: str) -> Generator[None]:
200202
"""Suppress instrumentation within the context."""
201203
ctx = context.get_current()
202204
for key in keys:
@@ -209,7 +211,7 @@ def _suppress_instrumentation(*keys: str) -> Iterable[None]:
209211

210212

211213
@contextmanager
212-
def suppress_instrumentation() -> Iterable[None]:
214+
def suppress_instrumentation() -> Generator[None]:
213215
"""Suppress instrumentation within the context."""
214216
with _suppress_instrumentation(
215217
_SUPPRESS_INSTRUMENTATION_KEY, _SUPPRESS_INSTRUMENTATION_KEY_PLAIN
@@ -218,7 +220,7 @@ def suppress_instrumentation() -> Iterable[None]:
218220

219221

220222
@contextmanager
221-
def suppress_http_instrumentation() -> Iterable[None]:
223+
def suppress_http_instrumentation() -> Generator[None]:
222224
"""Suppress instrumentation within the context."""
223225
with _suppress_instrumentation(_SUPPRESS_HTTP_INSTRUMENTATION_KEY):
224226
yield

0 commit comments

Comments
 (0)