Skip to content

Commit

Permalink
Upgrade deps, handle attributes argument of get_meter more simply and…
Browse files Browse the repository at this point in the history
… correctly
  • Loading branch information
alexmojaki committed Feb 4, 2025
1 parent 4c83f5c commit ba50f6a
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 396 deletions.
2 changes: 1 addition & 1 deletion logfire/_internal/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def rewrite_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef, qualnam

return ast.fix_missing_locations(
ast.copy_location(
type(node)(
type(node)( # type: ignore
name=node.name,
args=node.args,
body=new_body,
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
from opentelemetry.instrumentation.pymongo import (
PymongoInstrumentor,
dummy_callback, # type: ignore[reportUnknownVariableType]
dummy_callback,
)
except ImportError:
raise RuntimeError(
Expand Down
16 changes: 7 additions & 9 deletions logfire/_internal/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,15 @@ def get_meter(
name: str,
version: str | None = None,
schema_url: str | None = None,
*args: Any,
**kwargs: Any,
attributes: Attributes | None = None,
) -> Meter:
with self.lock:
if name in self.suppressed_scopes:
provider = NoOpMeterProvider()
else:
provider = self.provider
meter = _ProxyMeter(
provider.get_meter(name, version=version, schema_url=schema_url, *args, **kwargs),
name,
version,
schema_url,
)
inner_meter = provider.get_meter(name, version, schema_url, attributes)
meter = _ProxyMeter(inner_meter, name, version, schema_url)
self.meters.add(meter)
return meter

Expand Down Expand Up @@ -160,9 +155,12 @@ def create_histogram(
name: str,
unit: str = '',
description: str = '',
**kwargs: Any,
) -> Histogram:
with self._lock:
proxy = _ProxyHistogram(self._meter.create_histogram(name, unit, description), name, unit, description)
proxy = _ProxyHistogram(
self._meter.create_histogram(name, unit, description, **kwargs), name, unit, description
)
self._instruments.add(proxy)
return proxy

Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def end(self, end_time: int | None = None) -> None:
def get_span_context(self) -> SpanContext:
return self.span.get_span_context()

def set_attributes(self, attributes: dict[str, otel_types.AttributeValue]) -> None:
def set_attributes(self, attributes: Mapping[str, otel_types.AttributeValue]) -> None:
self.span.set_attributes(attributes)

def set_attribute(self, key: str, value: otel_types.AttributeValue) -> None:
Expand Down
2 changes: 1 addition & 1 deletion logfire/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if TYPE_CHECKING:
from wsgiref.types import WSGIEnvironment

ResponseHook = Callable[[Span, 'WSGIEnvironment', int, 'list[tuple[str, str]]'], None]
ResponseHook = Callable[[Span, 'WSGIEnvironment', str, 'list[tuple[str, str]]'], None]
"""A callback called when a response is sent by the server."""

RequestHook = Callable[[Span, 'WSGIEnvironment'], None]
Expand Down
4 changes: 2 additions & 2 deletions tests/otel_integrations/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def test_instrument_mysql_connection(exporter: TestExporter, mysql_container: My
)

conn = MySQLInstrumentor().uninstrument_connection(conn) # type: ignore
with conn.cursor() as cursor: # type: ignore
cursor.execute('INSERT INTO test (id, name) VALUES (2, "test-2")') # type: ignore
with conn.cursor() as cursor:
cursor.execute('INSERT INTO test (id, name) VALUES (2, "test-2")')

assert len(exporter.exported_spans_as_dict()) == 1

Expand Down
894 changes: 513 additions & 381 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit ba50f6a

Please sign in to comment.