|
2 | 2 |
|
3 | 3 | <!-- TODO: link to devsite doc once it is published --> |
4 | 4 |
|
5 | | -This sample is an ADK agent instrumented with OpenTelemetry to send traces and logs with GenAI |
6 | | -prompts and responses, and metrics to Google Cloud Observability. |
| 5 | +This demo shows does remote uploading and with `.ref` attributes in the telemetry, following OTel semconv 1.37 for GenAI: https://github.com/open-telemetry/semantic-conventions/blob/v1.37.0/docs/gen-ai/gen-ai-events.md |
7 | 6 |
|
8 | | -The Agent is a SQL expert that has full access to an ephemeral SQLite database. The database is |
9 | | -initially empty. |
| 7 | +## Configure upload |
| 8 | +This demo uses the [fsspec](https://filesystem-spec.readthedocs.io/) library to do the upload |
| 9 | +in a vendor agnostic way, which is configured in an environment variable |
| 10 | +`OTEL_PYTHON_GENAI_UPLOADER_PATH`. For example, to upload to GCS bucket `my-bucket` with |
| 11 | +subdirectory `v1/`: |
10 | 12 |
|
11 | | -## APIs and Permissions |
12 | | - |
13 | | -Enable the relevant Cloud Observability APIs if they aren't already enabled. |
14 | | -```sh |
15 | | -gcloud services enable telemetry.googleapis.com logging.googleapis.com monitoring.googleapis.com cloudtrace.googleapis.com |
| 13 | +```console |
| 14 | +export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://my-bucket/v1" |
16 | 15 | ``` |
17 | 16 |
|
18 | | -This sample writes to Cloud Logging, Cloud Monitoring, and Cloud Trace. Grant yourself the |
19 | | -following roles to run the example: |
20 | | -- `roles/logging.logWriter` – see https://cloud.google.com/logging/docs/access-control#permissions_and_roles |
21 | | -- `roles/monitoring.metricWriter` – see https://cloud.google.com/monitoring/access-control#predefined_roles |
22 | | -- `roles/telemetry.writer` – see https://cloud.google.com/trace/docs/iam#telemetry-roles |
23 | | - |
24 | | -## Running the example |
| 17 | +This will work with any installed fsspec implementations and also allows using any fsspec |
| 18 | +configuration like URL Chaining: |
| 19 | +- [Built in implementations](https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations) |
| 20 | +- [Known third party impls](https://filesystem-spec.readthedocs.io/en/latest/api.html#external-implementations) |
| 21 | +- [URL Chaining](https://filesystem-spec.readthedocs.io/en/latest/features.html#url-chaining) |
25 | 22 |
|
26 | | -The sample can easily be run in Cloud Shell. You can also use |
27 | | -[Application Default Credentials][ADC] locally. Clone and set environment variables: |
28 | | -```sh |
29 | | -git clone https://github.com/GoogleCloudPlatform/opentelemetry-operations-python.git |
30 | | -cd opentelemetry-operations-python/samples/adk-sql-agent |
| 23 | +## Run the demo |
31 | 24 |
|
32 | | -# Capture GenAI prompts and responses |
33 | | -export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true |
34 | | -# Capture application logs automatically |
35 | | -export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true |
36 | | -``` |
| 25 | +To run the app, set some environment variables (alternatively can be put in `main.env`): |
37 | 26 |
|
38 | | -Create a virtual environment and run the sample: |
39 | | -```sh |
40 | | -python -m venv venv/ |
41 | | -source venv/bin/activate |
42 | | -pip install -r requirements.txt |
43 | | -python main.py |
44 | | -``` |
| 27 | +```console |
| 28 | +# Port if not default |
| 29 | +export PORT=8000 |
| 30 | +# Project for ADC |
| 31 | +export GOOGLE_CLOUD_PROJECT=my-project |
45 | 32 |
|
46 | | -Alternatively if you have [`uv`](https://docs.astral.sh/uv/) installed: |
| 33 | +# Configure the upload path |
| 34 | +export OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://${GOOGLE_CLOUD_PROJECT}/v1" |
47 | 35 |
|
48 | | -```sh |
49 | | -uv run main.py |
| 36 | +uv run --env-file main.env main.py |
50 | 37 | ``` |
51 | 38 |
|
52 | | -## Viewing the results |
| 39 | +## Dockerfile |
53 | 40 |
|
54 | | -To view the generated traces with [Generative AI |
55 | | -events](https://cloud.google.com/trace/docs/finding-traces#view_generative_ai_events) in the |
56 | | -GCP console, use the [Trace Explorer](https://cloud.google.com/trace/docs/finding-traces). Filter for spans named `invoke agent`. |
| 41 | +Build |
57 | 42 |
|
58 | | -[ADC]: https://cloud.google.com/docs/authentication/application-default-credentials |
| 43 | +```console |
| 44 | +# from this directory, run with repo root build context |
| 45 | +docker build -f ./Dockerfile -t adk-sql-agent-write-aside .. |
| 46 | +``` |
| 47 | + |
| 48 | +Run: |
| 49 | +```console |
| 50 | +docker run --rm \ |
| 51 | + -p 8000:8000 \ |
| 52 | + -e PORT=8000 \ |
| 53 | + -e GOOGLE_APPLICATION_CREDENTIALS \ |
| 54 | + -e GOOGLE_CLOUD_PROJECT \ |
| 55 | + -e OTEL_PYTHON_GENAI_UPLOADER_PATH="gs://otel-starter-project-genai-refs/v1" \ |
| 56 | + -v "$GOOGLE_APPLICATION_CREDENTIALS:$GOOGLE_APPLICATION_CREDENTIALS" \ |
| 57 | + adk-sql-agent-write-aside:latest |
| 58 | +``` |
0 commit comments