2626from opentelemetry .instrumentation .instrumentor import BaseInstrumentor
2727from opentelemetry .instrumentation .utils import unwrap
2828from opentelemetry .instrumentation .openai .environment_variables import (
29- ELASTIC_OTEL_GENAI_CAPTURE_CONTENT ,
3029 ELASTIC_OTEL_GENAI_EVENTS ,
30+ OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT ,
3131)
3232from opentelemetry .instrumentation .openai .helpers import (
3333 _get_embeddings_span_attributes_from_wrapper ,
@@ -78,10 +78,13 @@ def _instrument(self, **kwargs):
7878 ``tracer_provider``: a TracerProvider, defaults to global
7979 ``meter_provider``: a MeterProvider, defaults to global
8080 ``event_logger_provider``: a EventLoggerProvider, defaults to global
81- ``capture_content ``: to enable content capturing, defaults to False
81+ ``capture_message_content ``: to enable content capturing, defaults to False
8282 """
83- capture_content = "true" if kwargs .get ("capture_content" ) else "false"
84- self .capture_content = os .environ .get (ELASTIC_OTEL_GENAI_CAPTURE_CONTENT , capture_content ).lower () == "true"
83+ capture_message_content = "true" if kwargs .get ("capture_message_content" ) else "false"
84+ self .capture_message_content = (
85+ os .environ .get (OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT , capture_message_content ).lower ()
86+ == "true"
87+ )
8588
8689 # we support 3 values for deciding how to send events:
8790 # - "latest" to match latest semconv, as 1.27.0 it's span
@@ -135,7 +138,7 @@ def _patch(self, _module):
135138 )
136139
137140 def _uninstrument (self , ** kwargs ):
138- # unwrap only supports uninstrementing real module references so we
141+ # unwrap only supports uninstrumenting real module references so we
139142 # import here.
140143 import openai
141144
@@ -159,7 +162,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
159162 end_on_exit = False ,
160163 ) as span :
161164 # TODO: more fine grained depending on the message.role?
162- if self .capture_content :
165+ if self .capture_message_content :
163166 messages = kwargs .get ("messages" , [])
164167
165168 if self .event_kind == "log" :
@@ -184,7 +187,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
184187 return StreamWrapper (
185188 stream = result ,
186189 span = span ,
187- capture_content = self .capture_content ,
190+ capture_message_content = self .capture_message_content ,
188191 event_kind = self .event_kind ,
189192 event_attributes = event_attributes ,
190193 event_logger = self .event_logger ,
@@ -201,7 +204,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
201204 _record_token_usage_metrics (self .token_usage_metric , span , result .usage )
202205 _record_operation_duration_metric (self .operation_duration_metric , span , start_time )
203206
204- if self .capture_content :
207+ if self .capture_message_content :
205208 if self .event_kind == "log" :
206209 _send_log_events_from_choices (
207210 self .event_logger , choices = result .choices , attributes = event_attributes
@@ -234,7 +237,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
234237 # this is important to avoid having the span closed before ending the stream
235238 end_on_exit = False ,
236239 ) as span :
237- if self .capture_content :
240+ if self .capture_message_content :
238241 messages = kwargs .get ("messages" , [])
239242
240243 if self .event_kind == "log" :
@@ -259,7 +262,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
259262 return StreamWrapper (
260263 stream = result ,
261264 span = span ,
262- capture_content = self .capture_content ,
265+ capture_message_content = self .capture_message_content ,
263266 event_kind = self .event_kind ,
264267 event_attributes = event_attributes ,
265268 event_logger = self .event_logger ,
@@ -276,7 +279,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
276279 _record_token_usage_metrics (self .token_usage_metric , span , result .usage )
277280 _record_operation_duration_metric (self .operation_duration_metric , span , start_time )
278281
279- if self .capture_content :
282+ if self .capture_message_content :
280283 if self .event_kind == "log" :
281284 _send_log_events_from_choices (
282285 self .event_logger , choices = result .choices , attributes = event_attributes
0 commit comments