Log Levels
Traces can have a lot of observations (data model). You can differentiate the importance of observations with the level
attribute to control the verbosity of your traces and highlight errors and warnings. Available levels
: DEBUG
, DEFAULT
, WARNING
, ERROR
.
In addition to the level, you can also include a statusMessage
to provide additional context.
The v3 SDK is currently in beta. Please check out the SDK v3 for more details.
When using the @observe()
decorator:
from langfuse import observe, get_client
langfuse = get_client()
@observe()
def my_function():
# ... processing logic ...
# Update the current span with a warning level
langfuse.update_current_span(
level="WARNING",
status_message="This is a warning"
)
When creating spans or generations directly:
from langfuse import Langfuse
langfuse = Langfuse()
# Using context managers (recommended)
with langfuse.start_as_current_span(name="my-operation") as span:
# Set level and status message on creation
with span.start_as_current_span(
name="potentially-risky-operation",
level="WARNING",
status_message="Operation may fail"
) as risky_span:
# ... do work ...
# Or update level and status message later
risky_span.update(
level="ERROR",
status_message="Operation failed with unexpected input"
)
# You can also update the currently active span without a direct reference
with langfuse.start_as_current_span(name="another-operation"):
# ... some processing ...
langfuse.update_current_span(
level="DEBUG",
status_message="Processing intermediate results"
)
Levels can also be set when creating generations:
with langfuse.start_as_current_generation(
name="llm-call",
model="gpt-4o",
level="DEFAULT" # Default level
) as generation:
# ... make LLM call ...
if error_detected:
generation.update(
level="ERROR",
status_message="Model returned malformed output"
)
Filter Trace by Log Level
When viewing a single trace, you can filter the observations by log level.