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.
When using the @observe()
decorator:
from langfuse import observe, get_client @observe() def my_function(): langfuse = get_client() # ... 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 get_client langfuse = get_client() # 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:
langfuse = get_client() 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.
GitHub Discussions
Was this page helpful?