Skip to content

Commit 79be724

Browse files
nik13claude
andcommitted
fix(fi_instrumentation): keep TH-8727 to the one-line register() change
The fix is deleting `tracer_provider._default_processor = True` from register(). The private _remove_default_processor() helper and the INFO line logged when a bare TracerProvider() replaces its default went beyond that, so they are removed, with the test of the log line. A bare TracerProvider() behaves exactly as on main again. The livekit test that follows the installed fi-instrumentation-otel now reads the mark register() leaves on the provider instead of comparing version numbers, so it stays right whatever version the fix ships in. The README and the livekit comments no longer name the unreleased version; only CHANGELOG.md and pyproject.toml do. The CHANGELOG entry now says a register(span_exporter=...) exporter was dropped the same way, and is kept now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e1b803d commit 79be724

6 files changed

Lines changed: 29 additions & 72 deletions

File tree

‎python/CHANGELOG.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
provider `register()` returns (a console exporter, a second backend, or a
66
framework's own processor, such as LiveKit's privacy filter) shut the Future AGI
77
exporter down and removed it, so traces silently stopped reaching Future AGI.
8-
Processors added later now run next to it, as in upstream OpenTelemetry.
8+
The same happened to a custom `register(span_exporter=...)` exporter. Processors
9+
added later now run next to it, as in upstream OpenTelemetry.
910
**Behaviour change:** code that relied on `add_span_processor()` to swap out
1011
`register()`'s exporter now exports to both; pass `register(span_exporter=...)`
1112
to export somewhere else instead.
1213
- A `TracerProvider()` constructed directly is unchanged: its first
1314
`add_span_processor()` call still replaces the default `SimpleSpanProcessor`
14-
added on construction, and now logs that at INFO.
15+
added on construction.
1516

1617
## [1.1.0] - 2026-08-11
1718
### Feature

