Skip to content

Commit 44f5081

Browse files
committed
Fill out rest of the zero-code example.
1 parent 65241b0 commit 44f5081

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

instrumentation-genai/opentelemetry-instrumentation-google-genai/examples/zero-code/.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414

1515

16-
# Uncomment and change to your OTLP endpoint
17-
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
18-
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc
16+
# Update to change exporter configuration as desired.
17+
# See: https://opentelemetry.io/docs/zero-code/python/configuration/
18+
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
19+
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
1920

2021
# Uncomment to change parameters used to configure 'google.genai'
2122
# GOOGLE_GENAI_USE_VERTEXAI=1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
OpenTelemetry Google GenAI SDK Manual Instrumentation Example
2+
============================================
3+
4+
This is an example of how to instrument Google GenAI SDK calls with zero code changes,
5+
using `opentelemetryh-instrument`.
6+
7+
When `main.py <main.py>`_ is run, it exports traces, logs, and metrics to an OTLP
8+
compatible endpoint. Traces include details such as the model used and the
9+
duration of the chat request. Logs capture the chat request and the generated
10+
response, providing a comprehensive view of the performance and behavior of
11+
your GenAI SDK requests. Metrics include aggregate statistics such as the aggregate
12+
token usage as well as the latency distribution of the GenAI operations.
13+
14+
Note: `.env <.env>`_ file configures additional environment variables:
15+
16+
- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures
17+
Google GenAI SDK instrumentation to capture prompt and completion contents on
18+
events.
19+
20+
Setup
21+
-----
22+
23+
An OTLP compatible endpoint should be listening for traces, logs, and metrics on
24+
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.
25+
26+
Next, set up a virtual environment like this:
27+
28+
::
29+
30+
python3 -m venv .venv
31+
source .venv/bin/activate
32+
pip install "python-dotenv[cli]"
33+
pip install -r requirements.txt
34+
opentelemetry-bootstrap -a install
35+
36+
37+
Run
38+
---
39+
40+
Run the example like this:
41+
42+
::
43+
44+
export PROMPT="Your prompt here"
45+
dotenv run -- opentelemetry-instrument python main.py
46+

instrumentation-genai/opentelemetry-instrumentation-google-genai/examples/zero-code/requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
google-genai
16+
opentelemetry-api
17+
opentelemetry-sdk
18+
opentelemetry-exporter-otlp-proto-grpc
19+
opentelemetry-instrumentation
20+
opentelemetry-instrumentation-requests
21+
opentelemetry-instrumentation-google-genai
22+
opentelemetry-contrib-instrumentations
23+
opentelemetry-distro[otlp]

0 commit comments

Comments
 (0)