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,10 @@ 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 = os .environ .get (OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT , capture_message_content ).lower () == "true"
8585
8686 # we support 3 values for deciding how to send events:
8787 # - "latest" to match latest semconv, as 1.27.0 it's span
@@ -135,7 +135,7 @@ def _patch(self, _module):
135135 )
136136
137137 def _uninstrument (self , ** kwargs ):
138- # unwrap only supports uninstrementing real module references so we
138+ # unwrap only supports uninstrumenting real module references so we
139139 # import here.
140140 import openai
141141
@@ -159,7 +159,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
159159 end_on_exit = False ,
160160 ) as span :
161161 # TODO: more fine grained depending on the message.role?
162- if self .capture_content :
162+ if self .capture_message_content :
163163 messages = kwargs .get ("messages" , [])
164164
165165 if self .event_kind == "log" :
@@ -184,7 +184,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
184184 return StreamWrapper (
185185 stream = result ,
186186 span = span ,
187- capture_content = self .capture_content ,
187+ capture_message_content = self .capture_message_content ,
188188 event_kind = self .event_kind ,
189189 event_attributes = event_attributes ,
190190 event_logger = self .event_logger ,
@@ -201,7 +201,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs):
201201 _record_token_usage_metrics (self .token_usage_metric , span , result .usage )
202202 _record_operation_duration_metric (self .operation_duration_metric , span , start_time )
203203
204- if self .capture_content :
204+ if self .capture_message_content :
205205 if self .event_kind == "log" :
206206 _send_log_events_from_choices (
207207 self .event_logger , choices = result .choices , attributes = event_attributes
@@ -234,7 +234,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
234234 # this is important to avoid having the span closed before ending the stream
235235 end_on_exit = False ,
236236 ) as span :
237- if self .capture_content :
237+ if self .capture_message_content :
238238 messages = kwargs .get ("messages" , [])
239239
240240 if self .event_kind == "log" :
@@ -259,7 +259,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
259259 return StreamWrapper (
260260 stream = result ,
261261 span = span ,
262- capture_content = self .capture_content ,
262+ capture_message_content = self .capture_message_content ,
263263 event_kind = self .event_kind ,
264264 event_attributes = event_attributes ,
265265 event_logger = self .event_logger ,
@@ -276,7 +276,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs):
276276 _record_token_usage_metrics (self .token_usage_metric , span , result .usage )
277277 _record_operation_duration_metric (self .operation_duration_metric , span , start_time )
278278
279- if self .capture_content :
279+ if self .capture_message_content :
280280 if self .event_kind == "log" :
281281 _send_log_events_from_choices (
282282 self .event_logger , choices = result .choices , attributes = event_attributes
0 commit comments