Skip to content

Commit 8182904

Browse files
codefromthecryptxrmx
authored andcommitted
elastic-opentelemetry-instrumentation-openai: normalizes env variables to upstream
This normalizes the ENV variables around content capture to match upstream.
1 parent dae460d commit 8182904

File tree

49 files changed

+101
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+101
-95
lines changed

instrumentation/elastic-opentelemetry-instrumentation-openai/README.md

Lines changed: 9 additions & 3 deletions

instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
2727
from opentelemetry.instrumentation.utils import unwrap
2828
from 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
)
3232
from 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

instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/environment_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
ELASTIC_OTEL_GENAI_CAPTURE_CONTENT = "ELASTIC_OTEL_GENAI_CAPTURE_CONTENT"
17+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"
1818

1919
ELASTIC_OTEL_GENAI_EVENTS = "ELASTIC_OTEL_GENAI_EVENTS"

instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/wrappers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(
4545
self,
4646
stream,
4747
span: Span,
48-
capture_content: bool,
48+
capture_message_content: bool,
4949
event_kind: Literal["log", "span"],
5050
event_attributes: Attributes,
5151
event_logger: EventLogger,
@@ -55,7 +55,7 @@ def __init__(
5555
):
5656
self.stream = stream
5757
self.span = span
58-
self.capture_content = capture_content
58+
self.capture_message_content = capture_message_content
5959
self.event_kind = event_kind
6060
self.event_attributes = event_attributes
6161
self.event_logger = event_logger
@@ -84,7 +84,7 @@ def end(self, exc=None):
8484
if self.usage:
8585
_record_token_usage_metrics(self.token_usage_metric, self.span, self.usage)
8686

87-
if self.capture_content:
87+
if self.capture_message_content:
8888
if self.event_kind == "log":
8989
_send_log_events_from_stream_choices(
9090
self.event_logger, choices=self.choices, span=self.span, attributes=self.event_attributes

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content[azure_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content[azure_provider_chat_completions].yaml

File renamed without changes.

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content[ollama_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content[ollama_provider_chat_completions].yaml

File renamed without changes.

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content[openai_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content[openai_provider_chat_completions].yaml

File renamed without changes.

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content_log_events[azure_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_log_events[azure_provider_chat_completions].yaml

File renamed without changes.

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content_log_events[ollama_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_log_events[ollama_provider_chat_completions].yaml

File renamed without changes.

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_content_log_events[openai_provider_chat_completions].yaml renamed to instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_log_events[openai_provider_chat_completions].yaml

File renamed without changes.

0 commit comments

Comments
 (0)