Skip to content

Commit 06a2048

Browse files
committed
fixup
1 parent becd081 commit 06a2048

8 files changed

Lines changed: 53 additions & 58 deletions

File tree

py/src/braintrust/env.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,22 @@ def _resolve_use_legacy_uuid_ids() -> bool:
161161
"""Resolve whether the SDK should generate legacy UUID-based span/trace IDs.
162162
163163
The default is OpenTelemetry-compatible hex IDs (16-byte trace id / 8-byte
164-
span id) with V4 span-component export. Setting BRAINTRUST_LEGACY_UUID_IDS
164+
span id) with V4 span-component export. Setting BRAINTRUST_LEGACY_IDS
165165
opts back into UUID IDs with V3 export.
166166
167167
BRAINTRUST_OTEL_COMPAT (which selects the OpenTelemetry context manager)
168-
requires hex IDs, so it always wins: if both it and BRAINTRUST_LEGACY_UUID_IDS
168+
requires hex IDs, so it always wins: if both it and BRAINTRUST_LEGACY_IDS
169169
are set, legacy IDs are disabled and a warning is logged (at most once per
170170
process, even though this is re-resolved lazily on each access).
171171
"""
172172
global _warned_legacy_uuid_conflict
173173

174-
legacy = EnvVar("BRAINTRUST_LEGACY_UUID_IDS", EnvParser.BOOL).get(False)
174+
legacy = EnvVar("BRAINTRUST_LEGACY_IDS", EnvParser.BOOL).get(False)
175175
if EnvVar("BRAINTRUST_OTEL_COMPAT", EnvParser.BOOL).get(False):
176176
if legacy and not _warned_legacy_uuid_conflict:
177177
_warned_legacy_uuid_conflict = True
178178
_logger.warning(
179-
"BRAINTRUST_LEGACY_UUID_IDS is ignored because BRAINTRUST_OTEL_COMPAT "
179+
"BRAINTRUST_LEGACY_IDS is ignored because BRAINTRUST_OTEL_COMPAT "
180180
"requires OpenTelemetry-compatible hex span IDs. Using hex IDs."
181181
)
182182
return False
@@ -210,9 +210,4 @@ class BraintrustEnv:
210210
OTEL_COMPAT = EnvVar("BRAINTRUST_OTEL_COMPAT", EnvParser.BOOL)
211211
# Opt out of the default OpenTelemetry-compatible hex span/trace IDs and use
212212
# legacy UUID-based IDs (and V3 span-component export) instead.
213-
LEGACY_UUID_IDS = EnvVar("BRAINTRUST_LEGACY_UUID_IDS", EnvParser.BOOL)
214-
215-
# Whether to use legacy UUID IDs. Lazily resolved on each access from the
216-
# current environment, like the other fields above. The conflict warning
217-
# (OTEL_COMPAT wins over LEGACY_UUID_IDS) is emitted at most once per process.
218-
USE_LEGACY_UUID_IDS = _LegacyUuidIdsField()
213+
LEGACY_IDS = _LegacyUuidIdsField()

py/src/braintrust/id_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ def get_id_generator():
1111
This eliminates global state and makes tests parallelizable.
1212
Each caller gets their own generator instance.
1313
14-
Defaults to OpenTelemetry-compatible hex IDs. Set BRAINTRUST_LEGACY_UUID_IDS
14+
Defaults to OpenTelemetry-compatible hex IDs. Set BRAINTRUST_LEGACY_IDS
1515
to opt back into legacy UUID-based IDs.
1616
"""
17-
return UUIDGenerator() if BraintrustEnv.USE_LEGACY_UUID_IDS else OTELIDGenerator()
17+
return UUIDGenerator() if BraintrustEnv.LEGACY_IDS else OTELIDGenerator()
1818

1919

2020
class IDGenerator(ABC):

py/src/braintrust/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _get_exporter():
164164
serializing hex IDs via V3 would lose the compact encoding and risk
165165
corrupting hex values that happen to parse as UUIDs.
166166
"""
167-
return SpanComponentsV3 if BraintrustEnv.USE_LEGACY_UUID_IDS else SpanComponentsV4
167+
return SpanComponentsV3 if BraintrustEnv.LEGACY_IDS else SpanComponentsV4
168168

169169

