Installation
- Enable APM and StatsD in your Datadog Agent. For example, in Docker:
docker run -d
--cgroupns host \
--pid host \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-e DD_API_KEY=<DATADOG_API_KEY> \
-p 127.0.0.1:8126:8126/tcp \
-p 127.0.0.1:8125:8125/udp \
-e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
-e DD_APM_ENABLED=true \
gcr.io/datadoghq/agent:latest
- Install the Datadog APM Python library.
pip install ddtrace>=1.13
- Prefix your OpenAI Python application command with
ddtrace-run
.
DD_SERVICE="my-service" DD_ENV="staging" DD_API_KEY=<DATADOG_API_KEY> ddtrace-run python <your-app>.py
Note: If the Agent is using a non-default hostname or port, be sure to also set DD_AGENT_HOST
, DD_TRACE_AGENT_PORT
, or DD_DOGSTATSD_PORT
.
See the APM Python library documentation for more advanced usage.
Configuration
See the APM Python library documentation for all the available configuration options.
Log Prompt & Completion Sampling
To enable log prompt and completion sampling, set the DD_OPENAI_LOGS_ENABLED=1
environment variable. By default, 10% of traced requests will emit logs containing the prompts and completions.
To adjust the log sample rate, see the APM library documentation.
Note: Logs submission requires DD_API_KEY
to be specified when running ddtrace-run
.
Validation
Validate that the APM Python library can communicate with your Agent using:
You should see the following output:
Debug Logging
Pass the --debug
flag to ddtrace-run
to enable debug logging.
This displays any errors sending data:
ERROR:ddtrace.internal.writer.writer:failed to send, dropping 1 traces to intake at http://localhost:8126/v0.5/traces after 3 retries ([Errno 61] Connection refused)
WARNING:ddtrace.vendor.dogstatsd:Error submitting packet: [Errno 61] Connection refused, dropping the packet and closing the socket
DEBUG:ddtrace.contrib.openai._logging.py:sent 2 logs to 'http-intake.logs.datadoghq.com'
Installation
- Enable APM and StatsD in your Datadog Agent. For example, in Docker:
docker run -d
--cgroupns host \
--pid host \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-e DD_API_KEY=<DATADOG_API_KEY> \
-p 127.0.0.1:8126:8126/tcp \
-p 127.0.0.1:8125:8125/udp \
-e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
-e DD_APM_ENABLED=true \
gcr.io/datadoghq/agent:latest
- Install the Datadog APM Node.js library.
- Inject the library into your OpenAI Node.js application.
DD_TRACE_DEBUG=1 DD_TRACE_BEAUTIFUL_LOGS=1 DD_SERVICE="my-service" \
DD_ENV="staging" DD_API_KEY=<DATADOG_API_KEY> \
NODE_OPTIONS='-r dd-trace/init' node app.js
Note: If the Agent is using a non-default hostname or port, you must also set DD_AGENT_HOST
, DD_TRACE_AGENT_PORT
, or DD_DOGSTATSD_PORT
.
See the [APM Node.js OpenAI documentation][1] for more advanced usage.
Configuration
See the [APM Node.js library documentation][2] for all the available configuration options.
Log prompt and completion sampling
To enable log prompt and completion sampling, set the DD_OPENAI_LOGS_ENABLED=1
environment variable. By default, 10% of traced requests emit logs containing the prompts and completions.
To adjust the log sample rate, see the [APM library documentation][3].
Note: Logs submission requires DD_API_KEY
to be specified.
Validation
Validate that the APM Node.js library can communicate with your Agent by examining the debugging output from the application process. Within the section titled “Encoding payload,” you should see an entry with a name
field and a correlating value of openai.request
. See below for a truncated example of this output:
{
"name": "openai.request",
"resource": "listModels",
"meta": {
"component": "openai",
"span.kind": "client",
"openai.api_base": "https://api.openai.com/v1",
"openai.request.endpoint": "/v1/models",
"openai.request.method": "GET",
"language": "javascript"
},
"metrics": {
"openai.response.count": 106
},
"service": "my-service",
"type": "openai"
}
Installation
- Login to your OpenAI Account.
- Navigate to View API Keys under account settings.
- Click the Create a new secret key button.
- Copy the created API Key to your clipboard.
Configuration
- Navigate to the configuration tab inside Datadog OpenAI integration tile.
- Enter an account name and OpenAI API key copied above in the accounts configuration.