diff --git a/logfire/_internal/exporters/processor_wrapper.py b/logfire/_internal/exporters/processor_wrapper.py index cce4ed5a8..a067ef1f2 100644 --- a/logfire/_internal/exporters/processor_wrapper.py +++ b/logfire/_internal/exporters/processor_wrapper.py @@ -136,7 +136,13 @@ def _tweak_asgi_send_receive_spans(span: ReadableSpanDict) -> None: def _is_asgi_send_receive_span(name: str, instrumentation_scope: InstrumentationScope | None) -> bool: return ( - instrumentation_scope is not None and instrumentation_scope.name == 'opentelemetry.instrumentation.asgi' + instrumentation_scope is not None + and instrumentation_scope.name + in ( + 'opentelemetry.instrumentation.asgi', + 'opentelemetry.instrumentation.starlette', + 'opentelemetry.instrumentation.fastapi', + ) ) and (name.endswith((' http send', ' http receive', ' websocket send', ' websocket receive'))) diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index 09fd355fb..795dcd8d2 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -69,7 +69,7 @@ from django.http import HttpRequest, HttpResponse from fastapi import FastAPI from flask.app import Flask - from opentelemetry.metrics import _Gauge as Gauge + from opentelemetry.metrics import _Gauge as Gauge # type: ignore from starlette.applications import Starlette from starlette.requests import Request from starlette.websockets import WebSocket diff --git a/logfire/_internal/metrics.py b/logfire/_internal/metrics.py index 56ff8c2f9..09ff6b23d 100644 --- a/logfire/_internal/metrics.py +++ b/logfire/_internal/metrics.py @@ -24,7 +24,7 @@ try: # This only exists in opentelemetry-sdk>=1.23.0 - from opentelemetry.metrics import _Gauge + from opentelemetry.metrics import _Gauge # type: ignore Gauge = _Gauge except ImportError: # pragma: no cover @@ -99,10 +99,12 @@ def get_meter( name: str, version: str | None = None, schema_url: str | None = None, + *args: Any, + **kwargs: Any, ) -> Meter: with self.lock: meter = _ProxyMeter( - self.provider.get_meter(name, version=version, schema_url=schema_url), + self.provider.get_meter(name, version=version, schema_url=schema_url, *args, **kwargs), name, version, schema_url, diff --git a/logfire/_internal/tracer.py b/logfire/_internal/tracer.py index d1c09f1e7..b3bffc74c 100644 --- a/logfire/_internal/tracer.py +++ b/logfire/_internal/tracer.py @@ -50,19 +50,14 @@ def set_provider(self, provider: SDKTracerProvider) -> None: def get_tracer( self, - instrumenting_module_name: str, - instrumenting_library_version: str | None = None, - schema_url: str | None = None, + *args: Any, is_span_tracer: bool = True, + **kwargs: Any, ) -> _ProxyTracer: with self.lock: def make() -> Tracer: - return self.provider.get_tracer( - instrumenting_module_name=instrumenting_module_name, - instrumenting_library_version=instrumenting_library_version, - schema_url=schema_url, - ) + return self.provider.get_tracer(*args, **kwargs) tracer = _ProxyTracer(make(), self, is_span_tracer) self.tracers[tracer] = make diff --git a/requirements-dev.lock b/requirements-dev.lock index f718d38f7..db291303c 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -6,6 +6,7 @@ # features: [] # all-features: false # with-sources: false +# generate-hashes: false -e file:. aiohttp==3.9.5 @@ -73,6 +74,7 @@ coverage==7.6.0 deprecated==1.2.14 # via opentelemetry-api # via opentelemetry-exporter-otlp-proto-http + # via opentelemetry-semantic-conventions dirty-equals==0.7.1.post0 distlib==0.3.8 # via virtualenv @@ -118,7 +120,7 @@ httpx==0.27.0 # via anthropic # via fastapi # via openai -huggingface-hub==0.24.0 +huggingface-hub==0.24.2 # via tokenizers identify==2.6.0 # via pre-commit @@ -128,12 +130,12 @@ idna==3.7 # via httpx # via requests # via yarl -importlib-metadata==7.1.0 +importlib-metadata==8.0.0 # via opentelemetry-api # via opentelemetry-instrumentation-flask iniconfig==2.0.0 # via pytest -inline-snapshot==0.11.0 +inline-snapshot==0.12.0 itsdangerous==2.2.0 # via flask jinja2==3.1.4 @@ -175,7 +177,7 @@ mkdocs-autorefs==1.0.1 mkdocs-get-deps==0.2.0 # via mkdocs mkdocs-glightbox==0.4.0 -mkdocs-material==9.5.29 +mkdocs-material==9.5.30 mkdocs-material-extensions==1.3.1 # via mkdocs-material mkdocstrings==0.25.1 @@ -191,10 +193,10 @@ mypy-extensions==1.0.0 nodeenv==1.9.1 # via pre-commit # via pyright -numpy==2.0.0 +numpy==2.0.1 # via pandas -openai==1.36.0 -opentelemetry-api==1.25.0 +openai==1.37.0 +opentelemetry-api==1.26.0 # via opentelemetry-exporter-otlp-proto-http # via opentelemetry-instrumentation # via opentelemetry-instrumentation-aiohttp-client @@ -217,11 +219,11 @@ opentelemetry-api==1.25.0 # via opentelemetry-instrumentation-wsgi # via opentelemetry-sdk # via opentelemetry-semantic-conventions -opentelemetry-exporter-otlp-proto-common==1.25.0 +opentelemetry-exporter-otlp-proto-common==1.26.0 # via opentelemetry-exporter-otlp-proto-http -opentelemetry-exporter-otlp-proto-http==1.25.0 +opentelemetry-exporter-otlp-proto-http==1.26.0 # via logfire -opentelemetry-instrumentation==0.46b0 +opentelemetry-instrumentation==0.47b0 # via logfire # via opentelemetry-instrumentation-aiohttp-client # via opentelemetry-instrumentation-asgi @@ -241,37 +243,37 @@ opentelemetry-instrumentation==0.46b0 # via opentelemetry-instrumentation-starlette # via opentelemetry-instrumentation-system-metrics # via opentelemetry-instrumentation-wsgi -opentelemetry-instrumentation-aiohttp-client==0.46b0 -opentelemetry-instrumentation-asgi==0.46b0 +opentelemetry-instrumentation-aiohttp-client==0.47b0 +opentelemetry-instrumentation-asgi==0.47b0 # via opentelemetry-instrumentation-fastapi # via opentelemetry-instrumentation-starlette -opentelemetry-instrumentation-asyncpg==0.46b0 -opentelemetry-instrumentation-celery==0.46b0 -opentelemetry-instrumentation-dbapi==0.46b0 +opentelemetry-instrumentation-asyncpg==0.47b0 +opentelemetry-instrumentation-celery==0.47b0 +opentelemetry-instrumentation-dbapi==0.47b0 # via opentelemetry-instrumentation-psycopg # via opentelemetry-instrumentation-psycopg2 -opentelemetry-instrumentation-django==0.46b0 -opentelemetry-instrumentation-fastapi==0.46b0 -opentelemetry-instrumentation-flask==0.46b0 -opentelemetry-instrumentation-httpx==0.46b0 -opentelemetry-instrumentation-psycopg==0.46b0 -opentelemetry-instrumentation-psycopg2==0.46b0 -opentelemetry-instrumentation-pymongo==0.46b0 -opentelemetry-instrumentation-redis==0.46b0 -opentelemetry-instrumentation-requests==0.46b0 -opentelemetry-instrumentation-sqlalchemy==0.46b0 -opentelemetry-instrumentation-starlette==0.46b0 -opentelemetry-instrumentation-system-metrics==0.46b0 -opentelemetry-instrumentation-wsgi==0.46b0 +opentelemetry-instrumentation-django==0.47b0 +opentelemetry-instrumentation-fastapi==0.47b0 +opentelemetry-instrumentation-flask==0.47b0 +opentelemetry-instrumentation-httpx==0.47b0 +opentelemetry-instrumentation-psycopg==0.47b0 +opentelemetry-instrumentation-psycopg2==0.47b0 +opentelemetry-instrumentation-pymongo==0.47b0 +opentelemetry-instrumentation-redis==0.47b0 +opentelemetry-instrumentation-requests==0.47b0 +opentelemetry-instrumentation-sqlalchemy==0.47b0 +opentelemetry-instrumentation-starlette==0.47b0 +opentelemetry-instrumentation-system-metrics==0.47b0 +opentelemetry-instrumentation-wsgi==0.47b0 # via opentelemetry-instrumentation-django # via opentelemetry-instrumentation-flask -opentelemetry-proto==1.25.0 +opentelemetry-proto==1.26.0 # via opentelemetry-exporter-otlp-proto-common # via opentelemetry-exporter-otlp-proto-http -opentelemetry-sdk==1.25.0 +opentelemetry-sdk==1.26.0 # via logfire # via opentelemetry-exporter-otlp-proto-http -opentelemetry-semantic-conventions==0.46b0 +opentelemetry-semantic-conventions==0.47b0 # via opentelemetry-instrumentation-aiohttp-client # via opentelemetry-instrumentation-asgi # via opentelemetry-instrumentation-asyncpg @@ -288,7 +290,7 @@ opentelemetry-semantic-conventions==0.46b0 # via opentelemetry-instrumentation-starlette # via opentelemetry-instrumentation-wsgi # via opentelemetry-sdk -opentelemetry-util-http==0.46b0 +opentelemetry-util-http==0.47b0 # via opentelemetry-instrumentation-aiohttp-client # via opentelemetry-instrumentation-asgi # via opentelemetry-instrumentation-django @@ -321,11 +323,11 @@ pluggy==1.5.0 pre-commit==3.7.1 prompt-toolkit==3.0.47 # via click-repl -protobuf==4.25.3 +protobuf==4.25.4 # via googleapis-common-protos # via logfire # via opentelemetry-proto -psutil==5.9.8 +psutil==6.0.0 # via opentelemetry-instrumentation-system-metrics psycopg==3.2.1 psycopg-binary==3.2.1 @@ -345,7 +347,7 @@ pymdown-extensions==10.8.1 # via mkdocs-material # via mkdocstrings pymongo==4.8.0 -pyright==1.1.372 +pyright==1.1.373 pytest==8.3.1 # via pytest-django # via pytest-pretty @@ -373,7 +375,7 @@ pyyaml==6.0.1 pyyaml-env-tag==0.1 # via mkdocs redis==5.0.7 -regex==2024.5.15 +regex==2024.7.24 # via mkdocs-material requests==2.32.3 # via huggingface-hub @@ -386,8 +388,8 @@ rich==13.7.1 # via logfire # via pytest-pretty # via typer -ruff==0.5.3 -setuptools==71.0.4 +ruff==0.5.4 +setuptools==71.1.0 # via opentelemetry-instrumentation shellingham==1.5.4 # via typer @@ -401,7 +403,7 @@ sniffio==1.3.1 # via openai sqlalchemy==2.0.31 # via sqlmodel -sqlmodel==0.0.20 +sqlmodel==0.0.21 sqlparse==0.5.1 # via django starlette==0.37.2 @@ -422,6 +424,7 @@ typing-extensions==4.12.2 # via anthropic # via fastapi # via huggingface-hub + # via inline-snapshot # via logfire # via mypy # via openai diff --git a/requirements.lock b/requirements.lock index 8bae045c1..a988faa43 100644 --- a/requirements.lock +++ b/requirements.lock @@ -6,6 +6,7 @@ # features: [] # all-features: false # with-sources: false +# generate-hashes: false -e file:. certifi==2024.7.4 @@ -15,38 +16,39 @@ charset-normalizer==3.3.2 deprecated==1.2.14 # via opentelemetry-api # via opentelemetry-exporter-otlp-proto-http + # via opentelemetry-semantic-conventions executing==2.0.1 # via logfire googleapis-common-protos==1.63.2 # via opentelemetry-exporter-otlp-proto-http idna==3.7 # via requests -importlib-metadata==7.1.0 +importlib-metadata==8.0.0 # via opentelemetry-api markdown-it-py==3.0.0 # via rich mdurl==0.1.2 # via markdown-it-py -opentelemetry-api==1.25.0 +opentelemetry-api==1.26.0 # via opentelemetry-exporter-otlp-proto-http # via opentelemetry-instrumentation # via opentelemetry-sdk # via opentelemetry-semantic-conventions -opentelemetry-exporter-otlp-proto-common==1.25.0 +opentelemetry-exporter-otlp-proto-common==1.26.0 # via opentelemetry-exporter-otlp-proto-http -opentelemetry-exporter-otlp-proto-http==1.25.0 +opentelemetry-exporter-otlp-proto-http==1.26.0 # via logfire -opentelemetry-instrumentation==0.46b0 +opentelemetry-instrumentation==0.47b0 # via logfire -opentelemetry-proto==1.25.0 +opentelemetry-proto==1.26.0 # via opentelemetry-exporter-otlp-proto-common # via opentelemetry-exporter-otlp-proto-http -opentelemetry-sdk==1.25.0 +opentelemetry-sdk==1.26.0 # via logfire # via opentelemetry-exporter-otlp-proto-http -opentelemetry-semantic-conventions==0.46b0 +opentelemetry-semantic-conventions==0.47b0 # via opentelemetry-sdk -protobuf==4.25.3 +protobuf==4.25.4 # via googleapis-common-protos # via logfire # via opentelemetry-proto @@ -56,7 +58,7 @@ requests==2.32.3 # via opentelemetry-exporter-otlp-proto-http rich==13.7.1 # via logfire -setuptools==71.0.4 +setuptools==71.1.0 # via opentelemetry-instrumentation typing-extensions==4.12.2 # via logfire diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 28e097603..8f6a31e38 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -146,7 +146,7 @@ def test_create_metric_gauge(metrics_reader: InMemoryMetricReader) -> None: 'data_points': [ { 'attributes': {}, - 'start_time_unix_nano': 0, + 'start_time_unix_nano': None, 'time_unix_nano': IsInt(), 'value': 1, } @@ -169,7 +169,7 @@ def test_create_metric_gauge(metrics_reader: InMemoryMetricReader) -> None: 'data_points': [ { 'attributes': {}, - 'start_time_unix_nano': 0, + 'start_time_unix_nano': None, 'time_unix_nano': IsInt(), 'value': 24, } @@ -278,7 +278,7 @@ def observable_gauge(options: CallbackOptions): 'data_points': [ { 'attributes': {}, - 'start_time_unix_nano': 0, + 'start_time_unix_nano': None, 'time_unix_nano': IsInt(), 'value': 4000, }