@@ -125,6 +125,7 @@ def get_data(self) -> dict[str, Any]:
125125 return self ._data
126126
127127 def get_correlation_data_for_logs (self ) -> dict [str , Any ]:
128+ """Return correlation data for log enrichment."""
128129 return {}
129130
130131
@@ -234,9 +235,11 @@ def handle(self, span: LangfuseSpan, component_type: str | None) -> None:
234235
235236 @classmethod
236237 def from_dict (cls , data : dict [str , Any ]) -> "SpanHandler" :
238+ """Deserialize a SpanHandler from a dictionary."""
237239 return default_from_dict (cls , data )
238240
239241 def to_dict (self ) -> dict [str , Any ]:
242+ """Serialize this SpanHandler to a dictionary."""
240243 return default_to_dict (self )
241244
242245
@@ -273,6 +276,7 @@ class DefaultSpanHandler(SpanHandler):
273276 """DefaultSpanHandler provides the default Langfuse tracing behavior for Haystack."""
274277
275278 def create_span (self , context : SpanContext ) -> LangfuseSpan :
279+ """Create a Langfuse span based on the given context."""
276280 if self .tracer is None :
277281 message = (
278282 "Tracer is not initialized. "
@@ -343,6 +347,7 @@ def create_span(self, context: SpanContext) -> LangfuseSpan:
343347 return LangfuseSpan (self .tracer .start_as_current_span (name = context .name ))
344348
345349 def handle (self , span : LangfuseSpan , component_type : str | None ) -> None :
350+ """Process and enrich a span after component execution."""
346351 # If the span is at the pipeline level, we add input and output keys to the span
347352 at_pipeline_level = span .get_data ().get (_PIPELINE_INPUT_KEY ) is not None
348353 if at_pipeline_level :
@@ -456,6 +461,7 @@ def __init__(
456461 def trace (
457462 self , operation_name : str , tags : dict [str , Any ] | None = None , parent_span : Span | None = None
458463 ) -> Iterator [Span ]:
464+ """Create and manage a tracing span as a context manager."""
459465 tags = tags or {}
460466 span_name = tags .get (_COMPONENT_NAME_KEY , operation_name )
461467 component_type = tags .get (_COMPONENT_TYPE_KEY )
@@ -543,6 +549,7 @@ def trace(
543549 self .flush ()
544550
545551 def flush (self ) -> None :
552+ """Flush all pending spans to Langfuse."""
546553 self ._tracer .flush ()
547554
548555 def current_span (self ) -> Span | None :
@@ -558,13 +565,15 @@ def current_span(self) -> Span | None:
558565 def get_trace_url (self ) -> str :
559566 """
560567 Return the URL to the tracing data.
568+
561569 :return: The URL to the tracing data.
562570 """
563571 return self ._tracer .get_trace_url () or ""
564572
565573 def get_trace_id (self ) -> str :
566574 """
567575 Return the trace ID.
576+
568577 :return: The trace ID.
569578 """
570579 return self ._tracer .get_current_trace_id () or ""
0 commit comments