Skip to content

Commit 153e67a

Browse files
authored
Infer staging regions from write tokens (#1037)
1 parent 143ab85 commit 153e67a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

logfire/_internal/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,12 @@ def get_base_url_from_token(token: str) -> str:
17481748
region = 'us'
17491749
if match := PYDANTIC_LOGFIRE_TOKEN_PATTERN.match(token):
17501750
region = match.group('region')
1751+
1752+
if region == 'stagingus':
1753+
return 'https://logfire-us.pydantic.info'
1754+
elif region == 'stagingeu':
1755+
return 'https://logfire-eu.pydantic.info'
1756+
17511757
if region not in REGIONS:
17521758
region = 'us'
17531759

tests/test_configure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
LogfireConfig,
5151
LogfireCredentials,
5252
_get_token_repr, # type: ignore
53+
get_base_url_from_token,
5354
sanitize_project_name,
5455
)
5556
from logfire._internal.exporters.console import ConsoleLogExporter, ShowParentsConsoleSpanExporter
@@ -2272,3 +2273,8 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
22722273

22732274
assert exporter.export([]) == SpanExportResult.FAILURE
22742275
assert not caplog.messages
2276+
2277+
2278+
def test_staging_token_regions():
2279+
assert get_base_url_from_token('pylf_v1_stagingeu_123456') == 'https://logfire-eu.pydantic.info'
2280+
assert get_base_url_from_token('pylf_v1_stagingus_123456') == 'https://logfire-us.pydantic.info'

0 commit comments

Comments
 (0)