Skip to content

Commit 049a6da

Browse files
feat(client)!: remove blocked_instrumentation_scopes (#1931)
* chore!: require Python 3.11 or newer Python 3.10 reaches end of life in October 2026. Raise requires-python to >=3.11, target py311 in ruff, drop 3.10 from the CI unit matrix, and remove the pre-3.11 fallbacks for asyncio.create_task(context=...) and typing.NotRequired. Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * feat(openai)!: drop support for OpenAI SDK versions below 1.0 The OpenAI integration now always uses the v1 client shapes. Remove the pre-1.0 method definitions and every _is_openai_v1() branch, and raise the dev dependency floor to openai>=1.0.0. Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * feat(otel)!: send x-langfuse-ingestion-version: 4 by default The default OTLP exporter now sends x-langfuse-ingestion-version: 4 so servers in dual-write or preview mode process exported spans directly. It is a no-op on events_only deployments, and additional_headers can still override it. Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * feat(client)!: remove blocked_instrumentation_scopes blocked_instrumentation_scopes was deprecated in favor of should_export_span. Remove it from Langfuse, the resource manager and the span processor, and drop the leftover is_active entry from the create_prompt docstring. LANGFUSE_HOST and host keep working, but now log a deprecation warning when they decide the base URL. Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * fix(observe): keep detecting legacy-marked coroutine functions inspect.iscoroutinefunction ignores asyncio's _is_coroutine marker, which asgiref's markcoroutinefunction sets on Python < 3.12. Accept both so such functions keep the async wrapper and their observation ends after the coroutine runs. Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * test(otel): pin that a mixed-case ingestion-version override wins Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * feat(client): keep host and LANGFUSE_HOST working without a warning Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> * chore: re-run CI Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
1 parent 10e4849 commit 049a6da

8 files changed

Lines changed: 17 additions & 139 deletions

File tree

‎langfuse/_client/client.py‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import re
1010
import urllib.parse
1111
import uuid
12-
import warnings
1312
from datetime import datetime
1413
from hashlib import sha256
1514
from time import time_ns
@@ -251,19 +250,6 @@ def mask_otel_spans(
251250
252251
langfuse = Langfuse(mask_otel_spans=mask_otel_spans)
253252
```
254-
blocked_instrumentation_scopes (Optional[List[str]]): Deprecated. Use `should_export_span` instead. Equivalent behavior:
255-
```python
256-
from langfuse.span_filter import is_default_export_span
257-
blocked = {"sqlite", "requests"}
258-
259-
should_export_span = lambda span: (
260-
is_default_export_span(span)
261-
and (
262-
span.instrumentation_scope is None
263-
or span.instrumentation_scope.name not in blocked
264-
)
265-
)
266-
```
267253
should_export_span (Optional[Callable[[ReadableSpan], bool]]): Callback to decide whether to export a span. If omitted, Langfuse uses the default filter (Langfuse SDK spans, spans with `gen_ai.*` attributes, and known LLM instrumentation scopes).
268254
additional_headers (Optional[Dict[str, str]]): Additional headers to include in all API requests and in the default OTLPSpanExporter requests. These headers will be merged with default headers. Note: If httpx_client is provided, additional_headers must be set directly on your custom httpx_client as well. If `span_exporter` is provided, these headers are not wired into that exporter and must be configured on the exporter instance directly.
269255
tracer_provider(Optional[TracerProvider]): OpenTelemetry TracerProvider to use for Langfuse. This can be useful to set to have disconnected tracing between Langfuse and other OpenTelemetry-span emitting libraries. Note: To track active spans, the context is still shared between TracerProviders. This may lead to broken trace trees.
@@ -330,7 +316,6 @@ def __init__(
330316
sample_rate: Optional[float] = None,
331317
mask: Optional[MaskFunction] = None,
332318
mask_otel_spans: Optional[MaskOtelSpansFunction] = None,
333-
blocked_instrumentation_scopes: Optional[List[str]] = None,
334319
should_export_span: Optional[Callable[[ReadableSpan], bool]] = None,
335320
additional_headers: Optional[Dict[str, str]] = None,
336321
tracer_provider: Optional[TracerProvider] = None,
@@ -403,18 +388,6 @@ def __init__(
403388
"OTEL_SDK_DISABLED is set. Langfuse tracing will be disabled and no traces will appear in the UI."
404389
)
405390

406-
if blocked_instrumentation_scopes is not None:
407-
warnings.warn(
408-
"`blocked_instrumentation_scopes` is deprecated and will be removed in a future release. "
409-
"Use `should_export_span` instead. Example: "
410-
"from langfuse.span_filter import is_default_export_span; "
411-
'blocked={"scope"}; should_export_span=lambda span: '
412-
"is_default_export_span(span) and (span.instrumentation_scope is None or "
413-
"span.instrumentation_scope.name not in blocked).",
414-
DeprecationWarning,
415-
stacklevel=2,
416-
)
417-
418391
# Initialize api and tracer if requirements are met
419392
self._resources = LangfuseResourceManager(
420393
public_key=public_key,
@@ -431,7 +404,6 @@ def __init__(
431404
mask=mask,
432405
mask_otel_spans=mask_otel_spans,
433406
tracing_enabled=self._tracing_enabled,
434-
blocked_instrumentation_scopes=blocked_instrumentation_scopes,
435407
should_export_span=should_export_span,
436408
additional_headers=additional_headers,
437409
tracer_provider=tracer_provider,
@@ -4137,7 +4109,6 @@ def create_prompt(
41374109
Keyword Args:
41384110
name : The name of the prompt to be created.
41394111
prompt : The content of the prompt to be created.
4140-
is_active [DEPRECATED] : A flag indicating whether the prompt is active or not. This is deprecated and will be removed in a future release. Please use the 'production' label instead.
41414112
labels: The labels of the prompt. Defaults to None. To create a default-served prompt, add the 'production' label.
41424113
tags: The tags of the prompt. Defaults to None. Will be applied to all versions of the prompt.
41434114
config: Additional structured data to be saved with the prompt. Defaults to None.

‎langfuse/_client/get_client.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def _create_client_from_instance(
5151
sample_rate=instance.sample_rate,
5252
mask=instance.mask,
5353
mask_otel_spans=instance.mask_otel_spans,
54-
blocked_instrumentation_scopes=instance.blocked_instrumentation_scopes,
5554
should_export_span=instance.should_export_span,
5655
additional_headers=instance.additional_headers,
5756
tracer_provider=instance.tracer_provider,

‎langfuse/_client/resource_manager.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def __new__(
127127
mask: Optional[MaskFunction] = None,
128128
mask_otel_spans: Optional[MaskOtelSpansFunction] = None,
129129
tracing_enabled: Optional[bool] = None,
130-
blocked_instrumentation_scopes: Optional[List[str]] = None,
131130
should_export_span: Optional[Callable[[ReadableSpan], bool]] = None,
132131
additional_headers: Optional[Dict[str, str]] = None,
133132
tracer_provider: Optional[TracerProvider] = None,
@@ -166,7 +165,6 @@ def __new__(
166165
tracing_enabled=tracing_enabled
167166
if tracing_enabled is not None
168167
else True,
169-
blocked_instrumentation_scopes=blocked_instrumentation_scopes,
170168
should_export_span=should_export_span,
171169
additional_headers=additional_headers,
172170
tracer_provider=tracer_provider,
@@ -196,7 +194,6 @@ def _initialize_instance(
196194
mask: Optional[MaskFunction] = None,
197195
mask_otel_spans: Optional[MaskOtelSpansFunction] = None,
198196
tracing_enabled: bool = True,
199-
blocked_instrumentation_scopes: Optional[List[str]] = None,
200197
should_export_span: Optional[Callable[[ReadableSpan], bool]] = None,
201198
additional_headers: Optional[Dict[str, str]] = None,
202199
tracer_provider: Optional[TracerProvider] = None,
@@ -220,7 +217,6 @@ def _initialize_instance(
220217
self.release = release
221218
self.media_upload_thread_count = media_upload_thread_count
222219
self.sample_rate = sample_rate
223-
self.blocked_instrumentation_scopes = blocked_instrumentation_scopes
224220
self.should_export_span = should_export_span
225221
self.additional_headers = additional_headers
226222
self.id_generator = id_generator
@@ -259,7 +255,6 @@ def _initialize_instance(
259255
timeout=timeout,
260256
flush_at=flush_at,
261257
flush_interval=flush_interval,
262-
blocked_instrumentation_scopes=blocked_instrumentation_scopes,
263258
should_export_span=should_export_span,
264259
additional_headers=additional_headers,
265260
span_exporter=span_exporter,

‎langfuse/_client/span_processor.py‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import logging
1616
import os
1717
import threading
18-
from typing import Callable, Dict, List, Literal, Optional, cast
18+
from typing import Callable, Dict, Literal, Optional, cast
1919

2020
from opentelemetry import context as context_api
2121
from opentelemetry.context import Context
@@ -121,7 +121,6 @@ def __init__(
121121
timeout: Optional[int] = None,
122122
flush_at: Optional[int] = None,
123123
flush_interval: Optional[float] = None,
124-
blocked_instrumentation_scopes: Optional[List[str]] = None,
125124
should_export_span: Optional[Callable[[ReadableSpan], bool]] = None,
126125
additional_headers: Optional[Dict[str, str]] = None,
127126
span_exporter: Optional[SpanExporter] = None,
@@ -130,11 +129,6 @@ def __init__(
130129
otel_compression: Optional[Literal["gzip", "none"]] = None,
131130
):
132131
self.public_key = public_key
133-
self.blocked_instrumentation_scopes = (
134-
blocked_instrumentation_scopes
135-
if blocked_instrumentation_scopes is not None
136-
else []
137-
)
138132
self._should_export_span = should_export_span or is_default_export_span
139133

140134
self._app_root_lock = threading.Lock()
@@ -258,16 +252,6 @@ def on_end(self, span: ReadableSpan) -> None:
258252
)
259253
return
260254

261-
# Do not export spans from blocked instrumentation scopes
262-
if self._is_blocked_instrumentation_scope(span):
263-
langfuse_logger.debug(
264-
"Trace: Dropping span due to blocked instrumentation scope | "
265-
"span_name='%s' | instrumentation_scope='%s'",
266-
span.name,
267-
self._get_scope_name(span),
268-
)
269-
return
270-
271255
# Apply custom or default span filter
272256
try:
273257
should_export = self._should_export_span(span)
@@ -342,9 +326,6 @@ def _is_expected_exported_at_start(self, span: Span) -> bool:
342326
):
343327
return False
344328

345-
if self._is_blocked_instrumentation_scope(readable_span):
346-
return False
347-
348329
try:
349330
return bool(self._should_export_span(readable_span))
350331
except Exception as error:
@@ -359,12 +340,6 @@ def _is_expected_exported_at_start(self, span: Span) -> bool:
359340

360341
return False
361342

362-
def _is_blocked_instrumentation_scope(self, span: ReadableSpan) -> bool:
363-
return (
364-
span.instrumentation_scope is not None
365-
and span.instrumentation_scope.name in self.blocked_instrumentation_scopes
366-
)
367-
368343
def _is_langfuse_project_span(self, span: ReadableSpan) -> bool:
369344
if not is_langfuse_span(span):
370345
return False

‎tests/conftest.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ def mock_init(self: Any, **kwargs: Any) -> None:
102102
from langfuse._client.span_filter import is_default_export_span
103103

104104
self.public_key = kwargs.get("public_key", "test-public-key")
105-
blocked_scopes = kwargs.get("blocked_instrumentation_scopes")
106-
self.blocked_instrumentation_scopes = (
107-
blocked_scopes if blocked_scopes is not None else []
108-
)
109105
self._should_export_span = (
110106
kwargs.get("should_export_span") or is_default_export_span
111107
)

‎tests/unit/test_app_root_detection.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,15 @@ def test_active_langfuse_scope_sets_baggage_after_root_start(
252252
assert "langfuse.trace.metadata.trace_id" not in spans["child"].attributes
253253

254254

255-
def test_blocked_instrumentation_scope_parent_marks_child_as_app_root(
255+
def test_filtered_scope_parent_marks_child_as_app_root(
256256
memory_exporter,
257257
):
258258
tracer_provider, processor = _create_processor(
259259
memory_exporter,
260-
blocked_instrumentation_scopes=["blocked.scope"],
260+
should_export_span=lambda span: (
261+
span.instrumentation_scope is None
262+
or span.instrumentation_scope.name != "blocked.scope"
263+
),
261264
)
262265
blocked_tracer = tracer_provider.get_tracer("blocked.scope")
263266
langfuse_tracer = _langfuse_tracer(tracer_provider)

‎tests/unit/test_initialization.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ def test_env_host_fallback(self, cleanup_env_vars):
100100

101101
assert client._base_url == "http://env-host.com"
102102

103+
def test_env_host_fallback_logs_no_warning(self, cleanup_env_vars, caplog):
104+
"""Test that LANGFUSE_HOST keeps working without a deprecation warning."""
105+
caplog.set_level("WARNING", logger="langfuse")
106+
os.environ["LANGFUSE_HOST"] = "http://env-host.com"
107+
108+
client = Langfuse(public_key="test_pk", secret_key="test_sk")
109+
110+
assert client._base_url == "http://env-host.com"
111+
assert not any("deprecated" in record.message for record in caplog.records)
112+
103113
def test_default_base_url(self, cleanup_env_vars):
104114
"""Test that default base_url is used when nothing is set."""
105115
client = Langfuse(

‎tests/unit/test_otel.py‎

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ def mock_init(self, **kwargs):
120120
from langfuse._client.span_filter import is_default_export_span
121121

122122
self.public_key = kwargs.get("public_key", "test-key")
123-
blocked_scopes = kwargs.get("blocked_instrumentation_scopes")
124-
self.blocked_instrumentation_scopes = (
125-
blocked_scopes if blocked_scopes is not None else []
126-
)
127123
self._should_export_span = (
128124
kwargs.get("should_export_span") or is_default_export_span
129125
)
@@ -2408,10 +2404,6 @@ def mock_processor_init(self, **kwargs):
24082404
from langfuse._client.span_filter import is_default_export_span
24092405

24102406
self.public_key = kwargs.get("public_key", "test-key")
2411-
blocked_scopes = kwargs.get("blocked_instrumentation_scopes")
2412-
self.blocked_instrumentation_scopes = (
2413-
blocked_scopes if blocked_scopes is not None else []
2414-
)
24152407
self._should_export_span = (
24162408
kwargs.get("should_export_span") or is_default_export_span
24172409
)
@@ -2446,16 +2438,13 @@ def mock_initialize(self, **kwargs):
24462438
# Call original_initialize to set up all the necessary attributes
24472439
original_initialize(self, **kwargs)
24482440

2449-
# Now create our custom LangfuseSpanProcessor with the actual blocked_instrumentation_scopes
2441+
# Now create our custom LangfuseSpanProcessor with the actual should_export_span
24502442
from langfuse._client.span_processor import LangfuseSpanProcessor
24512443

24522444
processor = LangfuseSpanProcessor(
24532445
public_key=self.public_key,
24542446
secret_key=self.secret_key,
24552447
base_url=self.base_url,
2456-
blocked_instrumentation_scopes=kwargs.get(
2457-
"blocked_instrumentation_scopes"
2458-
),
24592448
should_export_span=kwargs.get("should_export_span"),
24602449
)
24612450
# Replace its exporter with our test exporter
@@ -2661,38 +2650,6 @@ def test_custom_should_export_span_with_composition(
26612650
assert "known-span" in exported_span_names
26622651
assert "unknown-span" not in exported_span_names
26632652

2664-
def test_blocked_scopes_override_should_export(
2665-
self, instrumentation_filtering_setup
2666-
):
2667-
"""Test that blocked scopes are dropped even when callback allows all."""
2668-
with pytest.warns(DeprecationWarning, match="blocked_instrumentation_scopes"):
2669-
Langfuse(
2670-
public_key=instrumentation_filtering_setup["test_key"],
2671-
secret_key="test-secret-key",
2672-
base_url="http://localhost:3000",
2673-
blocked_instrumentation_scopes=["my-framework.worker"],
2674-
should_export_span=lambda span: True,
2675-
)
2676-
2677-
tracer_provider = instrumentation_filtering_setup["test_tracer_provider"]
2678-
blocked_tracer = tracer_provider.get_tracer("my-framework.worker")
2679-
allowed_tracer = tracer_provider.get_tracer("custom.allowed")
2680-
2681-
blocked_span = blocked_tracer.start_span("blocked-span")
2682-
blocked_span.end()
2683-
allowed_span = allowed_tracer.start_span("allowed-span")
2684-
allowed_span.end()
2685-
tracer_provider.force_flush()
2686-
2687-
exported_span_names = [
2688-
span.name
2689-
for span in instrumentation_filtering_setup[
2690-
"blocked_exporter"
2691-
].get_finished_spans()
2692-
]
2693-
assert "blocked-span" not in exported_span_names
2694-
assert "allowed-span" in exported_span_names
2695-
26962653
def test_should_export_span_with_none_uses_default(
26972654
self, instrumentation_filtering_setup
26982655
):
@@ -2758,34 +2715,6 @@ def _failing_filter(_span):
27582715
for record in caplog.records
27592716
)
27602717

2761-
def test_blocked_scope_drop_logs_scope_name(
2762-
self, instrumentation_filtering_setup, caplog
2763-
):
2764-
"""Test that blocked scope drops include scope names in debug logs."""
2765-
caplog.set_level("DEBUG", logger="langfuse")
2766-
2767-
with pytest.warns(DeprecationWarning, match="blocked_instrumentation_scopes"):
2768-
Langfuse(
2769-
public_key=instrumentation_filtering_setup["test_key"],
2770-
secret_key="test-secret-key",
2771-
base_url="http://localhost:3000",
2772-
blocked_instrumentation_scopes=["my.blocked.scope"],
2773-
should_export_span=lambda span: True,
2774-
)
2775-
2776-
tracer_provider = instrumentation_filtering_setup["test_tracer_provider"]
2777-
blocked_tracer = tracer_provider.get_tracer("my.blocked.scope")
2778-
2779-
span = blocked_tracer.start_span("blocked-debug-span")
2780-
span.end()
2781-
tracer_provider.force_flush()
2782-
2783-
assert any(
2784-
"Dropping span due to blocked instrumentation scope" in record.message
2785-
and "my.blocked.scope" in record.message
2786-
for record in caplog.records
2787-
)
2788-
27892718

27902719
class TestConcurrencyAndAsync(TestOTelBase):
27912720
"""Tests for asynchronous and concurrent span operations."""

0 commit comments

Comments
 (0)