Supported OS Linux Windows Mac OS

概要

Datadog のメトリクス、APM、ログを使用して、OpenAI アカウントレベル、Python および Node.js ライブラリのリクエストから、コストの見積もり、プロンプトとコンプリーションのサンプリング、エラー追跡、パフォーマンスメトリクスなどを取得します。

セットアップ

Note: This setup method does not collect openai.api.usage.* metrics. To collect these metrics, also follow the API key setup instructions.

インストール

Web: Get Account-level Usage and Cost Metrics

Note: This setup method only collects openai.api.usage* metrics, and if you enable OpenAI in Cloud Cost Management, you will also get cost metrics, no additional permissions or setup required. Use the agent setup below for additional metrics.

  1. Login to your OpenAI Account.
  2. アカウント設定の View API Keys に移動します。
  3. Create a new secret key ボタンをクリックします。
  4. 作成した API キーをクリップボードにコピーします。
  5. Navigate to the configuration tab inside Datadog OpenAI integration tile.
  6. アカウント構成に、上記でコピーしたアカウント名と OpenAI API キーを入力します。
  7. If you use Cloud Cost Management and enable collecting cost data, it will be visible in Cloud Cost Management within 24 hours. (collected data)

APM: Get Usage Metrics for Python and Node.js Applications

  1. Datadog Agent で APM と StatsD を有効化します。例えば、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
  1. Datadog APM Python ライブラリをインストールします。
pip install ddtrace
  1. Prefix your OpenAI Python application command with ddtrace-run and the following environment variables as shown below:
DD_SERVICE="my-service" DD_ENV="staging" ddtrace-run python <your-app>.py

:

  • Non-US1 customers must set DD_SITE on the application command to the correct Datadog site parameter as specified in the table in the Datadog Site page (for example, datadoghq.eu for EU1 customers).

  • 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.

構成

See the APM Python library documentation for all the available configuration options.

ログプロンプトとコンプリーションサンプリング

To enable log prompt and completion sampling, set the DD_OPENAI_LOGS_ENABLED="true" 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.

: ログを送信するには、ddtrace-run を実行する際に DD_API_KEY を指定する必要があります。

検証

APM Python ライブラリを使用して Agent と通信できることを確認します。

ddtrace-run --info

次の出力が表示されるはずです。

    Agent error: None

デバッグロギング

ddtrace-run--debug フラグを渡すと、デバッグロギングが有効になります。

ddtrace-run --debug

データ送信時のエラーを表示します。

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'

Note: This setup method does not collect openai.api.usage.* metrics. To collect these metrics, also follow the API key setup instructions.

インストール

  1. Datadog Agent で APM と StatsD を有効化します。例えば、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
  1. Datadog APM Node.js ライブラリをインストールします。
npm install dd-trace
  1. ライブラリを OpenAI Node.js アプリケーションに挿入します。
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

: Agent がデフォルト以外のホスト名やポートを使用している場合、DD_AGENT_HOSTDD_TRACE_AGENT_PORTDD_DOGSTATSD_PORT も設定する必要があります。

より高度な使い方については、APM Node.js OpenAI のドキュメントを参照してください。

構成

利用可能なすべての構成オプションについては、APM Node.js ライブラリドキュメントを参照してください。

ログプロンプトとコンプリーションサンプリング

ログのプロンプトとコンプリーションサンプリングを有効にするには、環境変数 DD_OPENAI_LOGS_ENABLED=1 を設定します。デフォルトでは、トレースされたリクエストの 10% がプロンプトとコンプリーションを含むログを出力します。

ログのサンプルレートを調整するには、APM ライブラリのドキュメントを参照してください。

: ログを送信するには、DD_API_KEY を指定する必要があります。

検証

APM Node.js ライブラリが Agent と通信できることを、アプリケーションプロセスのデバッグ出力で確認します。“Encoding payload” というタイトルのセクションに、name フィールドと関連する値として openai.request というエントリがあるはずです。この出力の例を以下に示します。

{
  "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"
}

Note: This setup method only collects openai.api.usage.* metrics. To collect all metrics provided by this integration, also follow the APM setup instructions.

インストール

  1. Login to your OpenAI Account.
  2. アカウント設定の View API Keys に移動します。
  3. Click Create a new secret key.
  4. 作成した API キーをクリップボードにコピーします。

構成

  1. Navigate to the configuration tab inside Datadog OpenAI integration tile.
  2. アカウント構成に、上記でコピーしたアカウント名と OpenAI API キーを入力します。

収集データ

メトリクス

openai.api.usage.n_context_tokens_total
(gauge)
Total number of context tokens used (all-time)
Shown as token
openai.api.usage.n_generated_tokens_total
(gauge)
Total number of generated response tokens (all-time)
Shown as token
openai.api.usage.n_requests
(count)
Total number of requests
Shown as request
openai.organization.ratelimit.requests.remaining
(gauge)
Number of requests remaining in the rate limit.
Shown as request
openai.organization.ratelimit.tokens.remaining
(gauge)
Number of tokens remaining in the rate limit.
Shown as token
openai.ratelimit.requests
(gauge)
Number of requests in the rate limit.
Shown as request
openai.ratelimit.tokens
(gauge)
Number of tokens in the rate limit.
Shown as token
openai.request.duration
(gauge)
Request duration distribution.
Shown as nanosecond
openai.request.error
(count)
Number of errors.
Shown as error
openai.tokens.completion
(gauge)
Number of tokens used in the completion of a response from OpenAI.
Shown as token
openai.tokens.prompt
(gauge)
Number of tokens used in the prompt of a request to OpenAI.
Shown as token
openai.tokens.total
(gauge)
Total number of tokens used in a request to OpenAI.
Shown as token

イベント

OpenAI インテグレーションには、イベントは含まれません。

サービスチェック

OpenAI インテグレーションには、サービスのチェック機能は含まれません。

トラブルシューティング

ご不明な点は、Datadog のサポートチームまでお問合せください。

その他の参考資料

お役に立つドキュメント、リンクや記事:

PREVIEWING: alai97/reorganize-some-sections-in-dora-metrics