Skip to content

Commit 7b63d65

Browse files
committed
Comply with latest token format
1 parent d5cedcc commit 7b63d65

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

logfire/_internal/config.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
COMMON_REQUEST_HEADERS = {'User-Agent': f'logfire/{VERSION}'}
116116
"""Common request headers for requests to the Logfire API."""
117117
PROJECT_NAME_PATTERN = r'^[a-z0-9]+(?:-[a-z0-9]+)*$'
118+
PYDANTIC_LOGFIRE_TOKEN_PATTERN = re.compile(r'^pylf_v(?P<version>[0-9]+)_(?P<region>[a-z]+)_(?P<token>[a-zA-Z0-9]+)$')
118119

119120
METRICS_PREFERRED_TEMPORALITY = {
120121
Counter: AggregationTemporality.DELTA,
@@ -173,18 +174,20 @@ class AdvancedOptions:
173174
"""Configuration for OpenTelemetry logging. This is experimental and may be removed."""
174175

175176
def generate_base_url(self, token: str | None) -> str:
176-
if token and '-' in token:
177-
region, _ = token.split('-', maxsplit=1)
178-
else:
179-
region = None
180177
if self.base_url is not None:
181178
return self.base_url
182-
if region:
183-
return f'https://api-{region}.pydantic.dev'
184-
else:
185-
# default to us region for tokens that were created before regions were added
179+
180+
if token is None:
181+
# default to US region if no token is provided:
186182
return 'https://logfire-api.pydantic.dev'
187183

184+
match = PYDANTIC_LOGFIRE_TOKEN_PATTERN.match(token)
185+
if not match:
186+
# default to US region for tokens that were created before regions were added:
187+
return 'https://logfire-api.pydantic.dev'
188+
189+
return f'https://api-{match.group("region")}.pydantic.dev'
190+
188191

189192
@dataclass
190193
class PydanticPlugin:

logfire/_internal/config_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class _DefaultCallback:
9999
IGNORE_NO_CONFIG = ConfigParam(env_vars=['LOGFIRE_IGNORE_NO_CONFIG'], allow_file_config=True, default=False, tp=bool)
100100
"""Whether to show a warning message if logfire if used without calling logfire.configure()"""
101101
BASE_URL = ConfigParam(env_vars=['LOGFIRE_BASE_URL'], allow_file_config=True, default=None, tp=Union[str, None])
102+
"""The base URL of the Logfire backend. Primarily for testing purposes."""
102103
REGION = ConfigParam(env_vars=['LOGFIRE_REGION'], allow_file_config=True, default='us')
103104
"""The region of the Logfire backend."""
104-
"""The base URL of the Logfire backend. Primarily for testing purposes."""
105105
DISTRIBUTED_TRACING = ConfigParam(env_vars=['LOGFIRE_DISTRIBUTED_TRACING'], allow_file_config=True, default=None, tp=bool)
106106
"""Whether to extract incoming trace context. By default, will extract but warn about it."""
107107
# fmt: on

0 commit comments

Comments
 (0)