> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-workspaces-notebooks.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# instrumentOpenAIAgents

> TypeScript SDK リファレンス

export const GitHubLink = ({url, compact = false}) => <a href={url} target="_blank" rel="noopener noreferrer" className={compact ? "source-link" : "github-source-link"}>
    {compact ? "ソースを表示" : <>
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub のソース
      </>}
  </a>;

```ts theme={null}
instrumentOpenAIAgents(): Promise<boolean>
```

<GitHubLink url="https://github.com/wandb/weave/blob/7c9efdc9fe05ffcaf2430dd652ef9bc5b3ffdfaa/sdks/node/src/integrations/openai.agent.ts#L169" />

パッケージが利用可能な場合、OpenAI Agents に Weave のトレースを手動で登録します。

**注: 通常、この関数を呼び出す必要はありません。** Weave を import すると、OpenAI Agents はモジュールローダーフックを通じて自動的にインストルメントされます。この関数は、自動インストルメンテーションが機能しないエッジケース (例: 動的 import や、フックをバイパスするバンドラー) のために用意されています。

この関数は、利用側の node\_modules から @openai/agents を動的に import し、TracingProcessor の登録を試みます。パッケージがインストールされていない場合は、エラーをスローせずに false を返します。

<div id="returns">
  ## 戻り値
</div>

`Promise`\<`boolean`>

`Promise<boolean>` - 登録に成功した場合は `true`、`@openai/agents` を利用できない場合は `false`

<div id="examples">
  ## 例
</div>

```typescript twoslash theme={null}
// @noErrors
// ✅ 推奨: Weave を import するだけで、インストルメンテーションが自動的に行われます！
import * as weave from 'weave';
await weave.init('my-project');

// OpenAI Agents はフック経由でインストルメントされるため、手動での setup は不要です
import { Agent } from '@openai/agents';
const agent = new Agent({ ... });
await agent.run(input); // Weave で自動的にトレースされます
```

```typescript twoslash theme={null}
// @noErrors
// ⚠️ 自動フックが機能しないエッジケースでのみ必要
import { instrumentOpenAIAgents } from 'weave';

const registered = await instrumentOpenAIAgents();
if (!registered) {
  console.log('OpenAI Agents not found - install @openai/agents to enable tracing');
}
```

<div id="remarks">
  ## 備考
</div>

**自動インストルメンテーションの仕組み**: Weave を import すると、`addCJSInstrumentation()` と `addESMInstrumentation()` を通じてモジュールローダーフックが登録されます。その後、コードで `@openai/agents` を import すると、これらのフックが import を捕捉し、Weave のトレースを追加するためのパッチをモジュールに自動的に適用します。これは透過的に行われるため、特別な対応は不要です。

**この関数を使用するタイミング**: 自動インストルメンテーションが機能しない場合にのみ使用してください。たとえば、次のようなケースです。

* モジュールフックをバイパスする動的 import を使用している
* import-in-the-middle をサポートしていないバンドラーを使用している
* インストルメンテーションを実行するタイミングを明示的に制御する必要がある

**カスタム processor ロジックの代替手段**: カスタムのトレース動作が必要な場合は、
`createOpenAIAgentsTracingProcessor()` を使用して手動で登録してください：

```typescript twoslash theme={null}
// @noErrors
import { addTraceProcessor } from '@openai/agents';
import { createOpenAIAgentsTracingProcessor } from 'weave';

const processor = createOpenAIAgentsTracingProcessor();
addTraceProcessor(processor);
```
