-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blog post for OpenTelemetry Generative AI updates #5575
Open
drewby
wants to merge
95
commits into
open-telemetry:main
Choose a base branch
from
drewby:drewby/genai_blog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−0
Open
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
5c062d9
Initial draft
drewby e4735c4
Merge branch 'open-telemetry:main' into drewby/genai_blog
drewby 5c9a04b
Add screenshots
drewby c3d7c9e
Update link for Python repo
drewby db18921
fix spelling error
drewby 67f2bc9
Add link to Aspire Dashboard
drewby 6a51e0c
Add link to Jaeger
drewby 21b9c42
Updates from PR review
drewby 2e9eab2
Rename files
drewby a682d22
Pin version
drewby a437c07
Update linting/spelling error
drewby 9984bb5
Fix format error
drewby c02d7c1
Updates to library intro and metric section
drewby 7481b81
Update introduction
drewby ee503df
Use headers instead of bold
drewby 5fd96c3
Fix formatting
drewby ebbfab4
Link to docs page
drewby cf035e0
Add links to spec and python projects
drewby a6e4b96
Colon instead of period
drewby 41aa9dc
Add issue and sig
drewby 0189c62
Move text to flow better in outline
drewby 86e6c4d
Clarify library focus
drewby fceb35f
Add comment about using Events
drewby 30b6e38
Change Spans to Traces
drewby a0f3250
Specifics about the first Instrumentation Library
drewby 377b27a
Use alert shortcode
drewby d96b423
Add link to instrumentation library
drewby 076a6dc
Add link to "submit a PR" to ecosystem pages (#5571)
chalin 64c919d
Fix: fix dice number generator in JS examples (#5565)
oscar60310 00aea1f
Change Embrace Android distro component to Android (#5530)
davidlawrencer 366f6fa
Update opentelemetry-java version to v1.44.1 (#5577)
opentelemetrybot 2143b7c
Add new page feedback issue template (#5548)
svrnm 387abd2
Update java docs for 1.44.0 release (#5566)
jack-berg 0ad8134
add a "flag" filter to registry (#5328)
taylorhelene b176b96
add tags to registry entries (#5382)
olamideTiana be02c5d
Add quick installation for maven to the registry (#5330)
mercybassey 3c79c00
Add missing heading ids on lang:ja (#5584)
katzchang 78cece9
[CI] adjust-pages: report obsolete patch-code as INFO msgs (#5587)
chalin 19203c5
update pull request template (#5545)
svrnm 5adbe82
[es] restore observability primer (#5589)
svrnm 004375e
Remove unused import in Python prometheus doc (#5585)
mimikwang c3dc83c
[pt] Translate multiple pages on /pt/docs/languages/go (#5426)
vitorvasc b68e5f0
Revise k8s operator docs for Python after latest releases (#5583)
xrmx 045a384
Add missing en anchors for ES translations (#5580)
theletterf 480e666
docs: Add HTTP port to collector docker command (#5441)
kaylareopelle 5b93bb2
Add missing en anchors for PT-BR translations (#5594)
emdneto 1ce7435
Auto-update registry versions (1c01fda8cc057d3ae5bd6aca2a24b920ed9382…
opentelemetrybot 0e09925
Update opentelemetry-java-instrumentation version to v2.10.0 (#5598)
opentelemetrybot dcf3563
Update registry schema to allow any https URL for authors (#5605)
svrnm 5e89372
[pt] Temporarily patch page to avoid link-check failure (#5603)
emdneto 1de7735
Registry: add missing URL for Traefik (#5602)
chalin ed549af
Fix lint/link errors
drewby 8d893e3
Update code sample
drewby 9335129
fix format
drewby 035a0ac
Update code sample
drewby fb43d44
Updating the python example
drewby 3618743
Update jaeger url
drewby 9c81402
Add example of running with auto-instrument.
drewby fdd0e24
Updates from PR review
drewby f433d6e
Registry data cleanup: add urls to all authors (#5608)
svrnm 8e2f28a
[CI] Ensure that htmltest-config warnings fail GH check (#5612)
chalin 01b1940
Move performance to java agent, merge javadoc into API page (#5590)
jack-berg b0f7a2b
fixed installation command (#5614)
cglucks 58d5b7f
Blogpost to annoucing 2024 OTel Community Awards winners (#5613)
danielgblanco 6dc73c5
[ja] Temporarily patch page to avoid link-check failure (#5609)
katzchang 46cadd1
Added OddDotNet registry files (Attempt 2) (#5617)
DoubleTK b5842e9
Add maven to registry auto update workflow (#5586)
svrnm 562ea76
Auto-update registry versions (d41be13e5aa782b005c7e9617441cfff363917…
opentelemetrybot 0adbf1e
[CI] Detect unpinned git submodules in GH PR checks (#5627)
chalin 8a3c706
NPM packages refresh (#5628)
chalin 36981ac
Auto-update registry versions (e44886bbd0f9f00489124008e11f85ae080b48…
opentelemetrybot a2c6be4
Registry Updates Novemeber 2024 (#5625)
svrnm 671ca18
Sort and update community members page (#5619)
svrnm efe1747
Disable code-excerpting from Go getting-started (#5630)
chalin 610975b
Java documentation for cardinality limits (#5610)
jack-berg cef3b82
Add Logback MDC to the starter (#5636)
jeanbisutti b6603c5
Update opentelemetry-collector-releases version to v0.114.0 (#5638)
opentelemetrybot 9f4865f
Fix title for Rust stdout exporter (#5633)
AaronRM b2f9a3c
Updated summary and table of internal telemetry (#5567)
jade-guiton-dd 2d2accc
Update to Hugo 0.139.0 (#5642)
chalin f8a5dc9
[CI] Ensure that all `/fix` commands trigger a script (#5648)
chalin c65e4d9
Enable new page feedback template in hugo (#5582)
svrnm 711a6ff
Update content/en/blog/2024/otel-generative-ai/index.md
drewby c8bc856
Updates from PR feedback
drewby bb61aff
fix format
drewby c6bc6d7
Merge branch 'open-telemetry:main' into drewby/genai_blog
drewby b232156
Add contributors
drewby 6d68fa9
Merge branch 'open-telemetry:main' into drewby/genai_blog
drewby 510ed57
Shorten linkTitle
drewby b357cb7
Fix issue link
drewby bc07e57
Add example to export to console
drewby 2229453
Update alert for Events usage
drewby dd2f421
Update export to console
drewby 7a9c721
Results from /fix:refcache
opentelemetrybot 4b9daa4
Merge branch 'open-telemetry:main' into drewby/genai_blog
drewby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+136 KB
content/en/blog/2024/otel-generative-ai/aspire-dashboard-content-capture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
--- | ||
title: OpenTelemetry for Generative AI | ||
linkTitle: OTel for GenAI | ||
date: 2024-11-09 | ||
author: >- | ||
[Drew Robbins](https://github.com/drewby) (Microsoft), [Liudmila | ||
Molkova](https://github.com/lmolkova) (Microsoft) | ||
issue: https://github.com/open-telemetry/opentelemetry.io/issues/5581 | ||
sig: SIG GenAI Observability | ||
cSpell:ignore: genai liudmila molkova | ||
--- | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
As organizations increasingly adopt Large Language Models (LLMs) and other | ||
generative AI technologies, ensuring reliable performance, efficiency, and | ||
safety is essential to meet user expectations, optimize resource costs, and | ||
safeguard against unintended outputs. Effective observability for AI operations, | ||
behaviors, and outcomes can help meet these goals. OpenTelemetry is being | ||
enhanced to support these needs specifically for generative AI. | ||
|
||
Two primary assets are in development to make this possible: **Semantic | ||
Conventions** and **Instrumentation Libraries**. The first instrumentation | ||
library targets the | ||
[OpenAI Python API library](https://pypi.org/project/openai/). | ||
|
||
[**Semantic Conventions**](/docs/concepts/semantic-conventions/) establish | ||
standardized guidelines for how telemetry data is structured and collected | ||
across platforms, defining inputs, outputs, and operational details. For | ||
generative AI, these conventions streamline monitoring, troubleshooting, and | ||
optimizing AI models by standardizing attributes such as model parameters, | ||
response metadata, and token usage. This consistency supports better | ||
observability across tools, environments, and APIs, helping organizations track | ||
performance, cost, and safety with ease. | ||
|
||
The | ||
[**Instrumentation Library**](/docs/specs/otel/overview/#instrumentation-libraries) | ||
is being developed within the | ||
[OpenTelemetry Python Contrib](https://github.com/open-telemetry/opentelemetry-python-contrib) | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
under | ||
[instrumentation-genai](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation-genai) | ||
project to automate telemetry collection for generative AI applications. The | ||
first release is a Python library for instrumenting OpenAI client calls. This | ||
library captures spans and events, gathering essential data like model inputs, | ||
response metadata, and token usage in a structured format. | ||
|
||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Key Signals for Generative AI | ||
|
||
The [Semantic Conventions for Generative AI](/docs/specs/semconv/gen-ai/) focus | ||
on capturing insights into AI model behavior through three primary signals: | ||
[Traces](/docs/concepts/signals/traces/), | ||
[Metrics](/docs/concepts/signals/metrics/), and | ||
[Events](/docs/specs/otel/logs/event-api/). | ||
|
||
Together, these signals provide a comprehensive monitoring framework, enabling | ||
better cost management, performance tuning, and request tracing. | ||
|
||
### Traces: Tracing Model Interactions | ||
|
||
Traces track each model interaction's lifecycle, covering input parameters (for | ||
example, temperature, top_p) and response details like token count or errors. | ||
They provide visibility into each request, aiding in identifying bottlenecks and | ||
analyzing the impact of settings on model output. | ||
|
||
### Metrics: Monitoring Usage and Performance | ||
|
||
Metrics aggregate high-level indicators like request volume, latency, and token | ||
counts, essential for managing costs and performance. This data is particularly | ||
critical for API-dependent AI applications with rate limits and cost | ||
considerations. | ||
|
||
### Events: Capturing Detailed Interactions | ||
|
||
Events log detailed moments during model execution, such as user prompts and | ||
model responses, providing a granular view of model interactions. These insights | ||
are invaluable for debugging and optimizing AI applications where unexpected | ||
behaviors may arise. | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{{% alert title="Note" color="info" %}} Note that we decided to use | ||
[events emitted](/docs/specs/otel/logs/api/#emit-an-event) with the | ||
[Logs API](/docs/specs/otel/logs/api/) specification in the Semantic Conventions | ||
for Generative AI. Events allows for us to define specific | ||
[semantic conventions](/docs/specs/semconv/general/events/) for the user prompts | ||
and model responses that we capture. This addition to the API is in development | ||
and considered unstable.{{% /alert %}} | ||
|
||
### Extending Observability with Vendor-Specific Attributes | ||
|
||
The Semantic Conventions also define vendor-specific attributes for platforms | ||
like OpenAI and Azure Inference API, ensuring telemetry captures both general | ||
and provider-specific details. This added flexibility supports multi-platform | ||
monitoring and in-depth insights. | ||
|
||
## Building the Python Instrumentation Library for OpenAI | ||
|
||
This Python-based library for OpenTelemetry captures key telemetry signals for | ||
OpenAI models, providing developers with an out-of-the-box observability | ||
solution tailored to AI workloads. The library, | ||
[hosted within the OpenTelemetry Python Contrib repository](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/opentelemetry-instrumentation-openai-v2%3D%3D2.0b0/instrumentation-genai/opentelemetry-instrumentation-openai-v2), | ||
automatically collects telemetry from OpenAI model interactions, including | ||
request and response metadata and token usage. | ||
|
||
As generative AI applications grow, additional instrumentation libraries for | ||
other languages will follow, extending OpenTelemetry support across more tools | ||
and environments. The current library's focus on OpenAI highlights its | ||
popularity and demand within AI development, making it a valuable initial | ||
implementation. | ||
|
||
### Example Usage | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Here's an example of using the OpenTelemetry Python library to monitor a | ||
generative AI application with the OpenAI client. | ||
|
||
Install the OpenTelemetry dependencies: | ||
|
||
```shell | ||
pip install opentelemetry-distro | ||
opentelemetry-bootstrap -a install | ||
``` | ||
|
||
Set the following environment variables, updating the endpoint and protocol as | ||
appropriate: | ||
|
||
```shell | ||
OPENAI_API_KEY=<replace_with_your_openai_api_key> | ||
|
||
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf | ||
OTEL_SERVICE_NAME=python-opentelemetry-openai | ||
OTEL_LOGS_EXPORTER=otlp_proto_http | ||
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true | ||
# Set to false or remove to disable log events | ||
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
Then include the following code in your Python application: | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python | ||
import os | ||
from openai import OpenAI | ||
|
||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client = OpenAI() | ||
chat_completion = client.chat.completions.create( | ||
model=os.getenv("CHAT_MODEL", "gpt-4o-mini"), | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "Write a short poem on OpenTelemetry.", | ||
}, | ||
], | ||
) | ||
print(chat_completion.choices[0].message.content) | ||
``` | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
And then run the example using `opentelemetry-instrument`: | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```shell | ||
opentelemetry-instrument python main.py | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
If you do not have a service running to collect telemetry, you can export to the | ||
console using the following: | ||
|
||
```shell | ||
opentelemetry-instrument --traces_exporter console --metrics_exporter console python main.py | ||
``` | ||
|
||
There is a complete example | ||
[available here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation-genai/opentelemetry-instrumentation-openai-v2/example). | ||
|
||
With this simple instrumentation, one can begin capture traces from their | ||
generative AI application. Here is an example from the | ||
[Aspire Dashboard](https://learn.microsoft.com/dotnet/aspire/fundamentals/dashboard/standalone?tabs=bash) | ||
for local debugging. | ||
|
||
![Chat trace in Aspire Dashboard](aspire-dashboard-trace.png) | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Here is a similar trace captured in | ||
[Jaeger](https://www.jaegertracing.io/docs/1.63/getting-started/#all-in-one): | ||
|
||
![Chat trace in Jaeger](jaeger-trace.png) | ||
|
||
It's also easy to capture the content history of the chat for debugging and | ||
improving your application. Simply set the environment variable | ||
`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` as follows: | ||
|
||
```shell | ||
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=True | ||
``` | ||
|
||
This will turn on content capture which collects OpenTelemetry events containing | ||
the payload: | ||
|
||
![Content Capture Aspire Dashboard](aspire-dashboard-content-capture.png) | ||
|
||
## Join Us in Shaping the Future of Generative AI Observability | ||
|
||
Community collaboration is key to OpenTelemetry's success. We invite developers, | ||
AI practitioners, and organizations to contribute, share feedback, or | ||
participate in discussions. Explore the OpenTelemetry Python Contrib project, | ||
contribute code, or help shape observability for AI as it continues to evolve. | ||
|
||
We now have contributors from [Amazon](https://aws.amazon.com/), | ||
[Elastic](https://www.elastic.co/), [Google](https://www.google.com/), | ||
[IBM](https://www.ibm.com), [Langtrace](https://www.langtrace.ai/), | ||
[Microsoft](https://www.microsoft.com/), [OpenLIT](https://openlit.io/), | ||
[Scorecard](https://www.scorecard.io/), [Traceloop](https://www.traceloop.com/), | ||
and more! | ||
|
||
You are welcome to join the community! More information can be found at the | ||
[Generative AI Observability project page](https://github.com/open-telemetry/community/blob/main/projects/gen-ai.md). | ||
drewby marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting this comment here to keep an eye on setting the date right when we finally publish. Do not resolve.