dispatcher.span_enter(...)
, I do not understand what values I'm meant to provide for id_
or bounded_args
and I'm only guessing that instance
is meant to be the instance of the span I want to use. Futhermore, I can't clearly see how my custom span is the one used when I use the @dispatcher.span
decorator. I have placed breakpoints inside the new_span
, prepare_to_exit_span
, and prepare_to_drop_span
functions inside my custom span but it doesn't look like they are called. An example would be helpful. Thanks.@dispatcher.span
decorator will dispatch a span for each span handler you attached to the dispatcher.@wrapt.decorator def wrapper(func, instance, args, kwargs): bound_args = inspect.signature(func).bind(*args, **kwargs) id_ = f"{func.__qualname__}-{uuid.uuid4()}" token = active_span_id.set(id_) parent_id = None if token.old_value is Token.MISSING else token.old_value self.span_enter( id_=id_, bound_args=bound_args, instance=instance, parent_id=parent_id ) try: result = func(*args, **kwargs) except BaseException as e: self.event(SpanDropEvent(span_id=id_, err_str=str(e))) self.span_drop(id_=id_, bound_args=bound_args, instance=instance, err=e) raise else: self.span_exit( id_=id_, bound_args=bound_args, instance=instance, result=result ) return result finally: # clean up active_span_id.reset(token)
class OrchestratorPipelineSpan(BaseSpan): num_of_agents: int = Field(default=0) agents_names: str = Field(default="nothing here") class OrchestratorPipelineSpanHandler(BaseSpanHandler[OrchestratorPipelineSpan]): @classmethod def class_name(cls) -> str: """Class name.""" return "OrchestratorPipelineSpanHandler" def new_span( self, id: str, parent_span_id: Optional[str], **kwargs ) -> Optional[OrchestratorPipelineSpan]: """Create a span.""" # logic for creating a new MyCustomSpan print("new_span") return OrchestratorPipelineSpan(num_of_agents=42, agents_names="agent1, agent2") def prepare_to_exit_span( self, id: str, result: Optional[Any] = None, **kwargs ) -> Any: """Logic for preparing to exit a span.""" print("prepare_to_exit_span") def prepare_to_drop_span(self, id: str, err: Optional[Exception], **kwargs) -> Any: """Logic for preparing to drop a span.""" print("prepare_to_drop_span") root_dispatcher = instrument.get_dispatcher() root_dispatcher.add_span_handler(OrchestratorPipelineSpanHandler())
print
statements in each function in the OrchestratorPipelineSpanHandler, but they never get hit. This is surprising.span_id
property which is the ID of the open span you wish the event to be placed in.span_id
for a span that is auto-generated via the @dispatcher.span
decorator?current_span_ids
property inside the Dispatcher but I don't see it used (yet). It's also a dictionary so it's unclear which span id inside this dictionary is the current active span.id_ = f"{func.__qualname__}-{uuid.uuid4()}"
and then keeps track of the parent span π€ So youd have to repliacte the decorators method for keeping track of a parent span id? I thin?dispatcher = instrument.get_dispatcher(__name__) dispatcher.event(some_custom_event)