
    qiJ                         d Z ddlZ	 ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 dZd	efd
Z	 	 	 ddeded	efdZy# e$ r dZY w xY w)a  Core OpenTelemetry tracing utilities and setup for Pipecat.

This module provides functions to check availability and configure OpenTelemetry
tracing for Pipecat applications. It handles the optional nature of OpenTelemetry
dependencies and provides a safe setup process.
    N)trace)Resource)TracerProvider)BatchSpanProcessorConsoleSpanExporterTFreturnc                      t         S )zCheck if OpenTelemetry tracing is available and configured.

    Returns:
        True if tracing is available, False otherwise.
    )OPENTELEMETRY_AVAILABLE     M/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/utils/tracing/setup.pyis_tracing_availabler      s
     #"r   service_nameconsole_exportc                    t         sy	 t        j                  | t        j                  dd      t        j                  dd      d      }t        |      }t        j                  |       |r$t               }|j                  t        |             |r|j                  t        |             y# t        $ r}t        d	|        Y d
}~yd
}~ww xY w)a  Set up OpenTelemetry tracing with a user-provided exporter.

    Args:
        service_name: The name of the service for traces.
        exporter: A pre-configured OpenTelemetry span exporter instance.
                  If None, only console export will be available if enabled.
        console_export: Whether to also export traces to console (useful for debugging).

    Returns:
        True if setup was successful, False otherwise.

    Example::

        # With OTLP exporter
        from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter

        exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True)
        setup_tracing("my-service", exporter=exporter)
    FHOSTNAMEunknownENVIRONMENTdevelopment)zservice.namezservice.instance.idzdeployment.environment)resourceTzError setting up tracing: N)r
   r   createosgetenvr   r   set_tracer_providerr   add_span_processorr   	Exceptionprint)r   exporterr   r   tracer_providerconsole_exporteres          r   setup_tracingr"   %   s    0 #?? ,')yyY'G*,))M=*Q
 )(;!!/2 24../ABR/ST ../A(/KL *1#./s   B$B. .	C7C

C)pipecatNF)__doc__r   opentelemetryr   opentelemetry.sdk.resourcesr   opentelemetry.sdk.tracer   opentelemetry.sdk.trace.exportr   r   r
   ImportErrorboolr   strr"   r   r   r   <module>r,      su    
$#46V"
#d # " 55 5 
	5  $#$s   9 AA