Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipNikolovski committed Jan 3, 2025
2 parents 7702a59 + 3d5935f commit 174e144
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3100](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3100))
- Add support to database stability opt-in in `_semconv` utilities and add tests
([#3111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3111))
- `opentelemetry-instrumentation-system-metrics` Add `py.typed` file to enable PEP 561
([#3132](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3132))
- `opentelemetry-opentelemetry-sqlite3` Add `py.typed` file to enable PEP 561
([#3133](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3133))
- `opentelemetry-instrumentation-falcon` add support version to v4
([#3086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3086))
- `opentelemetry-instrumentation-falcon` Implement new HTTP semantic convention opt-in for Falcon
([#2790](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2790))
- `opentelemetry-instrumentation-wsgi` always record span status code to have it available in metrics
([#3148](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3148))
- add support to Python 3.13
([#3134](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3134))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def lambda_handler(event, context):
.. code:: python
from opentelemetry.instrumentation.aws_lambda import AwsLambdaInstrumentor
from opentelemetry.propagate import get_global_textmap
def custom_event_context_extractor(lambda_event):
# If the `TraceContextTextMapPropagator` is the global propagator, we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
---
"""

from __future__ import annotations

import gc
import logging
import os
import sys
import threading
from platform import python_implementation
from typing import Collection, Dict, Iterable, List, Optional
from typing import Any, Collection, Iterable

import psutil

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


_DEFAULT_CONFIG = {
_DEFAULT_CONFIG: dict[str, list[str] | None] = {
"system.cpu.time": ["idle", "user", "system", "irq"],
"system.cpu.utilization": ["idle", "user", "system", "irq"],
"system.memory.usage": ["used", "free", "cached"],
Expand Down Expand Up @@ -129,8 +129,8 @@
class SystemMetricsInstrumentor(BaseInstrumentor):
def __init__(
self,
labels: Optional[Dict[str, str]] = None,
config: Optional[Dict[str, List[str]]] = None,
labels: dict[str, str] | None = None,
config: dict[str, list[str] | None] | None = None,
):
super().__init__()
if config is None:
Expand Down Expand Up @@ -176,7 +176,7 @@ def __init__(
def instrumentation_dependencies(self) -> Collection[str]:
return _instruments

def _instrument(self, **kwargs):
def _instrument(self, **kwargs: Any):
# pylint: disable=too-many-branches
meter_provider = kwargs.get("meter_provider")
self._meter = get_meter(
Expand Down Expand Up @@ -408,7 +408,7 @@ def _instrument(self, **kwargs):
description="Number of file descriptors in use by the process.",
)

def _uninstrument(self, **__):
def _uninstrument(self, **kwargs: Any):
pass

def _get_open_file_descriptors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,7 @@ def add_response_attributes(
"""Adds HTTP response attributes to span using the arguments
passed to a PEP3333-conforming start_response callable.
"""
if not span.is_recording():
return
status_code_str, _ = start_response_status.split(" ", 1)

status_code = 0
try:
status_code = int(status_code_str)
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,19 @@ def test_response_attributes(self):
self.span.set_attribute.assert_has_calls(expected, any_order=True)
self.span.set_attribute.assert_has_calls(expected_new, any_order=True)

def test_response_attributes_noop(self):
mock_span = mock.Mock()
mock_span.is_recording.return_value = False

attrs = {}
otel_wsgi.add_response_attributes(
mock_span, "404 Not Found", {}, duration_attrs=attrs
)

self.assertEqual(mock_span.set_attribute.call_count, 0)
self.assertEqual(mock_span.is_recording.call_count, 2)
self.assertEqual(attrs[SpanAttributes.HTTP_STATUS_CODE], 404)

def test_credential_removal(self):
self.environ["HTTP_HOST"] = "username:password@mock"
self.environ["PATH_INFO"] = "/status/200"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import urllib.parse
from contextlib import contextmanager
from importlib import import_module
from re import escape, sub
from typing import Dict, Iterable, Sequence, Union
from typing import Any, Dict, Generator, Sequence

from wrapt import ObjectProxy

Expand Down Expand Up @@ -44,9 +46,9 @@


def extract_attributes_from_object(
obj: any, attributes: Sequence[str], existing: Dict[str, str] = None
obj: Any, attributes: Sequence[str], existing: Dict[str, str] | None = None
) -> Dict[str, str]:
extracted = {}
extracted: dict[str, str] = {}
if existing:
extracted.update(existing)
for attr in attributes:
Expand Down Expand Up @@ -81,7 +83,7 @@ def http_status_to_status_code(
return StatusCode.ERROR


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


def _url_quote(s) -> str: # pylint: disable=invalid-name
def _url_quote(s: Any) -> str: # pylint: disable=invalid-name
if not isinstance(s, (str, bytes)):
return s
quoted = urllib.parse.quote(s)
Expand All @@ -163,13 +165,13 @@ def _url_quote(s) -> str: # pylint: disable=invalid-name
return quoted.replace("%", "%%")


def _get_opentelemetry_values() -> dict:
def _get_opentelemetry_values() -> dict[str, Any]:
"""
Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
OpenTelemetry execution context.
"""
# Insert the W3C TraceContext generated
_headers = {}
_headers: dict[str, Any] = {}
propagator.inject(_headers)
return _headers

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


@contextmanager
def _suppress_instrumentation(*keys: str) -> Iterable[None]:
def _suppress_instrumentation(*keys: str) -> Generator[None]:
"""Suppress instrumentation within the context."""
ctx = context.get_current()
for key in keys:
Expand All @@ -209,7 +211,7 @@ def _suppress_instrumentation(*keys: str) -> Iterable[None]:


@contextmanager
def suppress_instrumentation() -> Iterable[None]:
def suppress_instrumentation() -> Generator[None]:
"""Suppress instrumentation within the context."""
with _suppress_instrumentation(
_SUPPRESS_INSTRUMENTATION_KEY, _SUPPRESS_INSTRUMENTATION_KEY_PLAIN
Expand All @@ -218,7 +220,7 @@ def suppress_instrumentation() -> Iterable[None]:


@contextmanager
def suppress_http_instrumentation() -> Iterable[None]:
def suppress_http_instrumentation() -> Generator[None]:
"""Suppress instrumentation within the context."""
with _suppress_instrumentation(_SUPPRESS_HTTP_INSTRUMENTATION_KEY):
yield

0 comments on commit 174e144

Please sign in to comment.