Skip to content

Commit 2342cb3

Browse files
elastic-opentelemetry-instrumentation-openai: switches to 1.28.0 default of log events (#31)
* elastic-opentelemetry-instrumentation-openai: switches to 1.28.0 default of log events This switches the event format default to log events per the recently released semver 1.28.0. Note: this doesn't yet delete span event support. * Remove stale comment Model is mandatory with azure client too. * Update timing for embeddings test --------- Co-authored-by: Adrian Cole <[email protected]>
1 parent 80de27a commit 2342cb3

File tree

46 files changed

+3725
-345
lines changed

Some content is hidden

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

46 files changed

+3725
-345
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ This instrumentation supports *0-code* / *autoinstrumentation*:
2424
```
2525
opentelemetry-instrument python use_openai.py
2626
27-
# You can record more information about prompts as span events by enabling content capture.
27+
# You can record more information about prompts as log events by enabling content capture.
2828
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true opentelemetry-instrument python use_openai.py
2929
30-
# You can record more information about prompts as log events by enabling content capture.
31-
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true ELASTIC_OTEL_GENAI_EVENTS=log opentelemetry-instrument python use_openai.py
30+
# You can record more information about prompts as span events by enabling content capture.
31+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true ELASTIC_OTEL_GENAI_EVENTS=span opentelemetry-instrument python use_openai.py
3232
```
3333

3434
Or manual instrumentation:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,25 @@ def _instrument(self, **kwargs):
8787
)
8888

8989
# we support 3 values for deciding how to send events:
90-
# - "latest" to match latest semconv, as 1.27.0 it's span
91-
# - "log" to send log events
92-
# - "span" to send span events (default)
90+
# - "latest" to match latest semconv, as 1.28.0 it's log
91+
# - "log" to send log events (default)
92+
# - "span" to send span events
9393
genai_events = os.environ.get(ELASTIC_OTEL_GENAI_EVENTS, "latest").lower()
94-
self.event_kind = "log" if genai_events == "log" else "span"
94+
self.event_kind = "span" if genai_events == "span" else "log"
9595

9696
tracer_provider = kwargs.get("tracer_provider")
9797
self.tracer = get_tracer(
9898
__name__,
9999
__version__,
100100
tracer_provider,
101-
schema_url=Schemas.V1_27_0.value,
101+
schema_url=Schemas.V1_28_0.value,
102102
)
103103
meter_provider = kwargs.get("meter_provider")
104104
self.meter = get_meter(
105105
__name__,
106106
__version__,
107107
meter_provider,
108-
schema_url=Schemas.V1_27_0.value,
108+
schema_url=Schemas.V1_28_0.value,
109109
)
110110
event_logger_provider = kwargs.get("event_logger_provider")
111111
self.event_logger = get_event_logger(__name__, event_logger_provider)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def _get_span_attributes_from_wrapper(instance, kwargs) -> Attributes:
158158
GEN_AI_SYSTEM: "openai",
159159
}
160160

