Skip to content

Commit e1b803d

Browse files
nik13claude
andcommitted
fix(fi_instrumentation): keep register()'s exporter when another span processor is added (TH-8727)
register() marked its own processor as a default (otel.py:244, `tracer_provider._default_processor = True`). The TracerProvider add_span_processor override shuts a default down and removes it, so the next add_span_processor() call on the provider register() returns (a console exporter, a second backend, LiveKit's privacy filter) dropped the Future AGI exporter, and traces silently stopped reaching Future AGI. Upstream OpenTelemetry's add_span_processor() only adds. register() now removes the provider's construction default itself and adds its processor as an ordinary one, so later processors run next to it. A TracerProvider() constructed directly is unchanged: its first add_span_processor() call still replaces the default SimpleSpanProcessor, and now logs that at INFO. register(span_exporter=...) stays the way to export somewhere else instead. The livekit test that pinned the old register() behaviour now expects the behaviour of the installed fi-instrumentation-otel: traceAI-livekit allows 1.1.0, so its TH-8665 workaround in enable_*() stays. Release: fi-instrumentation-otel 1.1.1 (version, CHANGELOG, README). Not published. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 17e573e commit e1b803d

7 files changed

Lines changed: 360 additions & 18 deletions

File tree

‎python/CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## [1.1.1] - 2026-10-21
2+
### Fixed
3+
- `register()` no longer marks its own exporter as a default that the next
4+
`add_span_processor()` call replaces. Before, adding any span processor to the
5+
provider `register()` returns (a console exporter, a second backend, or a
6+
framework's own processor, such as LiveKit's privacy filter) shut the Future AGI
7+
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.
9+
**Behaviour change:** code that relied on `add_span_processor()` to swap out
10+
`register()`'s exporter now exports to both; pass `register(span_exporter=...)`
11+
to export somewhere else instead.
12+
- A `TracerProvider()` constructed directly is unchanged: its first
13+
`add_span_processor()` call still replaces the default `SimpleSpanProcessor`
14+
added on construction, and now logs that at INFO.
15+
116
## [1.1.0] - 2026-08-11
217
### Feature
318
- `register()` now accepts span-processor / exporter / provider tuning:

‎python/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ provider.add_span_processor(BatchSpanProcessor(exporter))
249249
OpenAIInstrumentor().instrument(tracer_provider=provider)
250250
```
251251

252+
### More span processors
253+
254+
A span processor added to the provider `register()` returns runs next to the Future AGI exporter, so spans go to both:
255+
256+
```python
257+
from fi_instrumentation import register
258+
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
259+
260+
trace_provider = register(project_name="my_project")
261+
trace_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
262+
```
263+
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.
265+
252266
### Semantic Conventions
253267

254268
traceAI supports multiple semantic conventions:

‎python/fi_instrumentation/otel.py‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def register(
116116
) -> _TracerProvider:
117117
"""Configure and return a Future AGI `TracerProvider`.
118118
119+
Span processors added later with `add_span_processor` run next to the Future AGI
120+
exporter, never in place of it. To export somewhere else instead, pass `span_exporter`.
121+
119122
All tuning args below default to `None`, meaning the corresponding OpenTelemetry
120123
environment variable / upstream default applies (no behavior change when unset).
121124
@@ -240,8 +243,11 @@ def register(
240243
transport=transport,
241244
timeout=timeout,
242245
)
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()
243250
tracer_provider.add_span_processor(span_processor)
244-
tracer_provider._default_processor = True
245251

246252
if set_global_tracer_provider:
247253
trace_api.set_tracer_provider(tracer_provider)
@@ -271,10 +277,11 @@ class TracerProvider(_TracerProvider):
271277
272278
On construction a default `SimpleSpanProcessor` is added, exporting over `transport`.
273279
The collector endpoint is inferred from `transport` and the `FI_BASE_URL`/`FI_GRPC_URL`
274-
environment variables. Call `add_span_processor` to replace the default. In addition to
275-
the arguments below, all upstream `opentelemetry.sdk.trace.TracerProvider` keyword
276-
arguments (`sampler`, `resource`, `span_limits`, `id_generator`, ...) are accepted and
277-
forwarded.
280+
environment variables. The first `add_span_processor` call replaces the default; later calls
281+
add processors next to it. The provider `register()` returns has no such default: processors
282+
added to it run next to its exporter. In addition to the arguments below, all upstream
283+
`opentelemetry.sdk.trace.TracerProvider` keyword arguments (`sampler`, `resource`,
284+
`span_limits`, `id_generator`, ...) are accepted and forwarded.
278285
279286
Args:
280287
transport (Transport): Transport (HTTP or gRPC) used for the default exporter.
@@ -331,15 +338,27 @@ def add_span_processor(self, *args: Any, **kwargs: Any) -> None:
331338
"""
332339
Registers a new `SpanProcessor` for this `TracerProvider`.
333340
334-
If this `TracerProvider` has a default processor, it will be removed.
341+
On a `TracerProvider` constructed directly, the first call replaces the default
342+
`SimpleSpanProcessor` added on construction. Any other processor is kept, including the
343+
one `register()` adds: the new processor runs next to it, as in upstream OpenTelemetry.
335344
"""
336345

337346
if self._default_processor:
338-
self._active_span_processor.shutdown()
339-
self._active_span_processor._span_processors = tuple()
340-
self._default_processor = False
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()
341352
return super().add_span_processor(*args, **kwargs)
342353

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+
343362
def _tracing_details(self) -> str:
344363
project = self.resource.attributes.get(PROJECT_NAME)
345364
project_type = self.resource.attributes.get(PROJECT_TYPE)

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +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`. `fi_instrumentation.register()` marks its own exporter as a default that the
6-
next `add_span_processor` call replaces, so the filter used to shut the exporter down and no trace
7-
was sent. These tests pin that the exporter stays next to LiveKit's filter.
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.
810
911
Two end-to-end tests send one agent turn through the real mapping and the real HTTP exporter to
1012
a collector on 127.0.0.1, and read back what arrived: LiveKit 1.8's conversation content must reach
@@ -17,6 +19,7 @@
1719

1820
import asyncio
1921
import gzip
22+
import importlib.metadata
2023
import signal
2124
import threading
2225
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -25,6 +28,7 @@
2528
import pytest
2629
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, SpanExportResult
2730
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
31+
from packaging.version import Version
2832

2933
pytest.importorskip("livekit.agents", minversion="1.8")
3034

@@ -193,15 +197,26 @@ def test_a_processor_added_after_enabling_runs_alongside_the_exporter(
193197
assert [s.name for s in other.get_finished_spans()] == ["after-add"]
194198

195199

196-
def test_register_alone_still_lets_add_span_processor_replace_its_default(
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(
197207
make_provider: Any,
198208
) -> None:
199209
provider = make_provider()
210+
future_agi_processor = _processors(provider)[0]
200211
other_processor = SimpleSpanProcessor(InMemorySpanExporter())
201212

202213
provider.add_span_processor(other_processor)
203214

204-
assert _processors(provider) == [other_processor]
215+
if _REGISTER_KEEPS_ITS_EXPORTER:
216+
assert _processors(provider) == [future_agi_processor, other_processor]
217+
else:
218+
# Without enable_*, the processor replaces the exporter: why enable_* clears the mark.
219+
assert _processors(provider) == [other_processor]
205220

206221

207222
def test_livekit_cloud_never_receives_our_copies_of_redacted_content(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +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-
# `register()` marks its own exporter as a default that the next `add_span_processor` call
125-
# replaces. LiveKit adds its privacy filter through `add_span_processor`, which would shut the
126-
# exporter down and send nothing. Keep it: processors added from here on run alongside it.
124+
# With fi-instrumentation-otel before 1.1.1, `register()` marks its own exporter as a default
125+
# that the next `add_span_processor` call replaces. LiveKit adds its privacy filter through
126+
# `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.
127128
if getattr(provider, "_default_processor", False):
128129
provider._default_processor = False
129130

‎python/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fi-instrumentation-otel"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
description = "OpenTelemetry instrumentation"
55
authors = ["Future AGI <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)