@traceai/codex-sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -2
- package/dist/esm/attributes.d.ts +101 -0
- package/dist/esm/attributes.d.ts.map +1 -0
- package/dist/esm/attributes.js +104 -0
- package/dist/esm/attributes.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/instrumentation.d.ts +81 -0
- package/dist/esm/instrumentation.d.ts.map +1 -0
- package/dist/esm/instrumentation.js +186 -0
- package/dist/esm/instrumentation.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/spans.d.ts +152 -0
- package/dist/esm/spans.d.ts.map +1 -0
- package/dist/esm/spans.js +678 -0
- package/dist/esm/spans.js.map +1 -0
- package/dist/esm/threadWrapper.d.ts +35 -0
- package/dist/esm/threadWrapper.d.ts.map +1 -0
- package/dist/esm/threadWrapper.js +186 -0
- package/dist/esm/threadWrapper.js.map +1 -0
- package/dist/esm/types.d.ts +123 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +10 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esnext/attributes.d.ts +101 -0
- package/dist/esnext/attributes.d.ts.map +1 -0
- package/dist/esnext/attributes.js +104 -0
- package/dist/esnext/attributes.js.map +1 -0
- package/dist/esnext/index.d.ts +8 -0
- package/dist/esnext/index.d.ts.map +1 -0
- package/dist/esnext/index.js +5 -0
- package/dist/esnext/index.js.map +1 -0
- package/dist/esnext/instrumentation.d.ts +81 -0
- package/dist/esnext/instrumentation.d.ts.map +1 -0
- package/dist/esnext/instrumentation.js +191 -0
- package/dist/esnext/instrumentation.js.map +1 -0
- package/dist/esnext/spans.d.ts +152 -0
- package/dist/esnext/spans.d.ts.map +1 -0
- package/dist/esnext/spans.js +688 -0
- package/dist/esnext/spans.js.map +1 -0
- package/dist/esnext/threadWrapper.d.ts +35 -0
- package/dist/esnext/threadWrapper.d.ts.map +1 -0
- package/dist/esnext/threadWrapper.js +183 -0
- package/dist/esnext/threadWrapper.js.map +1 -0
- package/dist/esnext/types.d.ts +123 -0
- package/dist/esnext/types.d.ts.map +1 -0
- package/dist/esnext/types.js +10 -0
- package/dist/esnext/types.js.map +1 -0
- package/dist/esnext/version.d.ts +2 -0
- package/dist/esnext/version.d.ts.map +1 -0
- package/dist/esnext/version.js +2 -0
- package/dist/esnext/version.js.map +1 -0
- package/dist/src/attributes.d.ts +101 -0
- package/dist/src/attributes.d.ts.map +1 -0
- package/dist/src/attributes.js +107 -0
- package/dist/src/attributes.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/instrumentation.d.ts +81 -0
- package/dist/src/instrumentation.d.ts.map +1 -0
- package/dist/src/instrumentation.js +213 -0
- package/dist/src/instrumentation.js.map +1 -0
- package/dist/src/spans.d.ts +152 -0
- package/dist/src/spans.d.ts.map +1 -0
- package/dist/src/spans.js +698 -0
- package/dist/src/spans.js.map +1 -0
- package/dist/src/threadWrapper.d.ts +35 -0
- package/dist/src/threadWrapper.d.ts.map +1 -0
- package/dist/src/threadWrapper.js +206 -0
- package/dist/src/threadWrapper.js.map +1 -0
- package/dist/src/types.d.ts +123 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +11 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +5 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +75 -3
- package/src/attributes.ts +113 -0
- package/src/index.ts +27 -0
- package/src/instrumentation.ts +215 -0
- package/src/spans.ts +729 -0
- package/src/threadWrapper.ts +200 -0
- package/src/types.ts +113 -0
- package/src/version.ts +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,165 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @traceai/codex-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenTelemetry tracing for the [OpenAI Codex SDK](https://www.npmjs.com/package/@openai/codex-sdk) (`@openai/codex-sdk`), exported to Future AGI through `@traceai/fi-core`. Every `Thread.run()` and `Thread.runStreamed()` becomes one trace: a `codex.turn` span with one child span per thread item (shell commands, file changes, MCP tool calls, web searches, reasoning, agent messages, to-do lists, errors).
|
|
4
|
+
|
|
5
|
+
Alpha. Tested against `@openai/codex-sdk` 0.162.1 driving the real `codex` 0.162.1 binary, and against the real SDK driving a stand-in binary (`contract/`).
|
|
6
|
+
|
|
7
|
+
This is not Codex application session tracing (the `codex` TUI or IDE extension exporting through `[otel]` in `config.toml`), and not the OpenAI API instrumentation (`@traceai/openai`). The SDK runs the `codex` binary in a subprocess, so model requests made inside it are not visible to `@traceai/openai`.
|
|
8
|
+
|
|
9
|
+
| Item | Value |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Tested pin | `@openai/codex-sdk` 0.162.1 (Apache-2.0) with its bundled `@openai/codex` 0.162.1 |
|
|
12
|
+
| Peer range | `>=0.44.0 <1`. The `Thread` shape this package patches was checked on 0.44.0, 0.80.0, 0.100.0, 0.140.0 and 0.162.1 (`src/__tests__/sdkShape.test.ts` checks the installed one). The token handling below was verified on 0.162.1 only |
|
|
13
|
+
| Node | `>=18`, same as the SDK |
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @traceai/codex-sdk @traceai/fi-core @openai/codex-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Use
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import * as CodexSDK from "@openai/codex-sdk";
|
|
25
|
+
import { register, ProjectType } from "@traceai/fi-core";
|
|
26
|
+
import { CodexSDKInstrumentation, shutdown } from "@traceai/codex-sdk";
|
|
27
|
+
|
|
28
|
+
const tracerProvider = register({
|
|
29
|
+
projectType: ProjectType.OBSERVE,
|
|
30
|
+
projectName: "my-codex-app", // or FI_PROJECT_NAME; the collector drops a batch with no project_name
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
new CodexSDKInstrumentation({ tracerProvider }).manuallyInstrument(CodexSDK);
|
|
34
|
+
|
|
35
|
+
const thread = new CodexSDK.Codex().startThread({ workingDirectory: "/path/to/repo" });
|
|
36
|
+
const turn = await thread.run("List the files in this folder and read README.md");
|
|
37
|
+
|
|
38
|
+
await shutdown(tracerProvider); // flush before a short script exits
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`FI_API_KEY` and `FI_SECRET_KEY` are read by fi-core and sent as the `X-Api-Key` / `X-Secret-Key` headers. They are never copied onto spans.
|
|
42
|
+
|
|
43
|
+
The SDK is ESM-only, so its module namespace cannot be patched; its `Thread` class can. `manuallyInstrument(CodexSDK)` patches `Thread.prototype` once for the whole process. To trace only some clients instead, wrap instances:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const instrumentation = new CodexSDKInstrumentation({ tracerProvider });
|
|
47
|
+
const codex = instrumentation.wrapCodex(new CodexSDK.Codex()); // every thread it starts or resumes
|
|
48
|
+
const thread = instrumentation.wrapThread(existingThread); // one thread
|
|
49
|
+
instrumentation.unpatch(); // undo everything this object patched
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`instrumentCodexSDK(CodexSDK, { tracerProvider })` is the one-call form.
|
|
53
|
+
|
|
54
|
+
`CodexSDKInstrumentation` is not an OpenTelemetry `InstrumentationBase`: there is no module to hook on `require` or `import`, so passing it to `registerInstrumentations()` is not supported. Call `manuallyInstrument()` or the wrap methods.
|
|
55
|
+
|
|
56
|
+
`wrapThread()` and threads from `wrapCodex()` keep no reference to the thread: after `unpatch()` their patched method stays in place and passes events through untraced.
|
|
57
|
+
|
|
58
|
+
### What the wrapper does and does not do
|
|
59
|
+
|
|
60
|
+
- `run()` and `runStreamed()` both drive the SDK's private `Thread.runStreamedInternal()` generator. The wrapper wraps that one method, so both entry points are traced with real per-event timing. It yields the SDK's own event objects, unchanged and in order, and forwards `return()` / `throw()`: `run()` returns exactly what it returned before, and throws the same errors. If a future SDK drops that method, the wrapper falls back to `runStreamed()` and logs a warning that `run()` may be untraced.
|
|
61
|
+
- `Codex` options (`codexPathOverride`, `baseUrl`, `apiKey`, `config`, `env`) and thread options pass through untouched.
|
|
62
|
+
- A tracing error never fails the agent. An exporter or collector failure is logged and does not reject the stream.
|
|
63
|
+
- A turn ends when its event stream ends: read to the end, `break` out of `for await`, `events.return()`, a thrown error or an abort. A `runStreamed()` iterator that is dropped without any of these never ends its turn span: items that already finished are exported, but without their `codex.turn` parent. The turn span always ends last, after its open items, even if recording an attribute fails.
|
|
64
|
+
|
|
65
|
+
## Spans
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
codex.turn AGENT one per run() / runStreamed()
|
|
69
|
+
├─ codex.reasoning CHAIN
|
|
70
|
+
├─ codex.agent_message LLM
|
|
71
|
+
├─ codex.command_execution TOOL
|
|
72
|
+
├─ codex.file_change TOOL
|
|
73
|
+
├─ codex.mcp_tool_call TOOL
|
|
74
|
+
├─ codex.web_search TOOL
|
|
75
|
+
├─ codex.todo_list CHAIN
|
|
76
|
+
└─ codex.error CHAIN non-fatal error item: status UNSET, codex.warning=true
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`fi.span.kind` and `gen_ai.span.kind` carry the kind. An item type a newer SDK adds becomes `codex.<type>` (CHAIN). `codex.error` items are non-fatal: codex 0.162.1 sends config warnings, deprecation notices and model reroutes this way, so they do not mark the span or the turn ERROR.
|
|
80
|
+
|
|
81
|
+
| Field | Attributes | Source |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| Session | `session.id`, `gen_ai.conversation.id`, `codex.thread.id`; `codex.thread.resumed` | `thread.started.thread_id`, or the id of a resumed thread. Every child span carries `session.id` too |
|
|
84
|
+
| Model | `gen_ai.request.model` on the turn and on agent messages | `ThreadOptions.model`, when set. The SDK does not report which model the binary used, so a model chosen in `config.toml` is not recorded |
|
|
85
|
+
| Provider | `gen_ai.provider.name` = `openai`, always | Codex speaks the OpenAI Responses API. The SDK does not expose which `model_provider` the binary used, so a custom provider, Azure or `--oss` setup is still labelled `openai` |
|
|
86
|
+
| Tokens | `gen_ai.usage.input_tokens`, `output_tokens`, `total_tokens`, `cache_read_tokens`, `cache_write_tokens`, `output_tokens.reasoning` | `turn.completed.usage`, on the turn span only. See "Token usage" |
|
|
87
|
+
| Thread options | `codex.sandbox_mode`, `codex.approval_policy`, `codex.model_reasoning_effort`, `codex.web_search_mode` | `ThreadOptions` |
|
|
88
|
+
| Items | `codex.item.id`, `codex.item.type`, `codex.item.status`, `tool.name`, `gen_ai.tool.call.id` | `item.*` events |
|
|
89
|
+
| Commands | `codex.command.exit_code`, `codex.command.output_length` | `command_execution` |
|
|
90
|
+
| File changes | `codex.file_change.count`, `codex.file_change.kinds` (`add`, `delete`, `update`) | `file_change` |
|
|
91
|
+
| MCP | `tool.name` = the MCP tool, `codex.mcp.server`, `codex.mcp.tool` | `mcp_tool_call` |
|
|
92
|
+
| To-dos | `codex.todo.count`, `codex.todo.completed` | `todo_list` (started, updated, completed with the turn) |
|
|
93
|
+
| Errors | turn status ERROR; `codex.error.message`, `codex.error.type`; `codex.cancelled=true` | `turn.failed`; an `error` event with no `turn.completed` after it; a thrown error (for example `Codex Exec exited with code 1`); abort. `failed` items mark their own span ERROR. Error details are hidden independently of outputs (see "Privacy") |
|
|
94
|
+
| Retries | `codex.stream_error.count`, one `codex.stream_error` span event each | `error` events. Codex sends them for errors it retries ("Reconnecting... 1/5"); a turn that still reaches `turn.completed` ends OK |
|
|
95
|
+
|
|
96
|
+
Timing comes from when each event reaches your process. `agent_message` and `reasoning` items arrive only as `item.completed`; their spans start at the previous event (`codex.item.started_event=false`). The binary reports a command's `item.started` and `item.completed` close together, so command spans are short.
|
|
97
|
+
|
|
98
|
+
A fi-core `session.id` the app set (fi-core context helpers) is kept; the thread id still goes to `codex.thread.id`.
|
|
99
|
+
|
|
100
|
+
## Token usage
|
|
101
|
+
|
|
102
|
+
`turn.completed.usage` is the thread's running total, not the turn's own spend. Verified on 0.162.1 only: a second turn on a thread reported 39,318 input tokens after the first reported 19,378, and a third turn resumed from a new process reported 49,397. The Future AGI collector sums `gen_ai.usage.*` over a trace and over a `session.id`, so the turn span holds only the new spend:
|
|
103
|
+
|
|
104
|
+
- A new thread's first turn promotes the full value.
|
|
105
|
+
- Later turns promote the total minus the last total this process saw for that thread id (an in-process map, at most 1000 threads). `resumeThread(id)` in the same process uses it too.
|
|
106
|
+
- A resumed thread with no total seen in this process (a resume after a restart, or on another worker) promotes nothing on its first turn and sets `codex.usage.baseline_unknown=true`. Its later turns promote their difference.
|
|
107
|
+
- A turn that fails or is cancelled reports no usage, so its spend is counted on the thread's next completed turn. A new thread's first turn starts the thread at zero even when it fails, so the next turn still promotes its difference.
|
|
108
|
+
- If the total goes down, the reported value is promoted as is, `codex.usage.non_monotonic=true` is set, and the larger of the old and new totals is kept as the baseline.
|
|
109
|
+
- The running totals are always on `codex.cumulative.input_tokens`, `cached_input_tokens`, `cache_write_input_tokens`, `output_tokens`, `reasoning_output_tokens`.
|
|
110
|
+
|
|
111
|
+
`input_tokens` includes cached tokens and `output_tokens` includes reasoning tokens (OpenAI accounting); `total_tokens` is their sum. No cost is computed here; Future AGI estimates one from the model and tokens when `model` is set and it knows the model's price.
|
|
112
|
+
|
|
113
|
+
## Privacy: content is off by default
|
|
114
|
+
|
|
115
|
+
Prompts, shell commands, command output, file paths, MCP arguments and results, web search queries, reasoning, agent messages and to-do text can contain source code or secrets. They are **not** recorded unless you opt in:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
new CodexSDKInstrumentation({ tracerProvider, traceConfig: { hideInputs: false, hideOutputs: false } });
|
|
119
|
+
// or: FI_HIDE_INPUTS=false FI_HIDE_OUTPUTS=false
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
With inputs visible, the turn's `input.value` is the prompt and tool spans carry the command, file changes (including their paths), MCP arguments or search query. With outputs visible, the turn's `output.value` is the final agent message and items carry their output. Precedence: `traceConfig`, then the env var, then hidden. The env vars fail closed: only `false` (trimmed, any case) turns capture on; `0`, `no`, `off` or an empty value keep content hidden. Structural fields (lengths, counts, exit codes, statuses, tool and MCP server names) are always recorded.
|
|
123
|
+
|
|
124
|
+
Error details have a separate, default-on privacy gate: `hideErrorDetails: true`
|
|
125
|
+
(or `FI_HIDE_ERROR_DETAILS=true`). Status codes, error types, cancellation flags
|
|
126
|
+
and retry counts remain, but status descriptions, exception messages/stacks,
|
|
127
|
+
`codex.error.message`, retry-event text and failed-command output are omitted.
|
|
128
|
+
Turning ordinary outputs on does **not** turn error details on.
|
|
129
|
+
|
|
130
|
+
To include raw error details, explicitly set both `hideOutputs: false` and
|
|
131
|
+
`hideErrorDetails: false` (or both `FI_HIDE_OUTPUTS=false` and
|
|
132
|
+
`FI_HIDE_ERROR_DETAILS=false`). This can export stderr, provider bodies, local
|
|
133
|
+
paths, usernames and stack traces. If only error details are enabled while
|
|
134
|
+
outputs stay hidden, thrown errors use a fixed summary (`Codex Exec exited with
|
|
135
|
+
code N`, `Failed to parse item`, or the error class) rather than the raw message.
|
|
136
|
+
|
|
137
|
+
## Not captured
|
|
138
|
+
|
|
139
|
+
- **Per-request model spans and tokens.** The SDK reports agent messages, not individual Responses API calls.
|
|
140
|
+
- **The model the binary picked.** Only `ThreadOptions.model` is recorded.
|
|
141
|
+
- **Cost.** No cost is computed here; Future AGI estimates one from the model and tokens when `model` is set and it knows the model's price.
|
|
142
|
+
- **Exact durations.** Times are when events reach your process (see "Spans").
|
|
143
|
+
- **Approval decisions.** The event stream does not carry them.
|
|
144
|
+
- **Sub-agents.** codex 0.162.1 also emits `collab_tool_call` items (a sub-agent spawn) that are not in the SDK's types. They appear as a generic `codex.collab_tool_call` CHAIN span, with no link to the sub-agent's own work.
|
|
145
|
+
|
|
146
|
+
## Flushing
|
|
147
|
+
|
|
148
|
+
`shutdown(provider)` calls `forceFlush()` on the provider. It does not shut the provider down.
|
|
149
|
+
|
|
150
|
+
## Troubleshooting
|
|
151
|
+
|
|
152
|
+
- **`FI_PROJECT_NAME is not set`.** `register()` throws this without `projectName` or `FI_PROJECT_NAME`.
|
|
153
|
+
- **No traces.** `manuallyInstrument()` must get the module namespace (`import * as CodexSDK`), not the `Codex` class; it returns `false` otherwise. Its warning is logged only when an OpenTelemetry diag logger is set (`diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN)`). A `runStreamed()` iterator that is neither read to the end nor closed (`break`, `return()`) exports nothing.
|
|
154
|
+
- **Zero spans from a short script.** `await shutdown(provider)` before exit.
|
|
155
|
+
- **No tokens on a turn.** Look for `codex.usage.baseline_unknown=true`: the thread was resumed with no earlier total in this process. `codex.cumulative.*` still has the totals.
|
|
156
|
+
- **No model.** Pass `model` in `startThread()` / `resumeThread()` options.
|
|
157
|
+
- **Spans marked cancelled.** The caller left the `for await` loop with `break` (or called `events.return()`) before `turn.completed`, or aborted with `TurnOptions.signal`.
|
|
158
|
+
- **`codex.stream_error.count` on an OK turn.** Codex retried a stream error and the turn completed; nothing failed.
|
|
159
|
+
|
|
160
|
+
## Tests
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
pnpm --filter @traceai/codex-sdk test # jest: span model, privacy, usage, patching, SDK shape
|
|
164
|
+
pnpm --filter @traceai/codex-sdk test:contract # build, then the real SDK against contract/fake-codex.mjs
|
|
165
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Span names and attribute keys for Codex SDK spans.
|
|
3
|
+
*
|
|
4
|
+
* Standard keys (`fi.span.kind`, `session.id`, `input.value`, token counts...)
|
|
5
|
+
* come from `@traceai/fi-semantic-conventions` so the Future AGI collector
|
|
6
|
+
* promotes them. `codex.*` keys carry the SDK's own structural fields.
|
|
7
|
+
*/
|
|
8
|
+
import { FISpanKind } from "@traceai/fi-semantic-conventions";
|
|
9
|
+
export declare const SpanNames: {
|
|
10
|
+
readonly TURN: "codex.turn";
|
|
11
|
+
readonly AGENT_MESSAGE: "codex.agent_message";
|
|
12
|
+
readonly REASONING: "codex.reasoning";
|
|
13
|
+
readonly COMMAND_EXECUTION: "codex.command_execution";
|
|
14
|
+
readonly FILE_CHANGE: "codex.file_change";
|
|
15
|
+
readonly MCP_TOOL_CALL: "codex.mcp_tool_call";
|
|
16
|
+
readonly WEB_SEARCH: "codex.web_search";
|
|
17
|
+
readonly TODO_LIST: "codex.todo_list";
|
|
18
|
+
readonly ERROR: "codex.error";
|
|
19
|
+
};
|
|
20
|
+
/** SDK item type -> span name and Future AGI span kind. */
|
|
21
|
+
export declare const ITEM_SPANS: Record<string, {
|
|
22
|
+
name: string;
|
|
23
|
+
kind: FISpanKind;
|
|
24
|
+
tool: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
/** Fallback for an item type a newer SDK adds. */
|
|
27
|
+
export declare const UNKNOWN_ITEM_SPAN: {
|
|
28
|
+
kind: FISpanKind;
|
|
29
|
+
tool: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare const CodexAttributes: {
|
|
32
|
+
readonly THREAD_ID: "codex.thread.id";
|
|
33
|
+
readonly THREAD_RESUMED: "codex.thread.resumed";
|
|
34
|
+
readonly SANDBOX_MODE: "codex.sandbox_mode";
|
|
35
|
+
readonly APPROVAL_POLICY: "codex.approval_policy";
|
|
36
|
+
readonly REASONING_EFFORT: "codex.model_reasoning_effort";
|
|
37
|
+
readonly WEB_SEARCH_MODE: "codex.web_search_mode";
|
|
38
|
+
readonly INPUT_IMAGE_COUNT: "codex.input.image_count";
|
|
39
|
+
readonly INPUT_LENGTH: "codex.input.length";
|
|
40
|
+
readonly ITEM_ID: "codex.item.id";
|
|
41
|
+
readonly ITEM_TYPE: "codex.item.type";
|
|
42
|
+
readonly ITEM_STATUS: "codex.item.status";
|
|
43
|
+
/** false when the SDK sent only `item.completed`; the span then starts at the previous event. */
|
|
44
|
+
readonly ITEM_STARTED_EVENT: "codex.item.started_event";
|
|
45
|
+
readonly ITEM_INCOMPLETE: "codex.item.incomplete";
|
|
46
|
+
readonly COMMAND_EXIT_CODE: "codex.command.exit_code";
|
|
47
|
+
readonly COMMAND_OUTPUT_LENGTH: "codex.command.output_length";
|
|
48
|
+
readonly FILE_CHANGE_COUNT: "codex.file_change.count";
|
|
49
|
+
readonly FILE_CHANGE_KINDS: "codex.file_change.kinds";
|
|
50
|
+
readonly MCP_SERVER: "codex.mcp.server";
|
|
51
|
+
readonly MCP_TOOL: "codex.mcp.tool";
|
|
52
|
+
readonly TODO_COUNT: "codex.todo.count";
|
|
53
|
+
readonly TODO_COMPLETED: "codex.todo.completed";
|
|
54
|
+
readonly TEXT_LENGTH: "codex.text.length";
|
|
55
|
+
readonly USAGE_CACHED_INPUT_TOKENS: "codex.usage.cached_input_tokens";
|
|
56
|
+
readonly USAGE_CACHE_WRITE_INPUT_TOKENS: "codex.usage.cache_write_input_tokens";
|
|
57
|
+
readonly USAGE_REASONING_OUTPUT_TOKENS: "codex.usage.reasoning_output_tokens";
|
|
58
|
+
/** A resumed thread's first turn in this process: no earlier total, so nothing promoted. */
|
|
59
|
+
readonly USAGE_BASELINE_UNKNOWN: "codex.usage.baseline_unknown";
|
|
60
|
+
/** The running total went down; the reported value was promoted as is. */
|
|
61
|
+
readonly USAGE_NON_MONOTONIC: "codex.usage.non_monotonic";
|
|
62
|
+
/** Prefix for the thread's running totals, e.g. `codex.cumulative.input_tokens`. */
|
|
63
|
+
readonly CUMULATIVE_PREFIX: "codex.cumulative.";
|
|
64
|
+
/** Fixed summary unless outputs are visible; see README "Privacy". */
|
|
65
|
+
readonly ERROR_MESSAGE: "codex.error.message";
|
|
66
|
+
/** Error class name of a thrown error, e.g. `Error`, `TypeError`. */
|
|
67
|
+
readonly ERROR_TYPE: "codex.error.type";
|
|
68
|
+
/** `error` events in the turn. Codex sends them for errors it retries; the turn can still complete. */
|
|
69
|
+
readonly STREAM_ERROR_COUNT: "codex.stream_error.count";
|
|
70
|
+
/** On `codex.error` spans: a non-fatal error item (warning, deprecation, model reroute). */
|
|
71
|
+
readonly WARNING: "codex.warning";
|
|
72
|
+
readonly CANCELLED: "codex.cancelled";
|
|
73
|
+
};
|
|
74
|
+
/** Standard keys used by this package, resolved from fi-semantic-conventions. */
|
|
75
|
+
export declare const StandardAttributes: {
|
|
76
|
+
readonly FI_SPAN_KIND: "fi.span.kind";
|
|
77
|
+
/** Same value as `fi.span.kind`; the Python fi_instrumentation key the collector also reads. */
|
|
78
|
+
readonly GEN_AI_SPAN_KIND: "gen_ai.span.kind";
|
|
79
|
+
readonly SESSION_ID: "session.id";
|
|
80
|
+
readonly CONVERSATION_ID: "gen_ai.conversation.id";
|
|
81
|
+
readonly INPUT_VALUE: "input.value";
|
|
82
|
+
readonly INPUT_MIME_TYPE: "input.mime_type";
|
|
83
|
+
readonly OUTPUT_VALUE: "output.value";
|
|
84
|
+
readonly OUTPUT_MIME_TYPE: "output.mime_type";
|
|
85
|
+
readonly MODEL_NAME: "gen_ai.request.model";
|
|
86
|
+
readonly PROVIDER: "gen_ai.provider.name";
|
|
87
|
+
readonly TOOL_NAME: "tool.name";
|
|
88
|
+
readonly GEN_AI_TOOL_NAME: "gen_ai.tool.name";
|
|
89
|
+
readonly TOOL_CALL_ID: "gen_ai.tool.call.id";
|
|
90
|
+
readonly AGENT_NAME: "gen_ai.agent.name";
|
|
91
|
+
readonly INPUT_TOKENS: "gen_ai.usage.input_tokens";
|
|
92
|
+
readonly OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
|
|
93
|
+
readonly TOTAL_TOKENS: "gen_ai.usage.total_tokens";
|
|
94
|
+
readonly CACHE_READ_TOKENS: "gen_ai.usage.cache_read_tokens";
|
|
95
|
+
readonly CACHE_WRITE_TOKENS: "gen_ai.usage.cache_write_tokens";
|
|
96
|
+
readonly REASONING_TOKENS: "gen_ai.usage.output_tokens.reasoning";
|
|
97
|
+
};
|
|
98
|
+
export declare const AGENT_NAME = "codex";
|
|
99
|
+
/** Codex talks to the OpenAI Responses API (or an OpenAI-compatible proxy). */
|
|
100
|
+
export declare const PROVIDER_NAME = "openai";
|
|
101
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAuB,MAAM,kCAAkC,CAAC;AAEnF,eAAO,MAAM,SAAS;;;;;;;;;;CAUZ,CAAC;AAEX,2DAA2D;AAC3D,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAUxF,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,iBAAiB;;;CAA0C,CAAC;AAEzE,eAAO,MAAM,eAAe;;;;;;;;;;;;IAa1B,iGAAiG;;;;;;;;;;;;;;;IAiBjG,4FAA4F;;IAE5F,0EAA0E;;IAE1E,oFAAoF;;IAGpF,sEAAsE;;IAEtE,qEAAqE;;IAErE,uGAAuG;;IAEvG,4FAA4F;;;CAGpF,CAAC;AAEX,iFAAiF;AACjF,eAAO,MAAM,kBAAkB;;IAE7B,gGAAgG;;;;;;;;;;;;;;;;;;;;CAoBxF,CAAC;AAEX,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,+EAA+E;AAC/E,eAAO,MAAM,aAAa,WAAW,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Span names and attribute keys for Codex SDK spans.
|
|
3
|
+
*
|
|
4
|
+
* Standard keys (`fi.span.kind`, `session.id`, `input.value`, token counts...)
|
|
5
|
+
* come from `@traceai/fi-semantic-conventions` so the Future AGI collector
|
|
6
|
+
* promotes them. `codex.*` keys carry the SDK's own structural fields.
|
|
7
|
+
*/
|
|
8
|
+
import { FISpanKind, SemanticConventions } from "@traceai/fi-semantic-conventions";
|
|
9
|
+
export const SpanNames = {
|
|
10
|
+
TURN: "codex.turn",
|
|
11
|
+
AGENT_MESSAGE: "codex.agent_message",
|
|
12
|
+
REASONING: "codex.reasoning",
|
|
13
|
+
COMMAND_EXECUTION: "codex.command_execution",
|
|
14
|
+
FILE_CHANGE: "codex.file_change",
|
|
15
|
+
MCP_TOOL_CALL: "codex.mcp_tool_call",
|
|
16
|
+
WEB_SEARCH: "codex.web_search",
|
|
17
|
+
TODO_LIST: "codex.todo_list",
|
|
18
|
+
ERROR: "codex.error",
|
|
19
|
+
};
|
|
20
|
+
/** SDK item type -> span name and Future AGI span kind. */
|
|
21
|
+
export const ITEM_SPANS = {
|
|
22
|
+
agent_message: { name: SpanNames.AGENT_MESSAGE, kind: FISpanKind.LLM, tool: false },
|
|
23
|
+
reasoning: { name: SpanNames.REASONING, kind: FISpanKind.CHAIN, tool: false },
|
|
24
|
+
command_execution: { name: SpanNames.COMMAND_EXECUTION, kind: FISpanKind.TOOL, tool: true },
|
|
25
|
+
file_change: { name: SpanNames.FILE_CHANGE, kind: FISpanKind.TOOL, tool: true },
|
|
26
|
+
mcp_tool_call: { name: SpanNames.MCP_TOOL_CALL, kind: FISpanKind.TOOL, tool: true },
|
|
27
|
+
web_search: { name: SpanNames.WEB_SEARCH, kind: FISpanKind.TOOL, tool: true },
|
|
28
|
+
todo_list: { name: SpanNames.TODO_LIST, kind: FISpanKind.CHAIN, tool: false },
|
|
29
|
+
// Non-fatal: status UNSET with codex.warning=true.
|
|
30
|
+
error: { name: SpanNames.ERROR, kind: FISpanKind.CHAIN, tool: false },
|
|
31
|
+
};
|
|
32
|
+
/** Fallback for an item type a newer SDK adds. */
|
|
33
|
+
export const UNKNOWN_ITEM_SPAN = { kind: FISpanKind.CHAIN, tool: false };
|
|
34
|
+
export const CodexAttributes = {
|
|
35
|
+
THREAD_ID: "codex.thread.id",
|
|
36
|
+
THREAD_RESUMED: "codex.thread.resumed",
|
|
37
|
+
SANDBOX_MODE: "codex.sandbox_mode",
|
|
38
|
+
APPROVAL_POLICY: "codex.approval_policy",
|
|
39
|
+
REASONING_EFFORT: "codex.model_reasoning_effort",
|
|
40
|
+
WEB_SEARCH_MODE: "codex.web_search_mode",
|
|
41
|
+
INPUT_IMAGE_COUNT: "codex.input.image_count",
|
|
42
|
+
INPUT_LENGTH: "codex.input.length",
|
|
43
|
+
ITEM_ID: "codex.item.id",
|
|
44
|
+
ITEM_TYPE: "codex.item.type",
|
|
45
|
+
ITEM_STATUS: "codex.item.status",
|
|
46
|
+
/** false when the SDK sent only `item.completed`; the span then starts at the previous event. */
|
|
47
|
+
ITEM_STARTED_EVENT: "codex.item.started_event",
|
|
48
|
+
ITEM_INCOMPLETE: "codex.item.incomplete",
|
|
49
|
+
COMMAND_EXIT_CODE: "codex.command.exit_code",
|
|
50
|
+
COMMAND_OUTPUT_LENGTH: "codex.command.output_length",
|
|
51
|
+
FILE_CHANGE_COUNT: "codex.file_change.count",
|
|
52
|
+
FILE_CHANGE_KINDS: "codex.file_change.kinds",
|
|
53
|
+
MCP_SERVER: "codex.mcp.server",
|
|
54
|
+
MCP_TOOL: "codex.mcp.tool",
|
|
55
|
+
TODO_COUNT: "codex.todo.count",
|
|
56
|
+
TODO_COMPLETED: "codex.todo.completed",
|
|
57
|
+
TEXT_LENGTH: "codex.text.length",
|
|
58
|
+
USAGE_CACHED_INPUT_TOKENS: "codex.usage.cached_input_tokens",
|
|
59
|
+
USAGE_CACHE_WRITE_INPUT_TOKENS: "codex.usage.cache_write_input_tokens",
|
|
60
|
+
USAGE_REASONING_OUTPUT_TOKENS: "codex.usage.reasoning_output_tokens",
|
|
61
|
+
/** A resumed thread's first turn in this process: no earlier total, so nothing promoted. */
|
|
62
|
+
USAGE_BASELINE_UNKNOWN: "codex.usage.baseline_unknown",
|
|
63
|
+
/** The running total went down; the reported value was promoted as is. */
|
|
64
|
+
USAGE_NON_MONOTONIC: "codex.usage.non_monotonic",
|
|
65
|
+
/** Prefix for the thread's running totals, e.g. `codex.cumulative.input_tokens`. */
|
|
66
|
+
CUMULATIVE_PREFIX: "codex.cumulative.",
|
|
67
|
+
/** Fixed summary unless outputs are visible; see README "Privacy". */
|
|
68
|
+
ERROR_MESSAGE: "codex.error.message",
|
|
69
|
+
/** Error class name of a thrown error, e.g. `Error`, `TypeError`. */
|
|
70
|
+
ERROR_TYPE: "codex.error.type",
|
|
71
|
+
/** `error` events in the turn. Codex sends them for errors it retries; the turn can still complete. */
|
|
72
|
+
STREAM_ERROR_COUNT: "codex.stream_error.count",
|
|
73
|
+
/** On `codex.error` spans: a non-fatal error item (warning, deprecation, model reroute). */
|
|
74
|
+
WARNING: "codex.warning",
|
|
75
|
+
CANCELLED: "codex.cancelled",
|
|
76
|
+
};
|
|
77
|
+
/** Standard keys used by this package, resolved from fi-semantic-conventions. */
|
|
78
|
+
export const StandardAttributes = {
|
|
79
|
+
FI_SPAN_KIND: SemanticConventions.FI_SPAN_KIND,
|
|
80
|
+
/** Same value as `fi.span.kind`; the Python fi_instrumentation key the collector also reads. */
|
|
81
|
+
GEN_AI_SPAN_KIND: "gen_ai.span.kind",
|
|
82
|
+
SESSION_ID: SemanticConventions.SESSION_ID,
|
|
83
|
+
CONVERSATION_ID: SemanticConventions.GEN_AI_CONVERSATION_ID,
|
|
84
|
+
INPUT_VALUE: SemanticConventions.INPUT_VALUE,
|
|
85
|
+
INPUT_MIME_TYPE: SemanticConventions.INPUT_MIME_TYPE,
|
|
86
|
+
OUTPUT_VALUE: SemanticConventions.OUTPUT_VALUE,
|
|
87
|
+
OUTPUT_MIME_TYPE: SemanticConventions.OUTPUT_MIME_TYPE,
|
|
88
|
+
MODEL_NAME: SemanticConventions.LLM_MODEL_NAME,
|
|
89
|
+
PROVIDER: SemanticConventions.LLM_PROVIDER,
|
|
90
|
+
TOOL_NAME: SemanticConventions.TOOL_NAME,
|
|
91
|
+
GEN_AI_TOOL_NAME: "gen_ai.tool.name",
|
|
92
|
+
TOOL_CALL_ID: "gen_ai.tool.call.id",
|
|
93
|
+
AGENT_NAME: "gen_ai.agent.name",
|
|
94
|
+
INPUT_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_PROMPT,
|
|
95
|
+
OUTPUT_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_COMPLETION,
|
|
96
|
+
TOTAL_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_TOTAL,
|
|
97
|
+
CACHE_READ_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_READ,
|
|
98
|
+
CACHE_WRITE_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_WRITE,
|
|
99
|
+
REASONING_TOKENS: SemanticConventions.LLM_TOKEN_COUNT_COMPLETION_DETAILS_REASONING,
|
|
100
|
+
};
|
|
101
|
+
export const AGENT_NAME = "codex";
|
|
102
|
+
/** Codex talks to the OpenAI Responses API (or an OpenAI-compatible proxy). */
|
|
103
|
+
export const PROVIDER_NAME = "openai";
|
|
104
|
+
//# sourceMappingURL=attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../src/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEnF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,YAAY;IAClB,aAAa,EAAE,qBAAqB;IACpC,SAAS,EAAE,iBAAiB;IAC5B,iBAAiB,EAAE,yBAAyB;IAC5C,WAAW,EAAE,mBAAmB;IAChC,aAAa,EAAE,qBAAqB;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AgG;IAChG,gBAAgB,EAAE,kBAAkB;IACpC,UAAU,EAAE,mBAAmB,CAAC,UAAU;IAC1C,eAAe,EAAE,mBAAmB,CAAC,sBAAsB;IAC3D,WAAW,EAAE,mBAAmB,CAAC,WAAW;IAC5C,eAAe,EAAE,mBAAmB,CAAC,eAAe;IACpD,YAAY,EAAE,mBAAmB,CAAC,YAAY;IAC9C,gBAAgB,EAAE,mBAAmB,CAAC,gBAAgB;IACtD,UAAU,EAAE,mBAAmB,CAAC,cAAc;IAC9C,QAAQ,EAAE,mBAAmB,CAAC,YAAY;IAC1C,SAAS,EAAE,mBAAmB,CAAC,SAAS;IACxC,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,qBAAqB;IACnC,UAAU,EAAE,mBAAmB;IAC/B,YAAY,EAAE,mBAAmB,CAAC,sBAAsB;IACxD,aAAa,EAAE,mBAAmB,CAAC,0BAA0B;IAC7D,YAAY,EAAE,mBAAmB,CAAC,qBAAqB;IACvD,iBAAiB,EAAE,mBAAmB,CAAC,yCAAyC;IAChF,kBAAkB,EAAE,mBAAmB,CAAC,0CAA0C;IAClF,gBAAgB,EAAE,mBAAmB,CAAC,4CAA4C;CAC1E,CAAC;AAEX,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC;AAClC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { CodexSDKInstrumentation, INSTRUMENTATION_NAME, instrumentCodexSDK, resolveContentPolicy, shutdown, } from "./instrumentation.js";
|
|
2
|
+
export type { CodexSDKInstrumentationConfig } from "./instrumentation.js";
|
|
3
|
+
export { isPatched } from "./threadWrapper.js";
|
|
4
|
+
export type { ContentPolicy } from "./spans.js";
|
|
5
|
+
export { AGENT_NAME, CodexAttributes, ITEM_SPANS, PROVIDER_NAME, SpanNames, StandardAttributes, } from "./attributes.js";
|
|
6
|
+
export type { CodexModuleLike, ThreadEventLike, ThreadItemLike, ThreadLike, ThreadOptionsLike, UsageLike, } from "./types.js";
|
|
7
|
+
export { VERSION } from "./version.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,eAAe,EACf,UAAU,EACV,aAAa,EACb,SAAS,EACT,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CodexSDKInstrumentation, INSTRUMENTATION_NAME, instrumentCodexSDK, resolveContentPolicy, shutdown, } from "./instrumentation.js";
|
|
2
|
+
export { isPatched } from "./threadWrapper.js";
|
|
3
|
+
export { AGENT_NAME, CodexAttributes, ITEM_SPANS, PROVIDER_NAME, SpanNames, StandardAttributes, } from "./attributes.js";
|
|
4
|
+
export { VERSION } from "./version.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACL,UAAU,EACV,eAAe,EACf,UAAU,EACV,aAAa,EACb,SAAS,EACT,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry points: an instrumentation object that patches the SDK's
|
|
3
|
+
* `Thread` class (or single `Codex` / `Thread` instances), and a `shutdown()`
|
|
4
|
+
* that flushes the tracer provider before a short script exits.
|
|
5
|
+
*/
|
|
6
|
+
import { TracerProvider } from "@opentelemetry/api";
|
|
7
|
+
import { TraceConfigOptions } from "@traceai/fi-core";
|
|
8
|
+
import { ContentPolicy } from "./spans.js";
|
|
9
|
+
import { CodexModuleLike } from "./types.js";
|
|
10
|
+
export declare const INSTRUMENTATION_NAME = "@traceai/codex-sdk";
|
|
11
|
+
export interface CodexSDKInstrumentationConfig {
|
|
12
|
+
/** Provider to create spans with. Defaults to the global provider at call time. */
|
|
13
|
+
tracerProvider?: TracerProvider;
|
|
14
|
+
/**
|
|
15
|
+
* fi-core trace config. Unlike fi-core, `hideInputs` and `hideOutputs`
|
|
16
|
+
* default to `true` here: prompts, shell commands, command output, file
|
|
17
|
+
* paths and MCP arguments can contain source code or secrets. Opt in with
|
|
18
|
+
* `false`, or with `FI_HIDE_INPUTS=false` / `FI_HIDE_OUTPUTS=false`.
|
|
19
|
+
*/
|
|
20
|
+
traceConfig?: TraceConfigOptions;
|
|
21
|
+
}
|
|
22
|
+
/** Precedence: explicit option > fi-core env var > this package's default (hidden). */
|
|
23
|
+
export declare function resolveContentPolicy(traceConfig?: TraceConfigOptions): ContentPolicy;
|
|
24
|
+
/**
|
|
25
|
+
* Traces `@openai/codex-sdk` turns.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as CodexSDK from "@openai/codex-sdk";
|
|
29
|
+
* const instrumentation = new CodexSDKInstrumentation({ tracerProvider });
|
|
30
|
+
* instrumentation.manuallyInstrument(CodexSDK);
|
|
31
|
+
* const thread = new CodexSDK.Codex().startThread();
|
|
32
|
+
* await thread.run("..."); // one codex.turn trace
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* The SDK is ESM-only, so its module namespace cannot be patched; its `Thread`
|
|
36
|
+
* class prototype can. `wrapCodex()` / `wrapThread()` patch single instances
|
|
37
|
+
* instead, for apps that prefer not to touch the shared class.
|
|
38
|
+
*
|
|
39
|
+
* This is not an OpenTelemetry `InstrumentationBase`: there is no module to
|
|
40
|
+
* hook on `require`/`import`, so it cannot be passed to
|
|
41
|
+
* `registerInstrumentations()`. Call `manuallyInstrument()` or the wrap methods.
|
|
42
|
+
*/
|
|
43
|
+
export declare class CodexSDKInstrumentation {
|
|
44
|
+
private tracerProvider?;
|
|
45
|
+
private readonly traceConfig?;
|
|
46
|
+
/** Undo functions for the class patch and wrapCodex() factories (never one per thread). */
|
|
47
|
+
private readonly undo;
|
|
48
|
+
/** False after unpatch(): instance patches stay in place but pass events through untraced. */
|
|
49
|
+
private enabled;
|
|
50
|
+
constructor(config?: CodexSDKInstrumentationConfig);
|
|
51
|
+
setTracerProvider(tracerProvider: TracerProvider): void;
|
|
52
|
+
/** The content policy this instrumentation applies. */
|
|
53
|
+
get contentPolicy(): ContentPolicy;
|
|
54
|
+
/**
|
|
55
|
+
* Patch `module.Thread.prototype`. Pass the SDK module namespace
|
|
56
|
+
* (`import * as CodexSDK from "@openai/codex-sdk"`) or `{ Thread }`.
|
|
57
|
+
* Returns `true` when the class was patched by this call.
|
|
58
|
+
*/
|
|
59
|
+
manuallyInstrument(module: CodexModuleLike): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Patch one Thread instance. Returns the same instance. No reference to the
|
|
62
|
+
* thread is kept: after `unpatch()` the patched method passes events through
|
|
63
|
+
* untraced instead of being removed.
|
|
64
|
+
*/
|
|
65
|
+
wrapThread<T extends object>(thread: T): T;
|
|
66
|
+
/** Patch one Codex instance so every thread it starts or resumes is traced. Returns the same instance. */
|
|
67
|
+
wrapCodex<T extends object>(codex: T): T;
|
|
68
|
+
/** Remove every patch this instrumentation applied. */
|
|
69
|
+
unpatch(): void;
|
|
70
|
+
/** Flush the provider's span processors. Does not shut the provider down. */
|
|
71
|
+
forceFlush(): Promise<void>;
|
|
72
|
+
private tracingContext;
|
|
73
|
+
}
|
|
74
|
+
/** Python-style convenience constructor. */
|
|
75
|
+
export declare function instrumentCodexSDK(module: CodexModuleLike, config?: CodexSDKInstrumentationConfig): CodexSDKInstrumentation;
|
|
76
|
+
/**
|
|
77
|
+
* Flush spans before a short script exits. Export errors are logged, never
|
|
78
|
+
* thrown: export failure does not fail the agent.
|
|
79
|
+
*/
|
|
80
|
+
export declare function shutdown(tracerProvider?: TracerProvider): Promise<void>;
|
|
81
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAe,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAY,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,eAAe,EAAc,MAAM,SAAS,CAAC;AAGtD,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AAUzD,MAAM,WAAW,6BAA6B;IAC5C,mFAAmF;IACnF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAQD,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,WAAW,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAMpF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qB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