161-
# on some azure clients the model was not mandatory
162161
if (request_model := kwargs.get("model")) is not None:
163162
span_attributes[GEN_AI_REQUEST_MODEL] = request_model
164163

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ interactions:
8080
}
8181
}
8282
],
83-
"created": 1731468960,
84-
"id": "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM",
83+
"created": 1731466221,
84+
"id": "chatcmpl-ASxkTeNjqCBy25d2g18faeBtc66GG",
8585
"model": "gpt-4-32k",
8686
"object": "chat.completion",
8787
"prompt_filter_results": [
@@ -122,33 +122,33 @@ interactions:
122122
Content-Type:
123123
- application/json
124124
Date:
125-
- Wed, 13 Nov 2024 03:36:00 GMT
125+
- Wed, 13 Nov 2024 02:50:21 GMT
126126
Set-Cookie: test_set_cookie
127127
Strict-Transport-Security:
128128
- max-age=31536000; includeSubDomains; preload
129129
access-control-allow-origin:
130130
- '*'
131131
apim-request-id:
132-
- 38407302-010e-4318-8ba2-cd1c61e474c5
132+
- 53c69374-78ff-4de0-a446-253028228455
133133
azureml-model-session:
134-
- d156-20241010120317
134+
- d158-20241010133731
135135
openai-organization: test_openai_org_id
136136
x-accel-buffering:
137137
- 'no'
138138
x-content-type-options:
139139
- nosniff
140140
x-ms-client-request-id:
141-
- 38407302-010e-4318-8ba2-cd1c61e474c5
141+
- 53c69374-78ff-4de0-a446-253028228455
142142
x-ms-rai-invoked:
143143
- 'true'
144144
x-ms-region:
145145
- Switzerland North
146146
x-ratelimit-remaining-requests:
147-
- '79'
147+
- '71'
148148
x-ratelimit-remaining-tokens:
149-
- '79968'
149+
- '79644'
150150
x-request-id:
151-
- 3910c5ca-854a-481d-b76c-e4140883c952
151+
- 54470131-0498-4318-a448-5d99d1e57699
152152
status:
153153
code: 200
154154
message: OK

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interactions:
4949
body:
5050
string: |-
5151
{
52-
"id": "chatcmpl-816",
52+
"id": "chatcmpl-295",
5353
"object": "chat.completion",
5454
"created": 1731311784,
5555
"model": "qwen2.5:0.5b",
@@ -59,20 +59,20 @@ interactions:
5959
"index": 0,
6060
"message": {
6161
"role": "assistant",
62-
"content": "Antarctica ocean."
62+
"content": "The Falkland Islands are located in which ocean?"
6363
},
6464
"finish_reason": "stop"
6565
}
6666
],
6767
"usage": {
6868
"prompt_tokens": 46,
69-
"completion_tokens": 6,
70-
"total_tokens": 52
69+
"completion_tokens": 11,
70+
"total_tokens": 57
7171
}
7272
}
7373
headers:
7474
Content-Length:
75-
- '303'
75+
- '335'
7676
Content-Type:
7777
- application/json
7878
Date:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interactions:
4949
body:
5050
string: |-
5151
{
52-
"id": "chatcmpl-ASfaOHHT6qOYpFc5M7uzSkgfXnnpJ",
52+
"id": "chatcmpl-ASfaOykfLmr5qdUddSbFIDNGReNRJ",
5353
"object": "chat.completion",
5454
"created": 1731396404,
5555
"model": "gpt-4o-mini-2024-07-18",
@@ -86,7 +86,7 @@ interactions:
8686
CF-Cache-Status:
8787
- DYNAMIC
8888
CF-RAY:
89-
- 8e14cba439f0ce22-SIN
89+
- 8e14cba7eed66bbd-SIN
9090
Connection:
9191
- keep-alive
9292
Content-Type:
@@ -108,7 +108,7 @@ interactions:
108108
- '771'
109109
openai-organization: test_openai_org_key
110110
openai-processing-ms:
111-
- '213'
111+
- '249'
112112
openai-version:
113113
- '2020-10-01'
114114
strict-transport-security:
@@ -118,15 +118,15 @@ interactions:
118118
x-ratelimit-limit-tokens:
119119
- '200000'
120120
x-ratelimit-remaining-requests:
121-
- '9984'
121+
- '9983'
122122
x-ratelimit-remaining-tokens:
123123
- '199966'
124124
x-ratelimit-reset-requests:
125-
- 2m17.802s
125+
- 2m25.844s
126126
x-ratelimit-reset-tokens:
127127
- 10ms
128128
x-request-id:
129-
- req_e6b1a7306539cbcad166c1907ae46d4f
129+
- req_3bef9643428bce1d1e43d476d8ef1c43
130130
status:
131131
code: 200
132132
message: OK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
interactions:
2+
- request:
3+
body: |-
4+
{
5+
"messages": [
6+
{
7+
"role": "user",
8+
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
9+
}
10+
],
11+
"model": "unused"
12+
}
13+
headers:
14+
accept:
15+
- application/json
16+
accept-encoding:
17+
- gzip, deflate
18+
api-key:
19+
- test_azure_api_key
20+
authorization:
21+
- Bearer test_openai_api_key
22+
connection:
23+
- keep-alive
24+
content-length:
25+
- '133'
26+
content-type:
27+
- application/json
28+
host:
29+
- test.openai.azure.com
30+
user-agent:
31+
- AsyncAzureOpenAI/Python 1.54.3
32+
x-stainless-arch:
33+
- arm64
34+
x-stainless-async:
35+
- async:asyncio
36+
x-stainless-lang:
37+
- python
38+
x-stainless-os:
39+
- MacOS
40+
x-stainless-package-version:
41+
- 1.54.3
42+
x-stainless-retry-count:
43+
- '0'
44+
x-stainless-runtime:
45+
- CPython
46+
x-stainless-runtime-version:
47+
- 3.12.6
48+
method: POST
49+
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview
50+
response:
51+
body:
52+
string: |-
53+
{
54+
"choices": [
55+
{
56+
"content_filter_results": {
57+
"hate": {
58+
"filtered": false,
59+
"severity": "safe"
60+
},
61+
"self_harm": {
62+
"filtered": false,
63+
"severity": "safe"
64+
},
65+
"sexual": {
66+
"filtered": false,
67+
"severity": "safe"
68+
},
69+
"violence": {
70+
"filtered": false,
71+
"severity": "safe"
72+
}
73+
},
74+
"finish_reason": "stop",
75+
"index": 0,
76+
"logprobs": null,
77+
"message": {
78+
"content": "Atlantic Ocean",
79+
"role": "assistant"
80+
}
81+
}
82+
],
83+
"created": 1731468960,
84+
"id": "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM",
85+
"model": "gpt-4-32k",
86+
"object": "chat.completion",
87+
"prompt_filter_results": [
88+
{
89+
"prompt_index": 0,
90+
"content_filter_results": {
91+
"hate": {
92+
"filtered": false,
93+
"severity": "safe"
94+
},
95+
"self_harm": {
96+
"filtered": false,
97+
"severity": "safe"
98+
},
99+
"sexual": {
100+
"filtered": false,
101+
"severity": "safe"
102+
},
103+
"violence": {
104+
"filtered": false,
105+
"severity": "safe"
106+
}
107+
}
108+
}
109+
],
110+
"system_fingerprint": null,
111+
"usage": {
112+
"completion_tokens": 2,
113+
"prompt_tokens": 24,
114+
"total_tokens": 26
115+
}
116+
}
117+
headers:
118+
Cache-Control:
119+
- no-cache, must-revalidate
120+
Content-Length:
121+
- '805'
122+
Content-Type:
123+
- application/json
124+
Date:
125+
- Wed, 13 Nov 2024 03:36:00 GMT
126+
Set-Cookie: test_set_cookie
127+
Strict-Transport-Security:
128+
- max-age=31536000; includeSubDomains; preload
129+
access-control-allow-origin:
130+
- '*'
131+
apim-request-id:
132+
- 38407302-010e-4318-8ba2-cd1c61e474c5
133+
azureml-model-session:
134+
- d156-20241010120317
135+
openai-organization: test_openai_org_id
136+
x-accel-buffering:
137+
- 'no'
138+
x-content-type-options:
139+
- nosniff
140+
x-ms-client-request-id:
141+
- 38407302-010e-4318-8ba2-cd1c61e474c5
142+
x-ms-rai-invoked:
143+
- 'true'
144+
x-ms-region:
145+
- Switzerland North
146+
x-ratelimit-remaining-requests:
147+
- '79'
148+
x-ratelimit-remaining-tokens:
149+
- '79968'
150+
x-request-id:
151+
- 3910c5ca-854a-481d-b76c-e4140883c952
152+
status:
153+
code: 200
154+
message: OK
155+
version: 1

0 commit comments

Comments
 (0)