|
1 | 1 | import io |
| 2 | +import logging |
2 | 3 | import math |
3 | 4 | import os |
4 | 5 | import shlex |
|
8 | 9 | from typing import TypeVar, cast |
9 | 10 |
|
10 | 11 |
|
| 12 | +_logger = logging.getLogger(__name__) |
| 13 | + |
| 14 | + |
11 | 15 | T = TypeVar("T") |
12 | 16 | EnvValue = bool | float | int | str |
13 | 17 | _Parser = Callable[[str], EnvValue | None] |
@@ -168,37 +172,23 @@ class BraintrustEnv: |
168 | 172 | LEGACY_UUID_IDS = EnvVar("BRAINTRUST_LEGACY_UUID_IDS", EnvParser.BOOL) |
169 | 173 |
|
170 | 174 |
|
171 | | -class BraintrustEnvError(Exception): |
172 | | - """Raised when Braintrust environment variables are configured inconsistently.""" |
173 | | - |
174 | | - |
175 | 175 | def use_legacy_uuid_ids() -> bool: |
176 | 176 | """Return True if the SDK should generate legacy UUID-based span/trace IDs. |
177 | 177 |
|
178 | 178 | The default is OpenTelemetry-compatible hex IDs (16-byte trace id / 8-byte |
179 | 179 | span id) with V4 span-component export. Setting BRAINTRUST_LEGACY_UUID_IDS |
180 | 180 | opts back into UUID IDs with V3 export. |
181 | 181 |
|
182 | | - Note: BRAINTRUST_OTEL_COMPAT (which selects the OpenTelemetry context |
183 | | - manager) requires hex IDs, so it always forces hex regardless of this |
184 | | - function. The mutually-exclusive combination is rejected by |
185 | | - validate_id_config(). |
| 182 | + BRAINTRUST_OTEL_COMPAT (which selects the OpenTelemetry context manager) |
| 183 | + requires hex IDs, so it always wins: if both it and BRAINTRUST_LEGACY_UUID_IDS |
| 184 | + are set, legacy IDs are disabled and a warning is logged. |
186 | 185 | """ |
187 | | - validate_id_config() |
| 186 | + legacy = BraintrustEnv.LEGACY_UUID_IDS.get(False) |
188 | 187 | if BraintrustEnv.OTEL_COMPAT.get(False): |
| 188 | + if legacy: |
| 189 | + _logger.warning( |
| 190 | + "BRAINTRUST_LEGACY_UUID_IDS is ignored because BRAINTRUST_OTEL_COMPAT " |
| 191 | + "requires OpenTelemetry-compatible hex span IDs. Using hex IDs." |
| 192 | + ) |
189 | 193 | return False |
190 | | - return BraintrustEnv.LEGACY_UUID_IDS.get(False) |
191 | | - |
192 | | - |
193 | | -def validate_id_config() -> None: |
194 | | - """Fail fast on mutually-exclusive ID configuration. |
195 | | -
|
196 | | - BRAINTRUST_OTEL_COMPAT requires OpenTelemetry-compatible hex IDs, while |
197 | | - BRAINTRUST_LEGACY_UUID_IDS forces legacy UUID IDs. They cannot both be set. |
198 | | - """ |
199 | | - if BraintrustEnv.OTEL_COMPAT.get(False) and BraintrustEnv.LEGACY_UUID_IDS.get(False): |
200 | | - raise BraintrustEnvError( |
201 | | - "BRAINTRUST_OTEL_COMPAT and BRAINTRUST_LEGACY_UUID_IDS are mutually " |
202 | | - "exclusive: OTEL compatibility requires hex span IDs, but legacy mode " |
203 | | - "forces UUID span IDs. Unset one of them." |
204 | | - ) |
| 194 | + return legacy |
0 commit comments