Skip to content

Commit

Permalink
Don't use logfire_instance in instrument_django (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Dec 27, 2024
1 parent 00656c1 commit 0ec183b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
28 changes: 20 additions & 8 deletions logfire/_internal/integrations/django.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Any
from __future__ import annotations

from typing import Any, Callable

from django.http import HttpRequest, HttpResponse
from opentelemetry.trace import Span

from logfire import Logfire
from logfire._internal.utils import maybe_capture_server_headers

try:
Expand All @@ -13,16 +17,24 @@
)


def instrument_django(logfire_instance: Logfire, *, capture_headers: bool = False, **kwargs: Any):
def instrument_django(
*,
capture_headers: bool,
is_sql_commentor_enabled: bool | None,
excluded_urls: str | None,
request_hook: Callable[[Span, HttpRequest], None] | None,
response_hook: Callable[[Span, HttpRequest, HttpResponse], None] | None,
**kwargs: Any,
) -> None:
"""Instrument the `django` module so that spans are automatically created for each web request.
See the `Logfire.instrument_django` method for details.
"""
maybe_capture_server_headers(capture_headers)
DjangoInstrumentor().instrument(
**{
'tracer_provider': logfire_instance.config.get_tracer_provider(),
'meter_provider': logfire_instance.config.get_meter_provider(),
**kwargs,
}
excluded_urls=excluded_urls,
is_sql_commentor_enabled=is_sql_commentor_enabled,
request_hook=request_hook,
response_hook=response_hook,
**kwargs,
)
11 changes: 7 additions & 4 deletions logfire/_internal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,8 @@ def instrument_django(
self,
capture_headers: bool = False,
is_sql_commentor_enabled: bool | None = None,
request_hook: Callable[[Span, HttpRequest], None] | None = None,
response_hook: Callable[[Span, HttpRequest, HttpResponse], None] | None = None,
request_hook: Callable[[trace_api.Span, HttpRequest], None] | None = None,
response_hook: Callable[[trace_api.Span, HttpRequest, HttpResponse], None] | None = None,
excluded_urls: str | None = None,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -1327,13 +1327,16 @@ def instrument_django(

self._warn_if_not_initialized_for_instrumentation()
return instrument_django(
self,
capture_headers=capture_headers,
is_sql_commentor_enabled=is_sql_commentor_enabled,
request_hook=request_hook,
response_hook=response_hook,
excluded_urls=excluded_urls,
**kwargs,
**{
'tracer_provider': self._config.get_tracer_provider(),
'meter_provider': self._config.get_meter_provider(),
**kwargs,
},
)

def instrument_requests(
Expand Down

0 comments on commit 0ec183b

Please sign in to comment.