MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / make_span

Method make_span

agentops/sdk/core.py:526–579  ·  view source on GitHub ↗

Create a span without context management for manual span lifecycle control. This function creates a span that will be properly nested within any parent span based on the current execution context, but requires manual ending via finalize_span. Args: oper

(
        self,
        operation_name: str,
        span_kind: str,
        version: Optional[int] = None,
        attributes: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

524 logger.error(f"Error ending trace: {e}", exc_info=True)
525
526 def make_span(
527 self,
528 operation_name: str,
529 span_kind: str,
530 version: Optional[int] = None,
531 attributes: Optional[Dict[str, Any]] = None,
532 ) -> tuple:
533 """
534 Create a span without context management for manual span lifecycle control.
535
536 This function creates a span that will be properly nested within any parent span
537 based on the current execution context, but requires manual ending via finalize_span.
538
539 Args:
540 operation_name: Name of the operation being traced
541 span_kind: Type of operation (from SpanKind)
542 version: Optional version identifier for the operation
543 attributes: Optional dictionary of attributes to set on the span
544
545 Returns:
546 A tuple of (span, context, token) where:
547 - span is the created span
548 - context is the span context
549 - token is the context token needed for detaching
550 """
551 # Create span with proper naming convention
552 span_name = f"{operation_name}.{span_kind}"
553
554 # Get tracer
555 tracer = self.get_tracer()
556
557 # Build span attributes using the attribute helper
558 attributes = get_span_attributes(
559 operation_name=operation_name,
560 span_kind=span_kind,
561 version=version,
562 **(attributes or {}),
563 )
564
565 current_context = context_api.get_current()
566
567 # Create the span with proper context management
568 if span_kind == SpanKind.SESSION:
569 # For session spans, create as a root span
570 span = tracer.start_span(span_name, attributes=attributes)
571 else:
572 # For other spans, use the current context
573 span = tracer.start_span(span_name, context=current_context, attributes=attributes)
574
575 # Set as current context and get token for detachment
576 ctx = trace.set_span_in_context(span)
577 token = context_api.attach(ctx)
578
579 return span, ctx, token
580
581 def finalize_span(self, span: trace.Span, token: Any) -> None:
582 """

Callers 3

start_traceMethod · 0.95
wrapperMethod · 0.80
wrapperFunction · 0.80

Calls 3

get_tracerMethod · 0.95
get_span_attributesFunction · 0.90
start_spanMethod · 0.45

Tested by

no test coverage detected