‎python/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ trace_provider = register(project_name="my_project")
261261
trace_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
262262
```
263263

264-
To export somewhere other than Future AGI, pass your exporter to `register(span_exporter=...)`. Before fi-instrumentation-otel 1.1.1, the first `add_span_processor()` call replaced the Future AGI exporter, and spans stopped reaching Future AGI.
264+
To export somewhere other than Future AGI, pass your exporter to `register(span_exporter=...)`. In older releases (see the CHANGELOG), the first `add_span_processor()` call replaced the Future AGI exporter, and spans stopped reaching Future AGI.
265265

266266
### Semantic Conventions
267267

‎python/fi_instrumentation/otel.py‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,8 @@ def register(
243243
transport=transport,
244244
timeout=timeout,
245245
)
246-
# The processor built here takes the place of the default the provider adds on construction.
247-
# It is not a default itself: a later add_span_processor() call adds a processor next to it,
248-
# as in upstream OpenTelemetry, so spans keep reaching Future AGI.
249-
tracer_provider._remove_default_processor()
246+
# Replaces the default the provider added on construction. This processor is not marked as a
247+
# default: a later add_span_processor() call adds next to it, as in upstream OpenTelemetry.
250248
tracer_provider.add_span_processor(span_processor)
251249

252250
if set_global_tracer_provider:
@@ -344,21 +342,11 @@ def add_span_processor(self, *args: Any, **kwargs: Any) -> None:
344342
"""
345343

346344
if self._default_processor:
347-
logger.info(
348-
"TracerProvider: add_span_processor() replaces the default SimpleSpanProcessor "
349-
"added on construction; spans no longer go to that default exporter."
350-
)
351-
self._remove_default_processor()
345+
self._active_span_processor.shutdown()
346+
self._active_span_processor._span_processors = tuple()
347+
self._default_processor = False
352348
return super().add_span_processor(*args, **kwargs)
353349

354-
def _remove_default_processor(self) -> None:
355-
"""Shut down and remove the default processor added on construction, if still attached."""
356-
if not self._default_processor:
357-
return
358-
self._active_span_processor.shutdown()
359-
self._active_span_processor._span_processors = tuple()
360-
self._default_processor = False
361-
362350
def _tracing_details(self) -> str:
363351
project = self.resource.attributes.get(PROJECT_NAME)
364352
project_type = self.resource.attributes.get(PROJECT_TYPE)

‎python/frameworks/livekit/tests/test_integration.py‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Tests for traceai-livekit: enabling the Future AGI attribute mapping.
33
44
livekit-agents 1.8 adds a privacy filter to the tracer provider it is handed, through
5-
`add_span_processor`. Before fi-instrumentation-otel 1.1.1, `fi_instrumentation.register()` marked
6-
its own exporter as a default that the next `add_span_processor` call replaces, so the filter used
7-
to shut the exporter down and no trace was sent. traceAI-livekit allows fi-instrumentation-otel
8-
1.1.0, so `enable_*` still clears that mark itself. These tests pin that the exporter stays next to
9-
LiveKit's filter, on either release.
5+
`add_span_processor`. Older fi-instrumentation-otel releases (1.1.0 and earlier, see its CHANGELOG)
6+
have `fi_instrumentation.register()` mark its own exporter as a default that the next
7+
`add_span_processor` call replaces, so the filter used to shut the exporter down and no trace was
8+
sent. traceAI-livekit still allows those releases, so `enable_*` clears that mark itself. These
9+
tests pin that the exporter stays next to LiveKit's filter, with or without the mark.
1010
1111
Two end-to-end tests send one agent turn through the real mapping and the real HTTP exporter to
1212
a collector on 127.0.0.1, and read back what arrived: LiveKit 1.8's conversation content must reach
@@ -19,7 +19,6 @@
1919

2020
import asyncio
2121
import gzip
22-
import importlib.metadata
2322
import signal
2423
import threading
2524
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -28,7 +27,6 @@
2827
import pytest
2928
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, SpanExportResult
3029
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
31-
from packaging.version import Version
3230

3331
pytest.importorskip("livekit.agents", minversion="1.8")
3432

@@ -197,26 +195,24 @@ def test_a_processor_added_after_enabling_runs_alongside_the_exporter(
197195
assert [s.name for s in other.get_finished_spans()] == ["after-add"]
198196

199197

200-
# fi-instrumentation-otel 1.1.1 stopped marking register()'s exporter as a replaceable default
201-
# (TH-8727). The earlier releases this package allows still mark it.
202-
_FI_INSTRUMENTATION_VERSION = Version(importlib.metadata.version("fi-instrumentation-otel"))
203-
_REGISTER_KEEPS_ITS_EXPORTER = _FI_INSTRUMENTATION_VERSION >= Version("1.1.1")
204-
205-
206-
def test_add_span_processor_after_register_alone_matches_the_fi_instrumentation_release(
198+
def test_add_span_processor_after_register_alone_follows_the_mark_enable_clears(
207199
make_provider: Any,
208200
) -> None:
209201
provider = make_provider()
202+
# Set by register() on fi-instrumentation-otel 1.1.0 and earlier, not on releases with the
203+
# TH-8727 fix. Read from the provider, not from a version number, so the test follows the
204+
# installed release whatever version the fix ships in.
205+
register_marks_its_exporter = getattr(provider, "_default_processor", False)
210206
future_agi_processor = _processors(provider)[0]
211207
other_processor = SimpleSpanProcessor(InMemorySpanExporter())
212208

213209
provider.add_span_processor(other_processor)
214210

215-
if _REGISTER_KEEPS_ITS_EXPORTER:
216-
assert _processors(provider) == [future_agi_processor, other_processor]
217-
else:
211+
if register_marks_its_exporter:
218212
# Without enable_*, the processor replaces the exporter: why enable_* clears the mark.
219213
assert _processors(provider) == [other_processor]
214+
else:
215+
assert _processors(provider) == [future_agi_processor, other_processor]
220216

221217

222218
def test_livekit_cloud_never_receives_our_copies_of_redacted_content(

‎python/frameworks/livekit/traceai_livekit/integration.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def enable_fi_attribute_mapping(transport: Transport = Transport.HTTP) -> bool:
121121
if not swapped_any:
122122
logger.warning(f"No {transport.value} exporters found to replace")
123123

124-
# With fi-instrumentation-otel before 1.1.1, `register()` marks its own exporter as a default
124+
# On fi-instrumentation-otel 1.1.0 and earlier, `register()` marks its own exporter as a default
125125
# that the next `add_span_processor` call replaces. LiveKit adds its privacy filter through
126126
# `add_span_processor`, which would shut the exporter down and send nothing. Keep it: processors
127-
# added from here on run alongside it. On 1.1.1 and later there is no mark to clear.
127+
# added from here on run alongside it. Releases with the TH-8727 fix set no mark to clear.
128128
if getattr(provider, "_default_processor", False):
129129
provider._default_processor = False
130130

‎python/tests/test_register_keeps_exporter.py‎

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212
import gzip
13-
import logging
1413
import signal
1514
import threading
1615
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -140,10 +139,6 @@ def _processors(provider: Any) -> List[Any]:
140139
return list(provider._active_span_processor._span_processors)
141140

142141

143-
def _ours(caplog: pytest.LogCaptureFixture) -> List[logging.LogRecord]:
144-
return [r for r in caplog.records if r.name == "fi_instrumentation.otel"]
145-
146-
147142
def _end_one_span(provider: Any, name: str) -> None:
148143
provider.get_tracer(__name__).start_span(name).end()
149144
provider.force_flush()
@@ -215,18 +210,16 @@ def test_register_with_span_exporter_uses_it_and_keeps_it(
215210
assert http_collector == []
216211

217212

218-
def test_register_says_nothing_about_a_default_processor(
213+
def test_register_verbose_no_longer_says_add_span_processor_overwrites_a_default(
219214
http_collector: List[str],
220215
make_provider: Any,
221-
caplog: pytest.LogCaptureFixture,
222216
capsys: pytest.CaptureFixture[str],
223217
) -> None:
224-
with caplog.at_level(logging.INFO, logger="fi_instrumentation.otel"):
225-
provider = make_provider(verbose=True)
226-
provider.add_span_processor(_OTelSimpleSpanProcessor(InMemorySpanExporter()))
218+
make_provider(verbose=True)
227219

228-
assert "replaces the default" not in caplog.text
229-
assert "will overwrite this default" not in capsys.readouterr().out
220+
printed = capsys.readouterr().out
221+
assert "OpenTelemetry Tracing Details" in printed
222+
assert "will overwrite this default" not in printed
230223

231224

232225
def test_a_tracer_provider_constructed_directly_still_replaces_its_default(
@@ -255,24 +248,3 @@ def test_a_tracer_provider_constructed_directly_still_replaces_its_default(
255248
assert http_collector == []
256249
finally:
257250
provider.shutdown()
258-
259-
260-
def test_replacing_the_default_is_logged_once(
261-
http_collector: List[str], caplog: pytest.LogCaptureFixture
262-
) -> None:
263-
provider = TracerProvider(verbose=False)
264-
try:
265-
with caplog.at_level(logging.INFO, logger="fi_instrumentation.otel"):
266-
provider.add_span_processor(_OTelSimpleSpanProcessor(InMemorySpanExporter()))
267-
assert [r.getMessage() for r in _ours(caplog)] == [
268-
"TracerProvider: add_span_processor() replaces the default SimpleSpanProcessor "
269-
"added on construction; spans no longer go to that default exporter."
270-
]
271-
assert _ours(caplog)[0].levelno == logging.INFO
272-
273-
caplog.clear()
274-
with caplog.at_level(logging.INFO, logger="fi_instrumentation.otel"):
275-
provider.add_span_processor(_OTelSimpleSpanProcessor(InMemorySpanExporter()))
276-
assert _ours(caplog) == []
277-
finally:
278-
provider.shutdown()

0 commit comments

Comments
 (0)