a
    ”˜ëjX  ã                   @   sr   d Z ddlZddlZddlmZ erLzddlmZ W n eyJ   eZY n0 ddl	m
Z dd„ Zdd	œd
d„ZdS )zBClient configuration for OpenTelemetry integration with LangSmith.é    N)ÚTYPE_CHECKING©ÚTracerProvider)Úutilsc               
   C   s€   zDddl m}  ddlm}m} ddlm} ddlm} | ||||fW S  t	yz } zt
 d|› �¡ W Y d}~dS d}~0 0 dS )z3Dynamically import OTEL client modules when needed.r   )ÚOTLPSpanExporter)ÚSERVICE_NAMEÚResourcer   )ÚBatchSpanProcessorzBOTEL_ENABLED is set but OpenTelemetry packages are not installed: N)Z5opentelemetry.exporter.otlp.proto.http.trace_exporterr   Zopentelemetry.sdk.resourcesr   r   Úopentelemetry.sdk.tracer   Zopentelemetry.sdk.trace.exportr	   ÚImportErrorÚwarningsÚwarn)r   r   r   r   r	   Úe© r   úd/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langsmith/_internal/otel/_otel_client.pyÚ_import_otel_client   s     ûÿr   r   )Úreturnc                  C   sÐ   t ƒ } | du rtdƒ‚| \}}}}}dtjvrHt d¡}|› d�tjd< dtjvrŠt d¡}d|› �}t ¡ }	|	r€|d|	› �7 }|tjd< tj dd	¡}
|||
d
did�}||d�}|ƒ }||ƒ}| 	|¡ |S )a,  Get the OTLP tracer provider for LangSmith.

    This function creates a tracer provider that exports spans using the OTLP protocol
    with LangSmith-specific defaults:

    - OTEL_EXPORTER_OTLP_ENDPOINT: https://api.smith.langchain.com/otel
    - OTEL_EXPORTER_OTLP_HEADERS: Contains x-api-key from LangSmith API key and
      Langsmith-Project header if project is configured

    These defaults can be overridden by setting the environment variables before
    calling this function.

    Returns:
        TracerProvider: The OTLP tracer provider.
    NzkOpenTelemetry packages are required to use this function. Please install with `pip install langsmith[otel]`ZOTEL_EXPORTER_OTLP_ENDPOINTz/otelZOTEL_EXPORTER_OTLP_HEADERSz
x-api-key=z,Langsmith-Project=ZOTEL_SERVICE_NAMEÚ	langsmithzlangsmith.internal_providerT)Ú
attributes)Úresource)
r   r   ÚosÚenvironÚls_utilsZget_api_urlZget_api_keyZget_tracer_projectÚgetZadd_span_processor)Zotel_importsr   r   r   r   r	   Zls_endpointZapi_keyÚheadersÚprojectZservice_namer   Ztracer_providerZotlp_exporterZspan_processorr   r   r   Úget_otlp_tracer_provider-   sB    ÿ
ú





ýÿ

r   )Ú__doc__r   r   Útypingr   r
   r   r   Úobjectr   r   r   r   r   r   r   r   r   Ú<module>   s   
