Skip to content

Commit 1379841

Browse files
committed
Remove embeddings capture via events
1 parent 3e286e2 commit 1379841

File tree

3 files changed

+0
-177
lines changed

3 files changed

+0
-177
lines changed

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
from openai import Stream
2020

2121
from opentelemetry._events import Event, EventLogger
22-
from opentelemetry.semconv._incubating.attributes import (
23-
event_attributes as EventAttributes,
24-
)
2522
from opentelemetry.semconv._incubating.attributes import (
2623
gen_ai_attributes as GenAIAttributes,
2724
)
@@ -438,50 +435,6 @@ def _set_embeddings_response_attributes(
438435
)
439436
# Don't set output tokens for embeddings as all tokens are input tokens
440437

441-
# Emit events for embeddings if content capture is enabled
442-
if capture_content:
443-
# Emit input event
444-
input_event_attributes = {
445-
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value,
446-
EventAttributes.EVENT_NAME: "gen_ai.embeddings.input",
447-
}
448-
event_logger.emit(
449-
Event(
450-
name="gen_ai.embeddings.input",
451-
attributes=input_event_attributes,
452-
body={"content": input_text, "role": "user"},
453-
)
454-
)
455-
456-
# Emit output event with embeddings data
457-
if getattr(result, "data", None) and len(result.data) > 0:
458-
embedding_data = []
459-
for item in result.data:
460-
if getattr(item, "embedding", None):
461-
embedding_data.append(
462-
{
463-
"index": item.index
464-
if hasattr(item, "index")
465-
else None,
466-
"embedding": item.embedding,
467-
"object": item.object
468-
if hasattr(item, "object")
469-
else "embedding",
470-
}
471-
)
472-
473-
output_event_attributes = {
474-
GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.OPENAI.value,
475-
EventAttributes.EVENT_NAME: "gen_ai.embeddings.output",
476-
}
477-
event_logger.emit(
478-
Event(
479-
name="gen_ai.embeddings.output",
480-
attributes=output_event_attributes,
481-
body={"embeddings": embedding_data},
482-
)
483-
)
484-
485438

486439
class ToolCallBuffer:
487440
def __init__(self, index, tool_call_id, function_name):

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_async_embeddings.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,71 +35,6 @@
3535
from opentelemetry.semconv._incubating.metrics import gen_ai_metrics
3636

3737

38-
@pytest.mark.asyncio
39-
@pytest.mark.vcr()
40-
async def test_async_embeddings_with_content(
41-
span_exporter, log_exporter, async_openai_client, instrument_with_content
42-
):
43-
"""Test creating embeddings asynchronously with content capture enabled"""
44-
model_name = "text-embedding-3-small"
45-
input_text = "This is a test for async embeddings"
46-
47-
response = await async_openai_client.embeddings.create(
48-
model=model_name,
49-
input=input_text,
50-
)
51-
52-
# Verify spans
53-
spans = span_exporter.get_finished_spans()
54-
assert len(spans) == 1
55-
assert_embedding_attributes(spans[0], model_name, response)
56-
57-
# Verify logs
58-
logs = log_exporter.get_finished_logs()
59-
assert (
60-
len(logs) == 2
61-
) # Should contain both input and output embeddings events
62-
63-
# Find input and output events
64-
input_event = None
65-
output_event = None
66-
for log in logs:
67-
if (
68-
log.log_record.attributes.get(EventAttributes.EVENT_NAME)
69-
== "gen_ai.embeddings.input"
70-
):
71-
input_event = log
72-
elif (
73-
log.log_record.attributes.get(EventAttributes.EVENT_NAME)
74-
== "gen_ai.embeddings.output"
75-
):
76-
output_event = log
77-
78-
# Verify both events exist
79-
assert input_event is not None, "Input embeddings event not found"
80-
assert output_event is not None, "Output embeddings event not found"
81-
82-
# Verify input event content
83-
input_content = {"content": input_text, "role": "user"}
84-
assert_message_in_logs(
85-
input_event, "gen_ai.embeddings.input", input_content, spans[0]
86-
)
87-
88-
# Verify output event content
89-
output_content = {
90-
"embeddings": [
91-
{
92-
"index": 0,
93-
"embedding": response.data[0].embedding,
94-
"object": "embedding",
95-
}
96-
]
97-
}
98-
assert_message_in_logs(
99-
output_event, "gen_ai.embeddings.output", output_content, spans[0]
100-
)
101-
102-
10338
@pytest.mark.asyncio
10439
@pytest.mark.vcr()
10540
async def test_async_embeddings_no_content(

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_embeddings.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,71 +35,6 @@
3535
from opentelemetry.semconv._incubating.metrics import gen_ai_metrics
3636

3737

38-
@pytest.mark.vcr()
39-
def test_embeddings_with_content(
40-
span_exporter, log_exporter, openai_client, instrument_with_content
41-
):
42-
"""Test creating embeddings with content capture enabled"""
43-
model_name = "text-embedding-3-small"
44-
input_text = "This is a test for embeddings"
45-
46-
response = openai_client.embeddings.create(
47-
model=model_name,
48-
input=input_text,
49-
)
50-
51-
# Verify spans
52-
spans = span_exporter.get_finished_spans()
53-
assert len(spans) == 1
54-
assert_embedding_attributes(spans[0], model_name, response)
55-
56-
# Verify logs
57-
logs = log_exporter.get_finished_logs()
58-
assert (
59-
len(logs) == 2
60-
) # Should contain both input and output embeddings events
61-
62-
# Find input and output events
63-
input_event = None
64-
output_event = None
65-
for log in logs:
66-
if (
67-
log.log_record.attributes.get(EventAttributes.EVENT_NAME)
68-
== "gen_ai.embeddings.input"
69-
):
70-
input_event = log
71-
elif (
72-
log.log_record.attributes.get(EventAttributes.EVENT_NAME)
73-
== "gen_ai.embeddings.output"
74-
):
75-
output_event = log
76-
77-
# Verify both events exist
78-
assert input_event is not None, "Input embeddings event not found"
79-
assert output_event is not None, "Output embeddings event not found"
80-
81-
# Verify input event content
82-
input_content = {"content": input_text, "role": "user"}
83-
assert_message_in_logs(
84-
input_event, "gen_ai.embeddings.input", input_content, spans[0]
85-
)
86-
87-
# Verify output event content
88-
# We don't need to specify exact values since the test provides a helper function to verify
89-
output_content = {
90-
"embeddings": [
91-
{
92-
"index": 0,
93-
"embedding": response.data[0].embedding,
94-
"object": "embedding",
95-
}
96-
]
97-
}
98-
assert_message_in_logs(
99-
output_event, "gen_ai.embeddings.output", output_content, spans[0]
100-
)
101-
102-
10338
@pytest.mark.vcr()
10439
def test_embeddings_no_content(
10540
span_exporter, log_exporter, openai_client, instrument_no_content

0 commit comments

Comments
 (0)