Skip to content

Commit

Permalink
use grpc endpoint in openai samples, add extra env vars to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Nov 22, 2024
1 parent 48f0b38 commit b442f8f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ OPENAI_API_KEY=sk-YOUR_API_KEY
# OPENAI_API_KEY=unused
# CHAT_MODEL=qwen2.5:0.5b

# Uncomment and change to your OTLP endpoint
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
# OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
# Uncomment and change to your OTLP endpoint and/or
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_SERVICE_NAME=opentelemetry-python-openai

# Change to 'false' to hide prompt and completion content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ 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_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures
OpenAI instrumentation to capture prompt and completion contents on
events.

Setup
-----

Minimally, update the `.env <.env>`_ file with your "OPENAI_API_KEY". An
OTLP compatible endpoint should be listening for traces and logs on
http://localhost:4318. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.

Next, set up a virtual environment like this:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
openai~=1.54.4

opentelemetry-sdk~=1.28.2
opentelemetry-exporter-otlp-proto-http~=1.28.2
opentelemetry-exporter-otlp-proto-grpc~=1.28.2
opentelemetry-instrumentation-openai-v2~=2.0b0
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ OPENAI_API_KEY=sk-YOUR_API_KEY
# OPENAI_API_KEY=unused
# CHAT_MODEL=qwen2.5:0.5b

OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
# Uncomment and change to your OTLP endpoint and/or
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc

OTEL_SERVICE_NAME=opentelemetry-python-openai

# Change to 'false' to disable logging
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
# Change to 'console' if your OTLP endpoint doesn't support logs
OTEL_LOGS_EXPORTER=otlp_proto_http
OTEL_LOGS_EXPORTER=otlp
# Change to 'false' to hide prompt and completion content
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ 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_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true` configures
OpenTelemetry SDK to export logs and events.
- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures
OpenAI instrumentation to capture prompt and completion contents on
events.
- `OTEL_LOGS_EXPORTER=otlp` to specify exporter type.

Setup
-----

Minimally, update the `.env <.env>`_ file with your "OPENAI_API_KEY". An
OTLP compatible endpoint should be listening for traces and logs on
http://localhost:4318. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.

Next, set up a virtual environment like this:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openai~=1.54.4

opentelemetry-sdk~=1.28.2
opentelemetry-exporter-otlp-proto-http~=1.28.2
opentelemetry-exporter-otlp-proto-grpc~=1.28.2
opentelemetry-distro~=0.49b2
opentelemetry-instrumentation-openai-v2~=2.0b0
2 changes: 2 additions & 0 deletions opentelemetry-distro/src/opentelemetry/distro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from opentelemetry.environment_variables import (
OTEL_METRICS_EXPORTER,
OTEL_TRACES_EXPORTER,
OTEL_LOGS_EXPORTER
)
from opentelemetry.instrumentation.distro import BaseDistro
from opentelemetry.sdk._configuration import _OTelSDKConfigurator
Expand All @@ -37,4 +38,5 @@ class OpenTelemetryDistro(BaseDistro):
def _configure(self, **kwargs):
os.environ.setdefault(OTEL_TRACES_EXPORTER, "otlp")
os.environ.setdefault(OTEL_METRICS_EXPORTER, "otlp")
os.environ.setdefault(OTEL_LOGS_EXPORTER, "otlp")
os.environ.setdefault(OTEL_EXPORTER_OTLP_PROTOCOL, "grpc")

0 comments on commit b442f8f

Please sign in to comment.