1414
1515import time
1616from threading import Lock
17- from typing import List , Optional
17+ from typing import Any , List , Optional
1818from uuid import UUID
1919
2020from opentelemetry ._events import get_event_logger
3030from .version import __version__
3131
3232
33- class TelemetryClient :
33+ class TelemetryHandler :
3434 """
35- High-level client managing GenAI invocation lifecycles and emitting
35+ High-level handler managing GenAI invocation lifecycles and emitting
3636 them as spans, metrics, and events.
3737 """
3838
39- def __init__ (self , emitter_type_full : bool = True , ** kwargs ):
39+ def __init__ (self , emitter_type_full : bool = True , ** kwargs : Any ):
4040 tracer_provider = kwargs .get ("tracer_provider" )
4141 self ._tracer = get_tracer (
4242 __name__ ,
@@ -79,8 +79,8 @@ def start_llm(
7979 prompts : List [Message ],
8080 run_id : UUID ,
8181 parent_run_id : Optional [UUID ] = None ,
82- ** attributes ,
83- ):
82+ ** attributes : Any ,
83+ ) -> None :
8484 invocation = LLMInvocation (
8585 messages = prompts ,
8686 run_id = run_id ,
@@ -95,7 +95,7 @@ def stop_llm(
9595 self ,
9696 run_id : UUID ,
9797 chat_generations : List [ChatGeneration ],
98- ** attributes ,
98+ ** attributes : Any ,
9999 ) -> LLMInvocation :
100100 with self ._lock :
101101 invocation = self ._llm_registry .pop (run_id )
@@ -106,7 +106,7 @@ def stop_llm(
106106 return invocation
107107
108108 def fail_llm (
109- self , run_id : UUID , error : Error , ** attributes
109+ self , run_id : UUID , error : Error , ** attributes : Any
110110 ) -> LLMInvocation :
111111 with self ._lock :
112112 invocation = self ._llm_registry .pop (run_id )
@@ -117,28 +117,28 @@ def fail_llm(
117117
118118
119119# Singleton accessor
120- _default_client : TelemetryClient | None = None
120+ _default_handler : Optional [ TelemetryHandler ] = None
121121
122122
123- def get_telemetry_client (
124- emitter_type_full : bool = True , ** kwargs
125- ) -> TelemetryClient :
126- global _default_client
127- if _default_client is None :
128- _default_client = TelemetryClient (
123+ def get_telemetry_handler (
124+ emitter_type_full : bool = True , ** kwargs : Any
125+ ) -> TelemetryHandler :
126+ global _default_handler
127+ if _default_handler is None :
128+ _default_handler = TelemetryHandler (
129129 emitter_type_full = emitter_type_full , ** kwargs
130130 )
131- return _default_client
131+ return _default_handler
132132
133133
134134# Module‐level convenience functions
135135def llm_start (
136136 prompts : List [Message ],
137137 run_id : UUID ,
138138 parent_run_id : Optional [UUID ] = None ,
139- ** attributes ,
140- ):
141- return get_telemetry_client ().start_llm (
139+ ** attributes : Any ,
140+ ) -> None :
141+ return get_telemetry_handler ().start_llm (
142142 prompts = prompts ,
143143 run_id = run_id ,
144144 parent_run_id = parent_run_id ,
@@ -147,14 +147,14 @@ def llm_start(
147147
148148
149149def llm_stop (
150- run_id : UUID , chat_generations : List [ChatGeneration ], ** attributes
150+ run_id : UUID , chat_generations : List [ChatGeneration ], ** attributes : Any
151151) -> LLMInvocation :
152- return get_telemetry_client ().stop_llm (
152+ return get_telemetry_handler ().stop_llm (
153153 run_id = run_id , chat_generations = chat_generations , ** attributes
154154 )
155155
156156
157- def llm_fail (run_id : UUID , error : Error , ** attributes ) -> LLMInvocation :
158- return get_telemetry_client ().fail_llm (
157+ def llm_fail (run_id : UUID , error : Error , ** attributes : Any ) -> LLMInvocation :
158+ return get_telemetry_handler ().fail_llm (
159159 run_id = run_id , error = error , ** attributes
160160 )
0 commit comments