Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ This instrumentation supports *0-code* / *autoinstrumentation*:
```
opentelemetry-instrument python use_openai.py

# You can record more information about prompts as span events by enabling content capture.
# You can record more information about prompts as log events by enabling content capture.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true opentelemetry-instrument python use_openai.py

# You can record more information about prompts as log events by enabling content capture.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true ELASTIC_OTEL_GENAI_EVENTS=log opentelemetry-instrument python use_openai.py
# You can record more information about prompts as span events by enabling content capture.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true ELASTIC_OTEL_GENAI_EVENTS=span opentelemetry-instrument python use_openai.py
```

Or manual instrumentation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,25 @@ def _instrument(self, **kwargs):
)

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

tracer_provider = kwargs.get("tracer_provider")
self.tracer = get_tracer(
__name__,
__version__,
tracer_provider,
schema_url=Schemas.V1_27_0.value,
schema_url=Schemas.V1_28_0.value,
)
meter_provider = kwargs.get("meter_provider")
self.meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url=Schemas.V1_27_0.value,
schema_url=Schemas.V1_28_0.value,
)
event_logger_provider = kwargs.get("event_logger_provider")
self.event_logger = get_event_logger(__name__, event_logger_provider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def _get_span_attributes_from_wrapper(instance, kwargs) -> Attributes:
GEN_AI_SYSTEM: "openai",
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ interactions:
}
}
],
"created": 1731468960,
"id": "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM",
"created": 1731466221,
"id": "chatcmpl-ASxkTeNjqCBy25d2g18faeBtc66GG",
"model": "gpt-4-32k",
"object": "chat.completion",
"prompt_filter_results": [
Expand Down Expand Up @@ -122,33 +122,33 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 13 Nov 2024 03:36:00 GMT
- Wed, 13 Nov 2024 02:50:21 GMT
Set-Cookie: test_set_cookie
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
access-control-allow-origin:
- '*'
apim-request-id:
- 38407302-010e-4318-8ba2-cd1c61e474c5
- 53c69374-78ff-4de0-a446-253028228455
azureml-model-session:
- d156-20241010120317
- d158-20241010133731
openai-organization: test_openai_org_id
x-accel-buffering:
- 'no'
x-content-type-options:
- nosniff
x-ms-client-request-id:
- 38407302-010e-4318-8ba2-cd1c61e474c5
- 53c69374-78ff-4de0-a446-253028228455
x-ms-rai-invoked:
- 'true'
x-ms-region:
- Switzerland North
x-ratelimit-remaining-requests:
- '79'
- '71'
x-ratelimit-remaining-tokens:
- '79968'
- '79644'
x-request-id:
- 3910c5ca-854a-481d-b76c-e4140883c952
- 54470131-0498-4318-a448-5d99d1e57699
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interactions:
body:
string: |-
{
"id": "chatcmpl-816",
"id": "chatcmpl-295",
"object": "chat.completion",
"created": 1731311784,
"model": "qwen2.5:0.5b",
Expand All @@ -59,20 +59,20 @@ interactions:
"index": 0,
"message": {
"role": "assistant",
"content": "Antarctica ocean."
"content": "The Falkland Islands are located in which ocean?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 46,
"completion_tokens": 6,
"total_tokens": 52
"completion_tokens": 11,
"total_tokens": 57
}
}
headers:
Content-Length:
- '303'
- '335'
Content-Type:
- application/json
Date:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interactions:
body:
string: |-
{
"id": "chatcmpl-ASfaOHHT6qOYpFc5M7uzSkgfXnnpJ",
"id": "chatcmpl-ASfaOykfLmr5qdUddSbFIDNGReNRJ",
"object": "chat.completion",
"created": 1731396404,
"model": "gpt-4o-mini-2024-07-18",
Expand Down Expand Up @@ -86,7 +86,7 @@ interactions:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8e14cba439f0ce22-SIN
- 8e14cba7eed66bbd-SIN
Connection:
- keep-alive
Content-Type:
Expand All @@ -108,7 +108,7 @@ interactions:
- '771'
openai-organization: test_openai_org_key
openai-processing-ms:
- '213'
- '249'
openai-version:
- '2020-10-01'
strict-transport-security:
Expand All @@ -118,15 +118,15 @@ interactions:
x-ratelimit-limit-tokens:
- '200000'
x-ratelimit-remaining-requests:
- '9984'
- '9983'
x-ratelimit-remaining-tokens:
- '199966'
x-ratelimit-reset-requests:
- 2m17.802s
- 2m25.844s
x-ratelimit-reset-tokens:
- 10ms
x-request-id:
- req_e6b1a7306539cbcad166c1907ae46d4f
- req_3bef9643428bce1d1e43d476d8ef1c43
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
interactions:
- request:
body: |-
{
"messages": [
{
"role": "user",
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
}
],
"model": "unused"
}
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
api-key:
- test_azure_api_key
authorization:
- Bearer test_openai_api_key
connection:
- keep-alive
content-length:
- '133'
content-type:
- application/json
host:
- test.openai.azure.com
user-agent:
- AsyncAzureOpenAI/Python 1.54.3
x-stainless-arch:
- arm64
x-stainless-async:
- async:asyncio
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.54.3
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.12.6
method: POST
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview
response:
body:
string: |-
{
"choices": [
{
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
},
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "Atlantic Ocean",
"role": "assistant"
}
}
],
"created": 1731468960,
"id": "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM",
"model": "gpt-4-32k",
"object": "chat.completion",
"prompt_filter_results": [
{
"prompt_index": 0,
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
],
"system_fingerprint": null,
"usage": {
"completion_tokens": 2,
"prompt_tokens": 24,
"total_tokens": 26
}
}
headers:
Cache-Control:
- no-cache, must-revalidate
Content-Length:
- '805'
Content-Type:
- application/json
Date:
- Wed, 13 Nov 2024 03:36:00 GMT
Set-Cookie: test_set_cookie
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
access-control-allow-origin:
- '*'
apim-request-id:
- 38407302-010e-4318-8ba2-cd1c61e474c5
azureml-model-session:
- d156-20241010120317
openai-organization: test_openai_org_id
x-accel-buffering:
- 'no'
x-content-type-options:
- nosniff
x-ms-client-request-id:
- 38407302-010e-4318-8ba2-cd1c61e474c5
x-ms-rai-invoked:
- 'true'
x-ms-region:
- Switzerland North
x-ratelimit-remaining-requests:
- '79'
x-ratelimit-remaining-tokens:
- '79968'
x-request-id:
- 3910c5ca-854a-481d-b76c-e4140883c952
status:
code: 200
message: OK
version: 1
Loading