Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to OTEL 1.29.0 #669

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def instrument_aiohttp_client(logfire_instance: Logfire, **kwargs: Any):

See the `Logfire.instrument_aiohttp_client` method for details.
"""
AioHttpClientInstrumentor().instrument( # type: ignore[reportUnknownMemberType]
AioHttpClientInstrumentor().instrument(
**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
'meter_provider': logfire_instance.config.get_meter_provider(),
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def instrument_asyncpg(logfire_instance: Logfire, **kwargs: Unpack[AsyncPGInstru

See the `Logfire.instrument_asyncpg` method for details.
"""
AsyncPGInstrumentor().instrument( # type: ignore[reportUnknownMemberType]
AsyncPGInstrumentor().instrument(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
'meter_provider': logfire_instance.config.get_meter_provider(),
Expand Down
4 changes: 1 addition & 3 deletions logfire/_internal/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ def instrument_aws_lambda(

See the `Logfire.instrument_aws_lambda` method for details.
"""
return AwsLambdaInstrumentor().instrument( # type: ignore[no-any-return]
tracer_provider=tracer_provider, meter_provider=meter_provider, **kwargs
)
return AwsLambdaInstrumentor().instrument(tracer_provider=tracer_provider, meter_provider=meter_provider, **kwargs)
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def instrument_celery(logfire_instance: Logfire, **kwargs: Unpack[CeleryInstrume

See the `Logfire.instrument_celery` method for details.
"""
return CeleryInstrumentor().instrument( # type: ignore[reportUnknownMemberType]
return CeleryInstrumentor().instrument(
**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
'meter_provider': logfire_instance.config.get_meter_provider(),
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def instrument_django(logfire_instance: Logfire, *, capture_headers: bool = Fals
See the `Logfire.instrument_django` method for details.
"""
maybe_capture_server_headers(capture_headers)
DjangoInstrumentor().instrument( # type: ignore[reportUnknownMemberType]
DjangoInstrumentor().instrument(
**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
'meter_provider': logfire_instance.config.get_meter_provider(),
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ def instrument_httpx(
response_hook=final_kwargs.get('response_hook'),
)
else:
instrumentor.instrument(**final_kwargs) # type: ignore[reportUnknownMemberType]
instrumentor.instrument(**final_kwargs)
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def instrument_pymongo(**kwargs: Unpack[PymongoInstrumentKwargs]) -> None:

See the `Logfire.instrument_pymongo` method for details.
"""
PymongoInstrumentor().instrument(**kwargs) # type: ignore[reportUnknownMemberType]
PymongoInstrumentor().instrument(**kwargs)
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def instrument_redis(capture_statement: bool = False, **kwargs: Unpack[RedisInst
if capture_statement:
request_hook = _capture_statement_hook(request_hook)

RedisInstrumentor().instrument(request_hook=request_hook, **kwargs) # type: ignore[reportUnknownMemberType]
RedisInstrumentor().instrument(request_hook=request_hook, **kwargs) # type: ignore


def _capture_statement_hook(request_hook: RequestHook | None = None) -> RequestHook:
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def instrument_requests(logfire_instance: Logfire, excluded_urls: Optional[str]

See the `Logfire.instrument_requests` method for details.
"""
RequestsInstrumentor().instrument( # type: ignore[reportUnknownMemberType]
RequestsInstrumentor().instrument(
excluded_urls=excluded_urls,
**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def instrument_sqlalchemy(**kwargs: Unpack[SQLAlchemyInstrumentKwargs]) -> None:

See the `Logfire.instrument_sqlalchemy` method for details.
"""
SQLAlchemyInstrumentor().instrument(**kwargs) # type: ignore[reportUnknownMemberType]
SQLAlchemyInstrumentor().instrument(**kwargs)
4 changes: 2 additions & 2 deletions logfire/_internal/integrations/sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def instrument_sqlite3(
See the `Logfire.instrument_sqlite3` method for details.
"""
if conn is not None:
return SQLite3Instrumentor().instrument_connection(conn, tracer_provider=tracer_provider) # type: ignore[reportUnknownMemberType]
return SQLite3Instrumentor().instrument_connection(conn, tracer_provider=tracer_provider)
else:
return SQLite3Instrumentor().instrument(tracer_provider=tracer_provider, **kwargs) # type: ignore[reportUnknownMemberType]
return SQLite3Instrumentor().instrument(tracer_provider=tracer_provider, **kwargs) # type: ignore
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def instrument_starlette(
See the `Logfire.instrument_starlette` method for details.
"""
maybe_capture_server_headers(capture_headers)
StarletteInstrumentor().instrument_app( # type: ignore[reportUnknownMemberType]
StarletteInstrumentor().instrument_app(
app,
**{ # type: ignore
'tracer_provider': tweak_asgi_spans_tracer_provider(logfire_instance, record_send_receive),
Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/integrations/system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def instrument_system_metrics(logfire_instance: Logfire, config: Config | None =
del config['process.runtime.cpu.utilization']

instrumentor = SystemMetricsInstrumentor(config=config) # type: ignore
instrumentor.instrument(meter_provider=logfire_instance.config.get_meter_provider()) # type: ignore
instrumentor.instrument(meter_provider=logfire_instance.config.get_meter_provider())


def measure_simple_cpu_utilization(logfire_instance: Logfire):
Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_asyncpg() -> None:
original_execute = asyncpg.Connection.execute # type: ignore[reportUnknownMemberType]
logfire.instrument_asyncpg()
assert original_execute is not asyncpg.Connection.execute # type: ignore[reportUnknownMemberType]
AsyncPGInstrumentor().uninstrument() # type: ignore[reportUnknownMemberType]
AsyncPGInstrumentor().uninstrument()
assert original_execute is asyncpg.Connection.execute # type: ignore[reportUnknownMemberType]


Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def say_hello(): # type: ignore
try:
yield app
finally:
CeleryInstrumentor().uninstrument() # type: ignore
CeleryInstrumentor().uninstrument()


@pytest.fixture(autouse=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handler(request: Request):
try:
response = client.get('https://example.org/')
finally:
HTTPXClientInstrumentor().uninstrument() # type: ignore
HTTPXClientInstrumentor().uninstrument()
# Validation of context propagation: ensure that the traceparent header contains the trace ID
traceparent_header = response.headers['traceparent']
assert f'{trace_id:032x}' == traceparent_header.split('-')[1]
Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_mysql_instrumentation(exporter: TestExporter, mysql_container: MySqlCon
},
]
)
MySQLInstrumentor().uninstrument() # type: ignore
MySQLInstrumentor().uninstrument()


def test_instrument_mysql_connection(exporter: TestExporter, mysql_container: MySqlContainer):
Expand Down
12 changes: 6 additions & 6 deletions tests/otel_integrations/test_psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def test_instrument_psycopg():

instrument_psycopg(psycopg)
assert original_connect is not psycopg.connect
PsycopgInstrumentor().uninstrument() # type: ignore
PsycopgInstrumentor().uninstrument()
assert original_connect is psycopg.connect

instrument_psycopg('psycopg')
assert original_connect is not psycopg.connect
PsycopgInstrumentor().uninstrument() # type: ignore
PsycopgInstrumentor().uninstrument()
assert original_connect is psycopg.connect


Expand All @@ -41,12 +41,12 @@ def test_instrument_psycopg2():

instrument_psycopg(psycopg2)
assert original_connect is not psycopg2.connect
Psycopg2Instrumentor().uninstrument() # type: ignore
Psycopg2Instrumentor().uninstrument()
assert original_connect is psycopg2.connect

instrument_psycopg('psycopg2')
assert original_connect is not psycopg2.connect
Psycopg2Instrumentor().uninstrument() # type: ignore
Psycopg2Instrumentor().uninstrument()
assert original_connect is psycopg2.connect


Expand All @@ -57,8 +57,8 @@ def test_instrument_both():
instrument_psycopg()
assert original_connect is not psycopg.connect
assert original_connect2 is not psycopg2.connect
PsycopgInstrumentor().uninstrument() # type: ignore
Psycopg2Instrumentor().uninstrument() # type: ignore
PsycopgInstrumentor().uninstrument()
Psycopg2Instrumentor().uninstrument()
assert original_connect is psycopg.connect
assert original_connect2 is psycopg2.connect

Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def uninstrument_redis():
try:
yield
finally:
RedisInstrumentor().uninstrument() # type: ignore
RedisInstrumentor().uninstrument()


def test_instrument_redis(redis: Redis, redis_port: str, exporter: TestExporter):
Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def send(self: Any, request: requests.Request, **kwargs: Any):
logfire.instrument_requests()
yield
instrumentor = RequestsInstrumentor()
instrumentor.uninstrument() # type: ignore
instrumentor.uninstrument()


@pytest.mark.anyio
Expand Down
4 changes: 2 additions & 2 deletions tests/otel_integrations/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
# Need to ensure this import happens _after_ importing sqlalchemy
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

logfire.instrument_sqlalchemy(engine=engine, enable_commenter=True, commenter_options={})
logfire.instrument_sqlalchemy(engine=engine)

class Base(DeclarativeBase):
pass
Expand Down Expand Up @@ -204,7 +204,7 @@ class AuthRecord(Base):
]
)

SQLAlchemyInstrumentor().uninstrument() # type: ignore[reportUnknownMemberType]
SQLAlchemyInstrumentor().uninstrument()


def test_missing_opentelemetry_dependency() -> None:
Expand Down
10 changes: 5 additions & 5 deletions tests/otel_integrations/test_sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_sqlite3_instrumentation(exporter: TestExporter):
]
)

SQLite3Instrumentor().uninstrument() # type: ignore
SQLite3Instrumentor().uninstrument()


def test_instrument_sqlite3_connection(exporter: TestExporter):
Expand Down Expand Up @@ -132,11 +132,11 @@ def test_instrument_sqlite3_connection(exporter: TestExporter):
]
)
spans_before_uninstrument = len(exporter.exported_spans_as_dict())
conn: sqlite3.Connection = SQLite3Instrumentor().uninstrument_connection(conn) # type: ignore
cur = conn.cursor() # type: ignore
cur.execute('INSERT INTO test (id, name) VALUES (2, "test-2")') # type: ignore
conn: sqlite3.Connection = SQLite3Instrumentor().uninstrument_connection(conn)
cur = conn.cursor()
cur.execute('INSERT INTO test (id, name) VALUES (2, "test-2")')
assert len(exporter.exported_spans_as_dict()) == spans_before_uninstrument
values = cur.execute('SELECT * FROM test').fetchall() # type: ignore
values = cur.execute('SELECT * FROM test').fetchall()
assert values == [(1, 'test'), (2, 'test-2')]


Expand Down
2 changes: 1 addition & 1 deletion tests/otel_integrations/test_system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_collected_metric_names(metrics_reader: InMemoryMetricReader) -> list[str
}
)
finally:
SystemMetricsInstrumentor().uninstrument() # type: ignore
SystemMetricsInstrumentor().uninstrument()


def test_default_system_metrics_collection(metrics_reader: InMemoryMetricReader) -> None:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,11 @@ def test_send_to_logfire_false() -> None:

def test_send_to_logfire_if_token_present() -> None:
with mock.patch('logfire._internal.config.Confirm.ask', side_effect=RuntimeError):
configure(send_to_logfire='if-token-present', console=False)
with requests_mock.Mocker() as request_mocker:
configure(send_to_logfire='if-token-present', console=False)
wait_for_check_token_thread()
assert GLOBAL_CONFIG.token is None
assert len(request_mocker.request_history) == 0


def test_send_to_logfire_if_token_present_empty() -> None:
Expand All @@ -1288,6 +1292,7 @@ def test_send_to_logfire_if_token_present_empty() -> None:
stack.enter_context(mock.patch('logfire._internal.config.Confirm.ask', side_effect=RuntimeError))
requests_mocker = stack.enter_context(requests_mock.Mocker())
configure(send_to_logfire='if-token-present', console=False)
wait_for_check_token_thread()
assert len(requests_mocker.request_history) == 0
finally:
del os.environ['LOGFIRE_TOKEN']
Expand Down
Loading
Loading