Skip to content

Commit e94a288

Browse files
authored
Support OpenTelemetry 1.30.0 (#839)
1 parent 4c83f5c commit e94a288

File tree

10 files changed

+540
-408
lines changed

10 files changed

+540
-408
lines changed

logfire/_internal/ast_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def rewrite_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef, qualnam
106106

107107
return ast.fix_missing_locations(
108108
ast.copy_location(
109-
type(node)(
109+
type(node)( # type: ignore
110110
name=node.name,
111111
args=node.args,
112112
body=new_body,

logfire/_internal/integrations/pymongo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
try:
99
from opentelemetry.instrumentation.pymongo import (
1010
PymongoInstrumentor,
11-
dummy_callback, # type: ignore[reportUnknownVariableType]
11+
dummy_callback,
1212
)
1313
except ImportError:
1414
raise RuntimeError(

logfire/_internal/metrics.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,15 @@ def get_meter(
4444
name: str,
4545
version: str | None = None,
4646
schema_url: str | None = None,
47-
*args: Any,
48-
**kwargs: Any,
47+
attributes: Attributes | None = None,
4948
) -> Meter:
5049
with self.lock:
5150
if name in self.suppressed_scopes:
5251
provider = NoOpMeterProvider()
5352
else:
5453
provider = self.provider
55-
meter = _ProxyMeter(
56-
provider.get_meter(name, version=version, schema_url=schema_url, *args, **kwargs),
57-
name,
58-
version,
59-
schema_url,
60-
)
54+
inner_meter = provider.get_meter(name, version, schema_url, attributes)
55+
meter = _ProxyMeter(inner_meter, name, version, schema_url)
6156
self.meters.add(meter)
6257
return meter
6358

@@ -160,9 +155,12 @@ def create_histogram(
160155
name: str,
161156
unit: str = '',
162157
description: str = '',
158+
**kwargs: Any,
163159
) -> Histogram:
164160
with self._lock:
165-
proxy = _ProxyHistogram(self._meter.create_histogram(name, unit, description), name, unit, description)
161+
proxy = _ProxyHistogram(
162+
self._meter.create_histogram(name, unit, description, **kwargs), name, unit, description
163+
)
166164
self._instruments.add(proxy)
167165
return proxy
168166

logfire/_internal/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def end(self, end_time: int | None = None) -> None:
137137
def get_span_context(self) -> SpanContext:
138138
return self.span.get_span_context()
139139

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

143143
def set_attribute(self, key: str, value: otel_types.AttributeValue) -> None:

logfire/integrations/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
if TYPE_CHECKING:
88
from wsgiref.types import WSGIEnvironment
99

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

1313
RequestHook = Callable[[Span, 'WSGIEnvironment'], None]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ classifiers = [
4646
"Framework :: OpenTelemetry :: Instrumentations",
4747
]
4848
dependencies = [
49-
"opentelemetry-sdk >= 1.21.0",
50-
"opentelemetry-exporter-otlp-proto-http >= 1.21.0",
49+
"opentelemetry-sdk >= 1.26.0, < 1.31.0",
50+
"opentelemetry-exporter-otlp-proto-http >= 1.26.0, < 1.31.0",
5151
"opentelemetry-instrumentation >= 0.41b0",
5252
"rich >= 13.4.2",
5353
"protobuf >= 4.23.4",

tests/otel_integrations/test_aws_lambda.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def lambda_handler(event: Any, context: MockLambdaContext):
2323
pass
2424

2525

26+
HANDLER_NAME = f'{__name__}.{lambda_handler.__name__}'
27+
28+
2629
# The below mock is based on the following code:
2730
# https://github.com/open-telemetry/opentelemetry-python-contrib/blob/ecf5529f99222e7d945eddcaa83acb8a47c9ba42/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py#L57-L66
2831
@dataclass
@@ -39,7 +42,7 @@ def test_instrument_aws_lambda(exporter: TestExporter) -> None:
3942
with logfire.span('span'):
4043
current_context = get_context()
4144

42-
with mock.patch.dict('os.environ', {_HANDLER: 'tests.otel_integrations.test_aws_lambda.lambda_handler'}):
45+
with mock.patch.dict('os.environ', {_HANDLER: HANDLER_NAME, 'AWS_LAMBDA_FUNCTION_NAME': HANDLER_NAME}):
4346
logfire.instrument_aws_lambda(lambda_handler, event_context_extractor=event_context_extractor)
4447

4548
context = MockLambdaContext(
@@ -66,14 +69,14 @@ def test_instrument_aws_lambda(exporter: TestExporter) -> None:
6669
},
6770
},
6871
{
69-
'name': 'tests.otel_integrations.test_aws_lambda.lambda_handler',
72+
'name': HANDLER_NAME,
7073
'context': {'trace_id': 1, 'span_id': 3, 'is_remote': False},
7174
'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': True},
7275
'start_time': 3000000000,
7376
'end_time': 4000000000,
7477
'attributes': {
7578
'logfire.span_type': 'span',
76-
'logfire.msg': 'tests.otel_integrations.test_aws_lambda.lambda_handler',
79+
'logfire.msg': HANDLER_NAME,
7780
'cloud.resource_id': 'arn:aws:lambda:us-east-1:123456:function:myfunction:myalias',
7881
'faas.invocation_id': 'mock_aws_request_id',
7982
'cloud.account.id': '123456',

tests/otel_integrations/test_mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def test_instrument_mysql_connection(exporter: TestExporter, mysql_container: My
115115
)
116116

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

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

tests/otel_integrations/test_psycopg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313

1414

1515
def test_check_version():
16-
assert check_version('psycopg2', '2.7.3.1', Psycopg2Instrumentor())
17-
assert not check_version('psycopg2', '2.7.3.0', Psycopg2Instrumentor())
16+
assert check_version('psycopg2-binary', '2.7.3.1', Psycopg2Instrumentor())
17+
assert not check_version('psycopg2-binary', '2.7.3.0', Psycopg2Instrumentor())
1818
assert check_version('psycopg', '3.1.0', PsycopgInstrumentor())
1919
assert not check_version('psycopg', '3.0.1', PsycopgInstrumentor())
2020

2121
assert check_version(psycopg.__name__, psycopg.__version__, PsycopgInstrumentor())
22-
assert check_version(psycopg2.__name__, psycopg2.__version__, Psycopg2Instrumentor()) # type: ignore
2322

2423

2524
def test_instrument_psycopg():

0 commit comments

Comments
 (0)