# -*- coding: utf-8 -*-"""The tracing interface class in agentscope."""fromtypingimportTYPE_CHECKINGifTYPE_CHECKING:fromopentelemetry.traceimportTracerelse:Tracer="Tracer"
[文档]defsetup_tracing(endpoint:str)->None:"""Set up the AgentScope tracing by configuring the endpoint URL. Args: endpoint (`str`): The endpoint URL for the tracing exporter. """# Lazy importfromopentelemetryimporttracefromopentelemetry.sdk.traceimportTracerProviderfromopentelemetry.sdk.trace.exportimportBatchSpanProcessorfromopentelemetry.exporter.otlp.proto.http.trace_exporterimport(OTLPSpanExporter,)tracer_provider=TracerProvider()exporter=OTLPSpanExporter(endpoint=endpoint)span_processor=BatchSpanProcessor(exporter)tracer_provider.add_span_processor(span_processor)trace.set_tracer_provider(tracer_provider)
def_get_tracer()->Tracer:"""Get the tracer Returns: `Tracer`: The tracer with the name "agentscope" and version. """fromopentelemetryimporttracefrom.._versionimport__version__returntrace.get_tracer("agentscope",__version__)