エンドポイント の詳細
- Path:
/otel/v1/traces - Method:
POST - Content-Type:
application/x-protobuf - Base URL: OTelトレースエンドポイントのベースURLは、W&Bのデプロイタイプによって異なります。
- Multi-tenant Cloud:
https://trace.wandb.ai/otel/v1/traces. - 専用クラウドおよびセルフマネージドのインスタンス:
https://<your-subdomain>.wandb.io/traces/otel/v1/traces.
<your-subdomain> は、組織固有のW&Bドメイン (例: acme.wandb.io) に置き換えてください。
認証とルーティング
wandb-api-key ヘッダーを使用し、スパンを適切な エンティティ と project にルーティングするために TracerProvider のリソース属性を使用します。wandb-api-key ヘッダーに W&B APIキーを渡し、続けて次のキーを TracerProvider クラスの OpenTelemetry リソース属性として指定します。
wandb.entity: W&B のチーム名またはユーザー名。wandb.project: トレースの送信先となるプロジェクト名。
例
WANDB_API_KEY: これは User Settings から取得できます。- Entity: トレースをログできるのは、アクセス権のあるチーム / エンティティ配下の project のみです。エンティティ名を確認するには、W&B ダッシュボード にアクセスし、左サイドバーの Teams フィールドを確認してください。
- Project name: プロジェクト名を選択してください。
OPENAI_API_KEY: これは OpenAI dashboard から取得できます。
OpenInference インストルメンテーション
- Python
- TypeScript
- Python
- TypeScript
openinference_example.py などの Python ファイルに、以下のコードを貼り付けます。OpenLLMetry インストルメンテーション
- Python
- TypeScript
- Python
- TypeScript
次のコードを、コードを実行します。
openllmetry_example.py などの Python ファイルに貼り付けてください。上記のコードと同じですが、OpenAIInstrumentor は openinference.instrumentation.openai ではなく opentelemetry.instrumentation.openai から import しています。インストルメンテーションを使用しない場合
- Python
- TypeScript
- Python
- TypeScript
次のコードを、コードを実行します。
opentelemetry_example.py などの Python ファイルに貼り付けてください。gen_ai と openinference を使用します。どちらのキーも検出されない場合は、すべての スパン属性が Trace view に表示されます。トレースを選択すると、サイドパネルで スパン全体を確認できます。
OpenTelemetry Collector を使用する
collector を設定する
- OTLP トレースを受信し、バッチ処理して Weave に転送するローカルサーバー (collector) をデプロイする Docker の設定ファイルを設定する。
- Docker を使用して、collector をローカルで実行する。
- Docker コンテナー内で実行中の collector にトレースを転送する、OpenAI への基本的な call を送信する。
collector-config.yaml ファイルを作成します。
collector-config.yaml
- ポート
4318(HTTP) で OTLP トレースを受信します。 wandb-api-keyヘッダーを使ってトレースを Weave の OTLP エンドポイントにエクスポートします。エンドポイント URL はWANDB_OTLP_ENDPOINTから、APIキーはWANDB_API_KEYから読み取ります。resourceプロセッサを使用してwandb.entityとwandb.projectをリソース属性として設定します。値はDEFAULT_WANDB_ENTITYとDEFAULT_WANDB_PROJECTから読み取ります。insertaction は、アプリケーションコードですでにこれらの属性を設定していない場合にのみ、これらの属性を追加します。- ネットワーク負荷を減らすため、バッチ処理とともにエクスポーター組み込みの
sending_queueを有効にします。
OTEL_EXPORTER_OTLP_ENDPOINT 環境変数を設定して、アプリケーションがそこにトレースをエクスポートするように構成します。OTel SDK はこの変数を自動的に読み取るため、exporter にエンドポイントを渡す必要はありません。
アプリケーションの TracerProvider で wandb.entity または wandb.project をリソース属性として設定すると、それらは collector の設定で定義されたデフォルトよりも優先されます。
OpenAIInstrumentor は OpenAI の Call をラップし、トレースを作成して collector にエクスポートします。collector は認証と Weave へのルーティングを処理します。
スクリプトの実行後、Weave UI でトレースを表示できます。
トレースを追加のバックエンドに送信するには、エクスポーターを追加し、それらを service.pipelines.traces.exporters リストに含めます。たとえば、同じ Collector インスタンスから Weave と Jaeger の両方にエクスポートできます。
OTel トレースをスレッドに整理する
wandb.thread_id: スパンを特定のスレッドにグループ化します。wandb.is_turn: スパンを会話のターンとしてマークします (スレッドビューでは行として表示されます) 。
wandb.thread_id を使用して関連する操作をグループ化し、wandb.is_turn を使用してスレッドビューで行として表示される高レベルの操作をマークします。
初期設定
初期設定
これらの例を実行するには、この設定を使用します。
- Python
- TypeScript
基本的な単一ターンのスレッドをトレースする
基本的な単一ターンのスレッドをトレースする
- Python
- TypeScript
同じ thread ID を共有する複数ターンの会話をトレースする
同じ thread ID を共有する複数ターンの会話をトレースする
- Python
- TypeScript
深くネストされた処理をトレースし、最も外側の span のみをターンとしてマークする
深くネストされた処理をトレースし、最も外側の span のみをターンとしてマークする
- Python
- TypeScript
スレッドに属しているもののターンではないバックグラウンド処理をトレースする
スレッドに属しているもののターンではないバックグラウンド処理をトレースする
- Python
- TypeScript
thread_id ごとにグループ化され、各ターンは個別の行として表示されます。
属性マッピング
対応フレームワーク
- OpenTelemetry GenAI: 生成 AI 向けの標準セマンティック規約 (
gen_ai.*)。 - OpenInference: Arize AI のインストルメンテーションライブラリ (
input.value,output.value,llm.*,openinference.*)。 - Vercel AI SDK: Vercel の AI SDK 属性 (
ai.prompt,ai.response,ai.model.*,ai.usage.*)。 - MLflow: MLflow のトラッキング属性 (
mlflow.spanInputs,mlflow.spanOutputs)。 - Traceloop: OpenLLMetry のインストルメンテーション (
traceloop.entity.*,traceloop.span.kind)。 - Google Vertex AI: Vertex AI のエージェント属性 (
gcp.vertex.agent.*)。 - OpenLit: OpenLit のオブザーバビリティ属性 (
gen_ai.content.completion)。 - Langfuse: Langfuse のトレース属性 (
langfuse.startTime,langfuse.endTime)。
属性のリファレンス
| 属性フィールド名 | W&B マッピング | 説明 | タイプ | 例 |
|---|---|---|---|---|
ai.prompt | inputs | ユーザーのプロンプトのテキストまたはメッセージ。 | 文字列、list、dict | "夏について短い俳句を書いて。" |
gen_ai.prompt | inputs | AIモデルへのプロンプト、またはメッセージの配列。 | list、dict、文字列 | [{"role":"user","content":"abc"}] |
input.value | inputs | モデル呼び出し時の入力値。 | 文字列、list、dict | {"text":"ジョークを言って"} |
mlflow.spanInputs | inputs | スパンの入力データ。 | 文字列、list、dict | ["プロンプトテキスト"] |
traceloop.entity.input | inputs | entityの入力データ。 | String、list、dict | "これをフランス語に翻訳して" |
gcp.vertex.agent.tool_call_args | inputs | ツールcallの引数。 | dict | {"args":{"query":"weather in SF"}} |
gcp.vertex.agent.llm_request | inputs | LLMリクエストのペイロード。 | Dict | {"contents":[{"role":"user","parts":[...]}]} |
input | inputs | 汎用的な入力値。 | String, list, dict | "このテキストを要約して" |
inputs | inputs | 汎用的な入力配列。 | List, dict, string | ["このテキストを要約してください"] |
ai.response | outputs | モデルの応答テキストまたはデータ。 | String、list、dict | "俳句をどうぞ..." |
gen_ai.completion | outputs | AIの補完結果。 | String、list、dict | "補完テキスト" |
output.value | outputs | モデルの出力値。 | String、list、dict | {"text":"回答テキスト"} |
mlflow.spanOutputs | outputs | スパンの出力データ。 | String、list、dict | ["answer"] |
gen_ai.content.completion | outputs | コンテンツ補完の結果。 | String | "回答テキスト" |
traceloop.entity.output | outputs | entityの出力データ。 | String、list、dict | "回答テキスト" |
gcp.vertex.agent.tool_response | outputs | ツール実行のレスポンス。 | dict、文字列 | {"toolResponse":"ok"} |
gcp.vertex.agent.llm_response | outputs | LLMのレスポンスペイロード。 | dict、文字列 | {"candidates":[...]} |
output | outputs | 汎用的な出力値。 | 文字列、list、dict | "回答テキスト" |
outputs | outputs | 汎用的な出力配列。 | list、dict、string | ["回答テキスト"] |
gen_ai.usage.input_tokens | usage.input_tokens | 消費された入力トークン数。 | Int | 42 |
gen_ai.usage.prompt_tokens | usage.prompt_tokens | 消費されたプロンプトトークン数。 | Int | 30 |
llm.token_count.prompt | usage.prompt_tokens | プロンプトのトークン数。 | Int | 30 |
ai.usage.promptTokens | usage.prompt_tokens | 消費されたプロンプトトークン数。 | Int | 30 |
gen_ai.usage.completion_tokens | usage.completion_tokens | 生成された補完トークン数。 | Int | 40 |
llm.token_count.completion | usage.completion_tokens | 補完トークン数。 | Int | 40 |
ai.usage.completionTokens | usage.completion_tokens | 生成された補完トークン数。 | Int | 40 |
llm.usage.total_tokens | usage.total_tokens | リクエストで使用されたトークンの合計数。 | Int | 70 |
llm.token_count.total | usage.total_tokens | トークンの総数。 | Int | 70 |
gen_ai.system | attributes.system | system prompt または指示。 | String | "あなたは役に立つアシスタントです。" |
llm.system | attributes.system | system prompt または指示。 | String | "あなたは役立つアシスタントです。" |
weave.span.kind | attributes.kind | Span のタイプまたはカテゴリ。 | String | "llm" |
traceloop.span.kind | attributes.kind | スパンのタイプまたはカテゴリ。 | 文字列 | "llm" |
openinference.span.kind | attributes.kind | スパンのタイプまたはカテゴリ。 | 文字列 | "llm" |
gen_ai.response.model | attributes.model | モデル識別子。 | 文字列 | "gpt-4o" |
llm.model_name | attributes.model | モデル識別子。 | 文字列 | "gpt-4o-mini" |
ai.model.id | attributes.model | モデル識別子。 | 文字列 | "gpt-4o" |
llm.provider | attributes.provider | モデルプロバイダ名。 | 文字列 | "openai" |
ai.model.provider | attributes.provider | モデルプロバイダ名。 | 文字列 | "openai" |
gen_ai.request | attributes.model_parameters | モデル生成のパラメーター。 | dict | {"temperature":0.7,"max_tokens":256} |
llm.invocation_parameters | attributes.model_parameters | モデル呼び出し時のパラメーター。 | dict | {"temperature":0.2} |
wandb.display_name | display_name | UI 用のカスタム表示名。 | 文字列 | "ユーザーメッセージ" |
gcp.vertex.agent.session_id | thread_id | セッションまたはスレッドの識別子。 | 文字列 | "thread_123" |
wandb.thread_id | thread_id | 会話のスレッド識別子。 | 文字列 | "thread_123" |
wb_run_id | wb_run_id | 関連する W&B run の識別子。 | 文字列 | "abc123" |
wandb.wb_run_id | wb_run_id | 関連付けられた W&B run の識別子。 | 文字列 | "abc123" |
gcp.vertex.agent.session_id | is_turn | スパンが会話のターンであることを示します。 | ブール値 | true |
wandb.is_turn | is_turn | スパンが会話のターンであることを示します。 | 真偽値 | true |
langfuse.startTime | start_time (上書き) | スパンの開始タイムスタンプを上書きします。 | タイムスタンプ (ISO8601/Unix ns) | "2024-01-01T12:00:00Z" |
langfuse.endTime | end_time (上書き) | スパンの終了タイムスタンプを上書きします。 | タイムスタンプ (ISO8601/Unix ns) | "2024-01-01T12:00:01Z" |