|
4 | 4 | from types import TracebackType
|
5 | 5 | from typing import TYPE_CHECKING, Any, Generic, Literal, TypedDict, TypeVar
|
6 | 6 |
|
| 7 | +from typing_extensions import Self |
| 8 | + |
| 9 | +from logfire._internal.config import get_base_url_from_token |
| 10 | + |
7 | 11 | try:
|
8 | 12 | from httpx import AsyncClient, Client, Response, Timeout
|
9 | 13 | from httpx._client import BaseClient
|
@@ -56,8 +60,6 @@ class RowQueryResults(TypedDict):
|
56 | 60 |
|
57 | 61 |
|
58 | 62 | T = TypeVar('T', bound=BaseClient)
|
59 |
| -S = TypeVar('S', bound='LogfireQueryClient') |
60 |
| -R = TypeVar('R', bound='AsyncLogfireQueryClient') |
61 | 63 |
|
62 | 64 |
|
63 | 65 | class _BaseLogfireQueryClient(Generic[T]):
|
@@ -102,13 +104,14 @@ class LogfireQueryClient(_BaseLogfireQueryClient[Client]):
|
102 | 104 | def __init__(
|
103 | 105 | self,
|
104 | 106 | read_token: str,
|
105 |
| - base_url: str = 'https://logfire-api.pydantic.dev/', |
| 107 | + base_url: str | None = None, |
106 | 108 | timeout: Timeout = DEFAULT_TIMEOUT,
|
107 | 109 | **client_kwargs: Any,
|
108 | 110 | ):
|
| 111 | + base_url = base_url or get_base_url_from_token(read_token) |
109 | 112 | super().__init__(base_url, read_token, timeout, Client, **client_kwargs)
|
110 | 113 |
|
111 |
| - def __enter__(self: S) -> S: |
| 114 | + def __enter__(self) -> Self: |
112 | 115 | self.client.__enter__()
|
113 | 116 | return self
|
114 | 117 |
|
@@ -226,13 +229,14 @@ class AsyncLogfireQueryClient(_BaseLogfireQueryClient[AsyncClient]):
|
226 | 229 | def __init__(
|
227 | 230 | self,
|
228 | 231 | read_token: str,
|
229 |
| - base_url: str = 'https://logfire-api.pydantic.dev/', |
| 232 | + base_url: str | None = None, |
230 | 233 | timeout: Timeout = DEFAULT_TIMEOUT,
|
231 | 234 | **async_client_kwargs: Any,
|
232 | 235 | ):
|
| 236 | + base_url = base_url or get_base_url_from_token(read_token) |
233 | 237 | super().__init__(base_url, read_token, timeout, AsyncClient, **async_client_kwargs)
|
234 | 238 |
|
235 |
| - async def __aenter__(self: R) -> R: |
| 239 | + async def __aenter__(self) -> Self: |
236 | 240 | await self.client.__aenter__()
|
237 | 241 | return self
|
238 | 242 |
|
|
0 commit comments