170170
class Exportable(ABC):
@@ -3914,7 +3914,7 @@ def _parent_span_ids_match_active_format(span_id: str | None, root_span_id: str
39143914
"""
39153915
if not span_id or not root_span_id:
39163916
return False
3917-
if BraintrustEnv.USE_LEGACY_UUID_IDS:
3917+
if BraintrustEnv.LEGACY_IDS:
39183918
# Legacy mode: accept only non-hex (UUID) ids.
39193919
return not _is_hex_ids(span_id, root_span_id)
39203920
# Hex mode (default): accept only hex-shaped ids.

py/src/braintrust/test_env.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,28 @@ def test_otel_compat_uses_shared_bool_parser(self, monkeypatch):
149149

150150

151151
class TestIdConfig:
152-
# USE_LEGACY_UUID_IDS is lazily resolved from the current environment on each
152+
# LEGACY_IDS is lazily resolved from the current environment on each
153153
# access, like the other settings, so tests just set env vars and read it.
154154

155155
def test_hex_ids_default(self, monkeypatch):
156156
monkeypatch.delenv("BRAINTRUST_OTEL_COMPAT", raising=False)
157-
monkeypatch.delenv("BRAINTRUST_LEGACY_UUID_IDS", raising=False)
158-
assert BraintrustEnv.USE_LEGACY_UUID_IDS is False
157+
monkeypatch.delenv("BRAINTRUST_LEGACY_IDS", raising=False)
158+
assert BraintrustEnv.LEGACY_IDS is False
159159

160160
def test_legacy_uuid_opt_out(self, monkeypatch):
161161
monkeypatch.delenv("BRAINTRUST_OTEL_COMPAT", raising=False)
162-
monkeypatch.setenv("BRAINTRUST_LEGACY_UUID_IDS", "true")
163-
assert BraintrustEnv.USE_LEGACY_UUID_IDS is True
162+
monkeypatch.setenv("BRAINTRUST_LEGACY_IDS", "true")
163+
assert BraintrustEnv.LEGACY_IDS is True
164164

165165
def test_otel_compat_forces_hex(self, monkeypatch):
166-
# OTEL_COMPAT implies hex IDs regardless of LEGACY_UUID_IDS being unset.
166+
# OTEL_COMPAT implies hex IDs regardless of LEGACY_IDS being unset.
167167
monkeypatch.setenv("BRAINTRUST_OTEL_COMPAT", "true")
168-
monkeypatch.delenv("BRAINTRUST_LEGACY_UUID_IDS", raising=False)
169-
assert BraintrustEnv.USE_LEGACY_UUID_IDS is False
168+
monkeypatch.delenv("BRAINTRUST_LEGACY_IDS", raising=False)
169+
assert BraintrustEnv.LEGACY_IDS is False
170170

171171
def test_conflicting_flags_otel_wins(self, monkeypatch):
172-
# OTEL_COMPAT wins over LEGACY_UUID_IDS: legacy is disabled (hex IDs)
172+
# OTEL_COMPAT wins over LEGACY_IDS: legacy is disabled (hex IDs)
173173
# rather than raising.
174174
monkeypatch.setenv("BRAINTRUST_OTEL_COMPAT", "true")
175-
monkeypatch.setenv("BRAINTRUST_LEGACY_UUID_IDS", "true")
176-
assert BraintrustEnv.USE_LEGACY_UUID_IDS is False
175+
monkeypatch.setenv("BRAINTRUST_LEGACY_IDS", "true")
176+
assert BraintrustEnv.LEGACY_IDS is False

py/src/braintrust/test_id_gen.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
def reset_id_generator_state():
1010
"""Reset ID generator state and environment variables before each test"""
1111
original_otel = os.getenv("BRAINTRUST_OTEL_COMPAT")
12-
original_legacy = os.getenv("BRAINTRUST_LEGACY_UUID_IDS")
12+
original_legacy = os.getenv("BRAINTRUST_LEGACY_IDS")
1313

1414
try:
1515
yield
1616
finally:
1717
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
18-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
18+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
1919
if original_otel:
2020
os.environ["BRAINTRUST_OTEL_COMPAT"] = original_otel
2121
if original_legacy:
22-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = original_legacy
22+
os.environ["BRAINTRUST_LEGACY_IDS"] = original_legacy
2323

2424

2525
def test_uuid_generator():
@@ -60,7 +60,7 @@ def test_otel_id_generator():
6060

6161
def test_id_get_env_var(reset_id_generator_state):
6262
# By default (no env vars) the generator produces OTEL-compatible hex IDs.
63-
# BRAINTRUST_OTEL_COMPAT always implies hex; BRAINTRUST_LEGACY_UUID_IDS opts
63+
# BRAINTRUST_OTEL_COMPAT always implies hex; BRAINTRUST_LEGACY_IDS opts
6464
# back into UUIDs (only when OTEL_COMPAT is off).
6565
cases = [
6666
(None, lambda _id: _assert_is_hex(_id)),
@@ -73,7 +73,7 @@ def test_id_get_env_var(reset_id_generator_state):
7373

7474
for env_var_value, assert_func in cases:
7575
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
76-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
76+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
7777
if env_var_value is not None:
7878
os.environ["BRAINTRUST_OTEL_COMPAT"] = env_var_value
7979
generator = id_gen.get_id_generator()
@@ -82,7 +82,7 @@ def test_id_get_env_var(reset_id_generator_state):
8282

8383

8484
def test_id_get_env_var_legacy_uuid(reset_id_generator_state):
85-
# BRAINTRUST_LEGACY_UUID_IDS opts back into UUID IDs.
85+
# BRAINTRUST_LEGACY_IDS opts back into UUID IDs.
8686
cases = [
8787
("true", lambda _id: uuid.UUID(_id)),
8888
("True", lambda _id: uuid.UUID(_id)),
@@ -91,8 +91,8 @@ def test_id_get_env_var_legacy_uuid(reset_id_generator_state):
9191

9292
for env_var_value, assert_func in cases:
9393
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
94-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
95-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = env_var_value
94+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
95+
os.environ["BRAINTRUST_LEGACY_IDS"] = env_var_value
9696
generator = id_gen.get_id_generator()
9797
assert_func(generator.get_span_id())
9898
assert_func(generator.get_trace_id())
@@ -101,7 +101,7 @@ def test_id_get_env_var_legacy_uuid(reset_id_generator_state):
101101
def test_otel_compat_wins_over_legacy_uuid(reset_id_generator_state):
102102
# When both are set, OTEL_COMPAT wins: hex IDs are used (no raise).
103103
os.environ["BRAINTRUST_OTEL_COMPAT"] = "true"
104-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
104+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
105105
generator = id_gen.get_id_generator()
106106
assert generator.share_root_span_id() is False
107107
_assert_is_hex(generator.get_span_id())

py/src/braintrust/test_logger.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,18 +2784,18 @@ def reset_id_generator_state():
27842784
logger._state._reset_id_generator()
27852785
logger._state._reset_context_manager()
27862786
original_otel = os.getenv("BRAINTRUST_OTEL_COMPAT")
2787-
original_legacy = os.getenv("BRAINTRUST_LEGACY_UUID_IDS")
2787+
original_legacy = os.getenv("BRAINTRUST_LEGACY_IDS")
27882788
try:
27892789
yield
27902790
finally:
27912791
logger._state._reset_id_generator()
27922792
logger._state._reset_context_manager()
27932793
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
2794-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
2794+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
27952795
if original_otel:
27962796
os.environ["BRAINTRUST_OTEL_COMPAT"] = original_otel
27972797
if original_legacy:
2798-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = original_legacy
2798+
os.environ["BRAINTRUST_LEGACY_IDS"] = original_legacy
27992799

28002800

28012801
def test_otel_compatible_span_export_import():
@@ -2876,7 +2876,7 @@ def test_span_with_uuid_ids_share_root_span_id(reset_id_generator_state):
28762876

28772877
# Opt into legacy UUID IDs (hex IDs are the default).
28782878
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
2879-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
2879+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
28802880
logger._state._reset_id_generator()
28812881

28822882
init_test_logger(__name__)
@@ -3079,9 +3079,9 @@ def test_update_span_includes_span_id_and_root_span_id_from_export(with_memory_l
30793079

30803080
def test_get_exporter_returns_v4_by_default():
30813081
"""Test that _get_exporter() returns SpanComponentsV4 by default (no env vars)."""
3082-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3082+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
30833083
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3084-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
3084+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
30853085
from braintrust.logger import _get_exporter
30863086
from braintrust.span_identifier_v4 import SpanComponentsV4
30873087

@@ -3091,9 +3091,9 @@ def test_get_exporter_returns_v4_by_default():
30913091

30923092
def test_get_exporter_returns_v3_when_legacy_uuid():
30933093
"""Test that _get_exporter() returns SpanComponentsV3 in legacy UUID mode."""
3094-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3094+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
30953095
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3096-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
3096+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
30973097
from braintrust.logger import _get_exporter
30983098
from braintrust.span_identifier_v3 import SpanComponentsV3
30993099

@@ -3114,9 +3114,9 @@ def test_get_exporter_returns_v4_when_otel_enabled():
31143114

31153115
def test_experiment_export_uses_v4_by_default():
31163116
"""Test that Experiment.export() uses V4 by default."""
3117-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3117+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
31183118
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3119-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
3119+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
31203120
experiment = init_test_exp("test-exp")
31213121
exported = experiment.export()
31223122

@@ -3128,9 +3128,9 @@ def test_experiment_export_uses_v4_by_default():
31283128

31293129
def test_experiment_export_uses_v3_in_legacy_mode():
31303130
"""Test that Experiment.export() uses V3 in legacy UUID mode."""
3131-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3131+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
31323132
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3133-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
3133+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
31343134
experiment = init_test_exp("test-exp")
31353135
exported = experiment.export()
31363136

@@ -3155,9 +3155,9 @@ def test_experiment_export_respects_otel_compat_enabled():
31553155

31563156
def test_logger_export_uses_v4_by_default():
31573157
"""Test that Logger.export() uses V4 by default."""
3158-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3158+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
31593159
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3160-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
3160+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
31613161
test_logger = init_test_logger(__name__)
31623162
exported = test_logger.export()
31633163

@@ -3169,9 +3169,9 @@ def test_logger_export_uses_v4_by_default():
31693169

31703170
def test_logger_export_uses_v3_in_legacy_mode():
31713171
"""Test that Logger.export() uses V3 in legacy UUID mode."""
3172-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
3172+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
31733173
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
3174-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
3174+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
31753175
test_logger = init_test_logger(__name__)
31763176
exported = test_logger.export()
31773177

py/src/braintrust/test_propagation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ def test_inject_noops_in_legacy_uuid_mode():
331331

332332
from braintrust.test_helpers import preserve_env_vars
333333

334-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
334+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
335335
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
336-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
336+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
337337
with _internal_with_memory_background_logger():
338338
logger = init_test_logger("legacy-inject")
339339
with logger.start_span(name="p") as span:

py/src/braintrust/test_span_components.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,17 @@ class TestExportFormatSelection:
343343
"""Test that span export format is coupled to the active ID format.
344344
345345
Hex IDs (the default) serialize as V4; legacy UUID IDs (opted into via
346-
BRAINTRUST_LEGACY_UUID_IDS) serialize as V3.
346+
BRAINTRUST_LEGACY_IDS) serialize as V3.
347347
"""
348348

349349
def test_export_format_based_on_env_variable(self):
350350
"""Test that export format follows the legacy-UUID opt-out flag."""
351351
from braintrust.test_helpers import init_test_logger, preserve_env_vars
352352

353-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
353+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
354354
# Legacy UUID mode should use V3.
355355
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
356-
os.environ["BRAINTRUST_LEGACY_UUID_IDS"] = "true"
356+
os.environ["BRAINTRUST_LEGACY_IDS"] = "true"
357357

358358
l = init_test_logger("test_export_v3")
359359
with l.start_span(name="test_span") as span:
@@ -362,7 +362,7 @@ def test_export_format_based_on_env_variable(self):
362362
assert SpanComponentsV4.get_version(export_v3_mode) == 3
363363

364364
# Default (hex) mode should use V4.
365-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
365+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
366366

367367
l = init_test_logger("test_export_v4")
368368
with l.start_span(name="test_span") as span:
@@ -378,9 +378,9 @@ def test_export_uses_v4_by_default(self):
378378
"""Test that export uses V4 format by default (no env vars set)."""
379379
from braintrust.test_helpers import init_test_logger, preserve_env_vars
380380

381-
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_UUID_IDS"):
381+
with preserve_env_vars("BRAINTRUST_OTEL_COMPAT", "BRAINTRUST_LEGACY_IDS"):
382382
os.environ.pop("BRAINTRUST_OTEL_COMPAT", None)
383-
os.environ.pop("BRAINTRUST_LEGACY_UUID_IDS", None)
383+
os.environ.pop("BRAINTRUST_LEGACY_IDS", None)
384384

385385
l = init_test_logger("test_default_v4")
386386
with l.start_span(name="test_span") as span:

0 commit comments

Comments
 (0)