openlit 1.34.8__py3-none-any.whl → 1.34.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,145 +1,55 @@
1
1
  """
2
- Module for monitoring Ollama API calls.
2
+ Module for monitoring ElevenLabs API calls.
3
3
  """
4
4
 
5
- import logging
6
5
  import time
7
- from opentelemetry.trace import SpanKind, Status, StatusCode
8
- from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
9
- from openlit.__helpers import (
10
- get_audio_model_cost,
11
- handle_exception,
12
- create_metrics_attributes,
13
- )
6
+ from opentelemetry.trace import SpanKind
7
+ from openlit.__helpers import handle_exception
8
+ from openlit.instrumentation.elevenlabs.utils import process_audio_response
14
9
  from openlit.semcov import SemanticConvention
15
10
 
16
- # Initialize logger for logging potential issues and operations
17
- logger = logging.getLogger(__name__)
18
-
19
11
  def generate(gen_ai_endpoint, version, environment, application_name,
20
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
12
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
21
13
  """
22
- Generates a telemetry wrapper for creating speech audio to collect metrics.
23
-
24
- Args:
25
- version: Version of the monitoring package.
26
- environment: Deployment environment (e.g., production, staging).
27
- application_name: Name of the application using the ElevenLabs API.
28
- tracer: OpenTelemetry tracer for creating spans.
29
- pricing_info: Information used for calculating the cost of generating speech audio.
30
- capture_message_content: Flag indicating whether to trace the input text and generated audio.
31
-
32
- Returns:
33
- A function that wraps the speech audio creation method to add telemetry.
14
+ Generates a telemetry wrapper for GenAI function call
34
15
  """
35
16
 
36
17
  def wrapper(wrapped, instance, args, kwargs):
37
18
  """
38
- Wraps the 'generate' API call to add telemetry.
39
-
40
- This collects metrics such as execution time, cost, and handles errors
41
- gracefully, adding details to the trace for observability.
42
-
43
- Args:
44
- wrapped: The original 'generate' method to be wrapped.
45
- instance: The instance of the class where the original method is defined.
46
- args: Positional arguments for the 'generate' method.
47
- kwargs: Keyword arguments for the 'generate' method.
48
-
49
- Returns:
50
- The response from the original 'generate' method.
19
+ Wraps the GenAI function call.
51
20
  """
52
21
 
53
22
  server_address, server_port = "api.elevenlabs.io", 443
54
- request_model = kwargs.get('model', kwargs.get('model_id', 'eleven_multilingual_v2'))
23
+ request_model = kwargs.get("model", kwargs.get("model_id", "eleven_multilingual_v2"))
55
24
 
56
- span_name = f'{SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO} {request_model}'
25
+ span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO} {request_model}"
57
26
 
58
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
27
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
59
28
  start_time = time.time()
60
29
  response = wrapped(*args, **kwargs)
61
- end_time = time.time()
62
30
 
63
31
  try:
64
- # Calculate cost of the operation
65
- cost = get_audio_model_cost(request_model,
66
- pricing_info, kwargs.get('text', ''))
67
-
68
- # Set Span attributes
69
- span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')
70
- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
71
- SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO)
72
- span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
73
- SemanticConvention.GEN_AI_SYSTEM_ASSEMBLYAI)
74
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
75
- request_model)
76
- span.set_attribute(SemanticConvention.SERVER_ADDRESS,
77
- server_address)
78
- span.set_attribute(SemanticConvention.SERVER_PORT,
79
- server_port)
80
- span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
81
- request_model)
82
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
83
- request_model)
84
- span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
85
- 'audio')
86
-
87
- # Set Span attributes (Extras)
88
- if gen_ai_endpoint == 'elevenlabs.generate':
89
- if isinstance(kwargs.get('voice', 'Rachel'), str):
90
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_VOICE,
91
- kwargs.get('voice', 'Rachel'))
92
- else:
93
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_VOICE,
94
- kwargs.get('voice_id', ''))
95
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_RESPONSE_FORMAT,
96
- kwargs.get('output_format', 'mp3'))
97
- span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_SETTINGS,
98
- str(kwargs.get('voice_settings', '')))
99
- span.set_attribute(DEPLOYMENT_ENVIRONMENT,
100
- environment)
101
- span.set_attribute(SERVICE_NAME,
102
- application_name)
103
- span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
104
- cost)
105
- span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
106
- version)
107
- if capture_message_content:
108
- span.add_event(
109
- name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
110
- attributes={
111
- SemanticConvention.GEN_AI_CONTENT_PROMPT: str(kwargs.get('text', '')),
112
- },
113
- )
114
-
115
- span.set_status(Status(StatusCode.OK))
116
-
117
- if disable_metrics is False:
118
- attributes = create_metrics_attributes(
119
- service_name=application_name,
120
- deployment_environment=environment,
121
- operation=SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO,
122
- system=SemanticConvention.GEN_AI_SYSTEM_ELEVENLABS,
123
- request_model=request_model,
124
- server_address=server_address,
125
- server_port=server_port,
126
- response_model=request_model,
127
- )
128
-
129
- metrics['genai_client_operation_duration'].record(
130
- end_time - start_time, attributes
131
- )
132
- metrics['genai_requests'].add(1, attributes)
133
- metrics['genai_cost'].record(cost, attributes)
134
-
135
- # Return original response
136
- return response
32
+ response = process_audio_response(
33
+ response=response,
34
+ gen_ai_endpoint=gen_ai_endpoint,
35
+ pricing_info=pricing_info,
36
+ server_port=server_port,
37
+ server_address=server_address,
38
+ environment=environment,
39
+ application_name=application_name,
40
+ metrics=metrics,
41
+ start_time=start_time,
42
+ span=span,
43
+ args=args,
44
+ kwargs=kwargs,
45
+ capture_message_content=capture_message_content,
46
+ disable_metrics=disable_metrics,
47
+ version=version
48
+ )
137
49
 
