-
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
|
You're right—blocked_instrumentation_scopes in Langfuse SDK v3 is supposed to filter out spans from specific OpenTelemetry instrumentation libraries (like FastAPI and Logfire), but in practice, it often doesn't work as expected, especially when using get_client or custom wrappers. This is a known limitation: the singleton pattern in get_client doesn't let you pass blocked_instrumentation_scopes, and even custom wrappers may not block unwanted scopes if the client isn't initialized early enough in your application's lifecycle. Filtering must be set globally at client initialization, not at the CallbackHandler level, and regex is not supported—you have to enumerate each scope explicitly discussion. The most reliable workaround is to initialize the Langfuse client with blocked_instrumentation_scopes at the very top of your main entrypoint (e.g., main.py, right after imports), before any other OpenTelemetry instrumentation or Langfuse integrations are set up. This ensures the block list is respected globally discussion. Initializing inside FastAPI lifecycle hooks or wrappers is too late and won't work. If you still see unwanted traces, consider using the OpenTelemetry Collector's filterprocessor to filter spans before they reach Langfuse. This lets you filter by attributes or span names, but be careful—complex filters can break trace relationships and cause incomplete traces docs. Currently, there's no backend filtering for instrumentation scopes in Langfuse; all filtering must happen in the SDK or collector before data is sent issue. Regex blocking isn't supported, so you need to keep your block list up to date issue. If you want to suppress all traces, you can set LANGFUSE_TRACING_ENABLED=False and OTEL_SDK_DISABLED=true, but this disables OpenTelemetry processing for the whole process and may affect other integrations issue. References:
To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Okay, initializing langfuse at the top-level app.py seems to do the trick, so the get_client wrapper isn't necessary. |
Beta Was this translation helpful? Give feedback.
-
|
But the same issue persists as highlighted in the discussion:
Any tips on how to approach this? |
Beta Was this translation helpful? Give feedback.
-
|
This happens because blocking instrumentation scopes like FastAPI or Logfire prevents those libraries from creating the root span, so Langfuse doesn’t have a meaningful top-level trace name to display. To fix this, you need to manually create and name the root span at the start of your request or workflow. You can do this with the Langfuse Python SDK using a context manager or the @observe decorator. For example: from langfuse import get_client
langfuse = get_client()
with langfuse.start_as_current_span(name="my-custom-trace", input={"request": "details"}) as root_span:
# ... your logic here ...
root_span.update_trace(
name="my-custom-trace", # sets the trace name
input={"request": "details"},
output={"result": "something"}
)If you use custom trace IDs or pass a trace_context, you may need to explicitly update the trace name and metadata using Best practice: always set the trace name and input/output on the root span, especially when blocking auto-instrumentation. The @observe decorator also handles trace grouping and naming automatically if you prefer that style docs. Recent Langfuse releases improved trace name handling, so upgrading may help if you’re still seeing issues issue. Let me know if you want a more specific code example for your setup! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@qrosseel You can simply instantiate Langfuse at the top of your application with the from langfuse import Langfuse
Langfuse(*)You will also have to manually set the trace name, input and output as the root span is being filtered out. [See here])(https://langfuse.com/docs/observability/sdk/python/instrumentation#override-default-behavior) |
Beta Was this translation helpful? Give feedback.
-
|
The from langfuse import Langfuse
langfuse = Langfuse(
blocked_instrumentation_scopes=["sqlalchemy", "psycopg"]
)This is intended to exclude spans whose However, filtering only works as intended if the instrumentation scope names in your block list exactly match the Also, filtering with Key points:
If spans are still showing up, ensure you:
For more details, see the Filtering by Instrumentation Scope section(1) and this related discussion(2). 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
@hassiebp
https://langfuse.com/docs/observability/sdk/python/advanced-usage#isolated-tracerprovider |
Beta Was this translation helpful? Give feedback.



@qrosseel You can simply instantiate Langfuse at the top of your application with the
blocked_instrumentation_scopesand use get_client throughout your app to access that instance.You will also have to manually set the trace name, input and output as the root span is being filtered out. [See here])(https://langfuse.com/docs/observability/sdk/python/instrumentation#override-default-behavior)