Skip to content

Commit f0154ea

Browse files
committed
Load dotenv in OpenAI Agents examples
1 parent 1d78868 commit f0154ea

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/manual/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ are applied:
3333

3434
dotenv run -- python main.py
3535

36+
The script automatically loads environment variables from ``.env`` so running
37+
``python main.py`` directly also works if the shell already has the required
38+
values exported.
39+
3640
You should see the agent response printed to the console while spans export to
3741
your configured observability backend.

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/manual/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
from agents import Agent, Runner, function_tool
7+
from dotenv import load_dotenv
78

89
from opentelemetry import trace
910
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
@@ -55,6 +56,7 @@ def run_agent() -> None:
5556

5657

5758
def main() -> None:
59+
load_dotenv()
5860
configure_otel()
5961
run_agent()
6062

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/manual/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
openai-agents~=0.3.3
2+
python-dotenv~=1.0
23

34
opentelemetry-sdk~=1.36.0
45
opentelemetry-exporter-otlp-proto-grpc~=1.36.0

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/zero-code/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ instrumentation is activated automatically:
3333

3434
dotenv run -- opentelemetry-instrument python main.py
3535

36+
Because ``main.py`` invokes ``load_dotenv``, running ``python main.py`` directly
37+
also works when the required environment variables are already exported.
38+
3639
You should see the agent response printed to the console while spans export to
3740
your observability backend.

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/zero-code/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from agents import Agent, Runner, function_tool
6+
from dotenv import load_dotenv
67

78

89
@function_tool
@@ -32,6 +33,7 @@ def run_agent() -> None:
3233

3334

3435
def main() -> None:
36+
load_dotenv()
3537
run_agent()
3638

3739

instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/zero-code/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
openai-agents~=0.3.3
2+
python-dotenv~=1.0
23

34
opentelemetry-sdk~=1.36.0
45
opentelemetry-exporter-otlp-proto-grpc~=1.36.0

0 commit comments

Comments
 (0)