138
50
  except Exception as e:
139
51
  handle_exception(span, e)
140
- logger.error('Error in trace creation: %s', e)
141
52
 
142
- # Return original response
143
- return response
53
+ return response
144
54
 
145
55
  return wrapper
@@ -0,0 +1,133 @@
1
+ """
2
+ ElevenLabs OpenTelemetry instrumentation utility functions
3
+ """
4
+ import time
5
+
6
+ from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
7
+ from opentelemetry.trace import Status, StatusCode
8
+
9
+ from openlit.__helpers import (
10
+ get_audio_model_cost,
11
+ create_metrics_attributes,
12
+ )
13
+ from openlit.semcov import SemanticConvention
14
+
15
+ def format_content(text):
16
+ """
17
+ Process text input to extract content.
18
+ """
19
+ return str(text) if text else ""
20
+
21
+ def common_span_attributes(scope, gen_ai_operation, gen_ai_system, server_address, server_port,
22
+ request_model, response_model, environment, application_name, is_stream, tbt, ttft, version):
23
+ """
24
+ Set common span attributes for both chat and RAG operations.
25
+ """
26
+
27
+ scope._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
28
+ scope._span.set_attribute(SemanticConvention.GEN_AI_OPERATION, gen_ai_operation)
29
+ scope._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM, gen_ai_system)
30
+ scope._span.set_attribute(SemanticConvention.SERVER_ADDRESS, server_address)
31
+ scope._span.set_attribute(SemanticConvention.SERVER_PORT, server_port)
32
+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL, request_model)
33
+ scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL, scope._response_model)
34
+ scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
35
+ scope._span.set_attribute(SERVICE_NAME, application_name)
36
+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM, is_stream)
37
+ scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT, scope._tbt)
38
+ scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT, scope._ttft)
39
+ scope._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION, version)
40
+
41
+ def record_audio_metrics(metrics, gen_ai_operation, gen_ai_system, server_address, server_port,
42
+ request_model, response_model, environment, application_name, start_time, end_time, cost):
43
+ """
44
+ Record audio generation metrics for the operation.
45
+ """
46
+
47
+ attributes = create_metrics_attributes(
48
+ operation=gen_ai_operation,
49
+ system=gen_ai_system,
50
+ server_address=server_address,
51
+ server_port=server_port,
52
+ request_model=request_model,
53
+ response_model=response_model,
54
+ service_name=application_name,
55
+ deployment_environment=environment,
56
+ )
57
+ metrics["genai_client_operation_duration"].record(end_time - start_time, attributes)
58
+ metrics["genai_requests"].add(1, attributes)
59
+ metrics["genai_cost"].record(cost, attributes)
60
+
61
+ def common_audio_logic(scope, gen_ai_endpoint, pricing_info, environment, application_name,
62
+ metrics, capture_message_content, disable_metrics, version):
63
+ """
64
+ Process audio generation request and generate Telemetry
65
+ """
66
+
67
+ text = format_content(scope._kwargs.get("text", ""))
68
+ request_model = scope._kwargs.get("model", scope._kwargs.get("model_id", "eleven_multilingual_v2"))
69
+ is_stream = False # ElevenLabs audio generation is not streaming
70
+
71
+ cost = get_audio_model_cost(request_model, pricing_info, text)
72
+
73
+ # Common Span Attributes
74
+ common_span_attributes(scope,
75
+ SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO, SemanticConvention.GEN_AI_SYSTEM_ELEVENLABS,
76
+ scope._server_address, scope._server_port, request_model, request_model,
77
+ environment, application_name, is_stream, scope._tbt, scope._ttft, version)
78
+
79
+ # Span Attributes for Cost and Tokens
80
+ scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST, cost)
81
+
82
+ # Span Attributes for Response parameters
83
+ scope._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE, scope._kwargs.get("output_format", "mp3_44100_128"))
84
+
85
+ # Audio-specific span attributes
86
+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_VOICE, scope._kwargs.get("voice_id", ""))
87
+ scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_SETTINGS, str(scope._kwargs.get("voice_settings", "")))
88
+
89
+ # Span Attributes for Content
90
+ if capture_message_content:
91
+ scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_PROMPT, text)
92
+
93
+ # To be removed once the change to span_attributes (from span events) is complete
94
+ scope._span.add_event(
95
+ name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
96
+ attributes={
97
+ SemanticConvention.GEN_AI_CONTENT_PROMPT: text,
98
+ },
99
+ )
100
+
101
+ scope._span.set_status(Status(StatusCode.OK))
102
+
103
+ # Metrics
104
+ if not disable_metrics:
105
+ record_audio_metrics(metrics, SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO, SemanticConvention.GEN_AI_SYSTEM_ELEVENLABS,
106
+ scope._server_address, scope._server_port, request_model, request_model, environment,
107
+ application_name, scope._start_time, scope._end_time, cost)
108
+
109
+ def process_audio_response(response, gen_ai_endpoint, pricing_info, server_port, server_address,
110
+ environment, application_name, metrics, start_time, span, args, kwargs, capture_message_content=False,
111
+ disable_metrics=False, version="1.0.0"):
112
+ """
113
+ Process audio generation request and generate Telemetry
114
+ """
115
+
116
+ scope = type("GenericScope", (), {})()
117
+
118
+ scope._start_time = start_time
119
+ scope._end_time = time.time()
120
+ scope._span = span
121
+ scope._server_address, scope._server_port = server_address, server_port
122
+ scope._kwargs = kwargs
123
+ scope._args = args
124
+
125
+ # Initialize streaming and timing values for ElevenLabs audio generation
126
+ scope._response_model = kwargs.get("model", kwargs.get("model_id", "eleven_multilingual_v2"))
127
+ scope._tbt = 0.0
128
+ scope._ttft = scope._end_time - scope._start_time
129
+
130
+ common_audio_logic(scope, gen_ai_endpoint, pricing_info, environment, application_name,
131
+ metrics, capture_message_content, disable_metrics, version)
132
+
133
+ return response
@@ -109,7 +109,7 @@ def record_embedding_metrics(metrics, gen_ai_operation, gen_ai_system, server_ad
109
109
  metrics["genai_prompt_tokens"].add(input_tokens, attributes)
110
110
  metrics["genai_cost"].record(cost, attributes)
111
111
 
112
- def common_generate_logic(scope, pricing_info, environment, application_name, metrics,
112
+ def common_t2s_logic(scope, pricing_info, environment, application_name, metrics,
113
113
  capture_message_content, disable_metrics, version, is_stream):
114
114
  """
115
115
  Process generate request and generate Telemetry
@@ -228,7 +228,7 @@ def process_streaming_generate_response(scope, pricing_info, environment, applic
228
228
  """
229
229
  Process generate request and generate Telemetry
230
230
  """
231
- common_generate_logic(scope, pricing_info, environment, application_name, metrics,
231
+ common_t2s_logic(scope, pricing_info, environment, application_name, metrics,
232
232
  capture_message_content, disable_metrics, version, is_stream=True)
233
233
 
234
234
  def process_generate_response(response, request_model, pricing_info, server_port, server_address,
@@ -252,7 +252,7 @@ def process_generate_response(response, request_model, pricing_info, server_port
252
252
  scope._args = args
253
253
  scope._tools = None
254
254
 
255
- common_generate_logic(scope, pricing_info, environment, application_name, metrics,
255
+ common_t2s_logic(scope, pricing_info, environment, application_name, metrics,
256
256
  capture_message_content, disable_metrics, version, is_stream=False)
257
257
 
258
258
  return response
@@ -41,7 +41,7 @@ def _dispatch_async(async_chat_wrap, async_emb_wrap):
41
41
 
42
42
  class OllamaInstrumentor(BaseInstrumentor):
43
43
  """
44
- An instrumentor for Ollama's client library.
44
+ An instrumentor for Ollama client library.
45
45
  """
46
46
 
47
47
  def instrumentation_dependencies(self) -> Collection[str]:
@@ -51,7 +51,6 @@ class OllamaInstrumentor(BaseInstrumentor):
51
51
  application_name = kwargs.get("application_name", "default_application")
52
52
  environment = kwargs.get("environment", "default_environment")
53
53
  tracer = kwargs.get("tracer")
54
- event_provider = kwargs.get("event_provider")
55
54
  metrics = kwargs.get("metrics_dict")
56
55
  pricing_info = kwargs.get("pricing_info", {})
57
56
  capture_message_content = kwargs.get("capture_message_content", False)
@@ -61,22 +60,22 @@ class OllamaInstrumentor(BaseInstrumentor):
61
60
  # Build wrapper factories for chat and embeddings
62
61
  sync_chat_wrap = chat(
63
62
  version, environment, application_name,
64
- tracer, event_provider, pricing_info,
63
+ tracer, pricing_info,
65
64
  capture_message_content, metrics, disable_metrics
66
65
  )
67
66
  sync_emb_wrap = embeddings(
68
67
  version, environment, application_name,
69
- tracer, event_provider, pricing_info,
68
+ tracer, pricing_info,
70
69
  capture_message_content, metrics, disable_metrics
71
70
  )
72
71
  async_chat_wrap = async_chat(
73
72
  version, environment, application_name,
74
- tracer, event_provider, pricing_info,
73
+ tracer, pricing_info,
75
74
  capture_message_content, metrics, disable_metrics
76
75
  )
77
76
  async_emb_wrap = async_embeddings(
78
77
  version, environment, application_name,
79
- tracer, event_provider, pricing_info,
78
+ tracer, pricing_info,
80
79
  capture_message_content, metrics, disable_metrics
81
80
  )
82
81
 
@@ -2,7 +2,6 @@
2
2
  Module for monitoring Ollama API calls.
3
3
  """
4
4
 
5
- import logging
6
5
  import time
7
6
  from opentelemetry.trace import SpanKind
8
7
  from openlit.__helpers import (
@@ -17,12 +16,10 @@ from openlit.instrumentation.ollama.utils import (
17
16
  )
18
17
  from openlit.semcov import SemanticConvention
19
18
 
20
- logger = logging.getLogger(__name__)
21
-
22
19
  def async_chat(version, environment, application_name,
23
- tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):
20
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
24
21
  """
25
- Generates a telemetry wrapper for GenAI function call
22
+ Generates a telemetry wrapper for Ollama async chat function call
26
23
  """
27
24
 
28
25
  class TracedAsyncStream:
@@ -38,7 +35,7 @@ def async_chat(version, environment, application_name,
38
35
  kwargs,
39
36
  server_address,
40
37
  server_port,
41
- **args,
38
+ args,
42
39
  ):
43
40
  self.__wrapped__ = wrapped
44
41
  self._span = span
@@ -48,11 +45,11 @@ def async_chat(version, environment, application_name,
48
45
  self._tool_calls = []
49
46
  self._input_tokens = 0
50
47
  self._output_tokens = 0
51
- self._response_role = ''
48
+ self._response_role = ""
52
49
  self._span_name = span_name
53
50
  self._args = args
54
51
  self._kwargs = kwargs
55
- self._start_time = time.time()
52
+ self._start_time = time.monotonic()
56
53
  self._end_time = None
57
54
  self._timestamps = []
58
55
  self._ttft = 0
@@ -81,56 +78,101 @@ def async_chat(version, environment, application_name,
81
78
  return chunk
82
79
  except StopAsyncIteration:
83
80
  try:
84
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
81
+ with tracer.start_as_current_span(self._span_name, kind=SpanKind.CLIENT) as self._span:
85
82
  process_streaming_chat_response(
86
83
  self,
87
84
  pricing_info=pricing_info,
88
85
  environment=environment,
89
86
  application_name=application_name,
90
87
  metrics=metrics,
91
- event_provider=event_provider,
92
88
  capture_message_content=capture_message_content,
93
89
  disable_metrics=disable_metrics,
94
90
  version=version
95
91
  )
96
92
  except Exception as e:
97
93
  handle_exception(self._span, e)
98
- logger.error("Error in trace creation: %s", e)
94
+
99
95
  raise
100
96
 
101
97
  async def wrapper(wrapped, instance, args, kwargs):
102
98
  """
103
- Wraps the GenAI function call.
99
+ Wraps the Ollama async chat function call.
104
100
  """
105
101
 
106
102
  streaming = kwargs.get("stream", False)
107
103
 
108
104
  server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 11434)
109
- json_body = kwargs.get("json", {}) or {}
110
- request_model = json_body.get("model") or kwargs.get("model")
105
+ request_model = kwargs.get("model")
111
106
 
112
107
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
113
108
 
114
- # pylint: disable=no-else-return
115
109
  if streaming:
116
110
  awaited_wrapped = await wrapped(*args, **kwargs)
117
111
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
118
- return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
112
+ return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port, args)
119
113
 
120
114
  else:
121
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
122
- start_time = time.time()
115
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
116
+ start_time = time.monotonic()
117
+
118
+ try:
119
+ response = await wrapped(*args, **kwargs)
120
+
121
+ response = process_chat_response(
122
+ response=response,
123
+ gen_ai_endpoint="ollama.chat",
124
+ pricing_info=pricing_info,
125
+ server_port=server_port,
126
+ server_address=server_address,
127
+ environment=environment,
128
+ application_name=application_name,
129
+ metrics=metrics,
130
+ start_time=start_time,
131
+ span=span,
132
+ capture_message_content=capture_message_content,
133
+ disable_metrics=disable_metrics,
134
+ version=version,
135
+ **kwargs
136
+ )
137
+
138
+ except Exception as e:
139
+ handle_exception(span, e)
140
+
141
+ return response
142
+
143
+ return wrapper
144
+
145
+ def async_embeddings(version, environment, application_name,
146
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):
147
+ """
148
+ Generates a telemetry wrapper for Ollama async embeddings function call
149
+ """
150
+
151
+ async def wrapper(wrapped, instance, args, kwargs):
152
+ """
153
+ Wraps the Ollama async embeddings function call.
154
+ """
155
+
156
+ server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 11434)
157
+ request_model = kwargs.get("model")
158
+
159
+ span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
160
+
161
+ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
162
+ start_time = time.monotonic()
163
+
164
+ try:
123
165
  response = await wrapped(*args, **kwargs)
124
- response = process_chat_response(
166
+
167
+ response = process_embedding_response(
125
168
  response=response,
126
- request_model=request_model,
169
+ gen_ai_endpoint="ollama.embeddings",
127
170
  pricing_info=pricing_info,
128
171
  server_port=server_port,
129
172
  server_address=server_address,
130
173
  environment=environment,
131
174
  application_name=application_name,
132
175
  metrics=metrics,
133
- event_provider=event_provider,
134
176
  start_time=start_time,
135
177
  span=span,
136
178
  capture_message_content=capture_message_content,
@@ -139,47 +181,8 @@ def async_chat(version, environment, application_name,
139
181
  **kwargs
140
182
  )
141
183
 
142
- return response
143
-
144
- return wrapper
145
-
146
- def async_embeddings(version, environment, application_name,
147
- tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):
148
- """
149
- Generates a telemetry wrapper for GenAI function call
150
- """
151
-
152
- async def wrapper(wrapped, instance, args, kwargs):
153
- """
154
- Wraps the GenAI function call.
155
- """
156
-
157
- server_address, server_port = set_server_address_and_port(instance, '127.0.0.1', 11434)
158
- json_body = kwargs.get('json', {}) or {}
159
- request_model = json_body.get('model') or kwargs.get('model')
160
-
161
- span_name = f'{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}'
162
-
163
- with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
164
- start_time = time.time()
165
- response = await wrapped(*args, **kwargs)
166
- response = process_embedding_response(
167
- response=response,
168
- request_model=request_model,
169
- pricing_info=pricing_info,
170
- server_port=server_port,
171
- server_address=server_address,
172
- environment=environment,
173
- application_name=application_name,
174
- metrics=metrics,
175
- event_provider=event_provider,
176
- start_time=start_time,
177
- span=span,
178
- capture_message_content=capture_message_content,
179
- disable_metrics=disable_metrics,
180
- version=version,
181
- **kwargs
182
- )
184
+ except Exception as e:
185
+ handle_exception(span, e)
183
186
 
184
187
  return response
185
188