-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...umentation/opentelemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code/.env
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,15 @@ | ||
# Update this with your real values | ||
AWS_ACCESS_KEY_ID=key | ||
AWS_SECRET_ACCESS_KEY=secret | ||
AWS_DEFAULT_REGION=eu-central-1 | ||
# Uncomment and set if your credentials are temporary | ||
# AWS_SESSION_TOKEN= | ||
|
||
# Uncomment and change to your OTLP endpoint | ||
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 | ||
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc | ||
|
||
OTEL_SERVICE_NAME=opentelemetry-python-bedrock | ||
|
||
# Uncomment if your OTLP endpoint doesn't support logs | ||
# OTEL_LOGS_EXPORTER=console |
50 changes: 50 additions & 0 deletions
50
...elemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code/README.rst
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,50 @@ | ||
Bedrock Zero-Code Instrumentation Example | ||
========================================= | ||
|
||
This is an example of how to instrument Bedrock calls with zero code changes, | ||
using `opentelemetry-instrument`. | ||
|
||
When examples are run, it exports traces and logs to an OTLP | ||
compatible endpoint. Traces include details such as the model used and the | ||
duration of the chat request. Logs capture the chat request and the generated | ||
response, providing a comprehensive view of the performance and behavior of | ||
your OpenAI requests. | ||
|
||
Note: `.env <.env>`_ file configures additional environment variables: | ||
|
||
- `OTEL_LOGS_EXPORTER=otlp` to specify exporter type. | ||
|
||
Available examples | ||
------------------ | ||
|
||
- `converse.py` uses `bedrock-runtime` `Converse API <https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html>_`. | ||
|
||
Setup | ||
----- | ||
|
||
Minimally, update the `.env <.env>`_ file with your "AWS_SECRET_ACCESS_KEY", | ||
"AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION" and if you are using temporary | ||
credentials "AWS_SESSION_TOKEN". An | ||
OTLP compatible endpoint should be listening for traces and logs on | ||
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well. | ||
|
||
Next, set up a virtual environment like this: | ||
|
||
:: | ||
|
||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
pip install "python-dotenv[cli]" | ||
pip install -r requirements.txt | ||
|
||
Run | ||
--- | ||
|
||
Run the example like this: | ||
|
||
:: | ||
|
||
dotenv run -- opentelemetry-instrument python converse.py | ||
|
||
You should see a poem generated by Bedrock while traces exported to your | ||
configured observability tool. |
22 changes: 22 additions & 0 deletions
22
...ion/opentelemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code/converse.py
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,22 @@ | ||
import os | ||
|
||
import boto3 | ||
|
||
|
||
def main(): | ||
client = boto3.client("bedrock-runtime") | ||
response = client.converse( | ||
modelId=os.getenv("CHAT_MODEL", "amazon.titan-text-lite-v1"), | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": [{"text": "Write a short poem on OpenTelemetry."}], | ||
}, | ||
], | ||
) | ||
|
||
print(response["output"]["message"]["content"][0]["text"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
6 changes: 6 additions & 0 deletions
6
...pentelemetry-instrumentation-botocore/examples/bedrock-runtime/zero-code/requirements.txt
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,6 @@ | ||
boto3~=1.35.99 | ||
|
||
opentelemetry-sdk~=1.29.0 | ||
opentelemetry-exporter-otlp-proto-grpc~=1.29.0 | ||
opentelemetry-distro~=0.50b0 | ||
opentelemetry-instrumentation-botocore~=0.50b0 |