Repository navigation
fix(openai-agents-ts): support @openai/agents up to 0.21 and add real-SDK compatibility test - #285
Merged
Merged
Conversation
…oints exports["."].import and "module" point at dist/esm/index.js, but the ESM and ESNext builds inherited rootDir "." and wrote dist/esm/src/index.js with extensionless relative imports, so `import "@traceai/openai-agents"` failed with ERR_MODULE_NOT_FOUND (published 0.1.0 has the same layout). Use rootDir "src" and the shared ESM/ESNext base configs, as traceai_openai and the other packages do; tsc-alias then adds the .js extensions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… SDK's real span data - Peer range ^0.4.0 -> >=0.4.0 <0.22.0 (npm install with @openai/agents 0.21.0 failed with ERESOLVE); the require hook uses the same range. - The processor read camelCase fields (toAgent, modelConfig, usage.inputTokens, input/response) that the SDK never emits. Every release from 0.4 to 0.21 uses snake_case (to_agent/from_agent, model_config, usage.input_tokens, response spans' _input/_response), so handoff names and graph.node.parent_id, invocation parameters, token counts and response/root input and output were all missing. - Response spans now carry model and token counts; generation spans carry output text and fall back to the Chat Completions usage block. - exclusiveProcessor option (default true keeps today's setTraceProcessors behaviour; false uses addTraceProcessor and keeps the SDK's OpenAI exporter), like exclusive_processor in Python. - manuallyInstrument() no longer throws on an ES module namespace. - realSdk.test.ts: real Runner + OpenAI models against an in-process fake OpenAI server (Responses and Chat Completions), asserting the span tree and flush on shutdown. Passes on 0.4.15, 0.11.8, 0.16.1 and 0.21.0; the old processor fails it. - Version 0.2.0, new package CHANGELOG.md and README.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TracerProvider() InstrumentationBase calls enable() from its constructor, before the subclass stores traceConfig, so the FITracer was always built with traceConfig undefined. fi-core returns its defaults for undefined without reading FI_HIDE_INPUTS / FI_HIDE_OUTPUTS, so neither the option nor the environment variables redacted anything. The FITracer also kept the tracer it got at that point. A provider set with setTracerProvider() afterwards (the order the README shows) was ignored unless enable() ran again, and spans went to the global provider instead. Build the FITracer again once the config is stored and when the module is patched, and always pass an options object so fi-core reads the environment. Three new real-SDK tests cover the README order, traceConfig redaction and FI_HIDE_* redaction; all three fail without this change. raw.input / raw.output are still exported by fi-core 1.0.0 (fixed in #271); the README says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes
@traceai/openai-agentsinstallable and correct on current@openai/agentsreleases, makes its hide flags andsetTracerProvider()work, and adds a compatibility test that runs the real SDK.^0.4.0->>=0.4.0 <0.22.0.npm install @traceai/openai-agents @openai/agents@0.21.0(the current release) fails today withERESOLVE. The require hook uses the same range, and the range is exported asSUPPORTED_AGENTS_VERSIONS.toAgent,modelConfig,usage.inputTokens,input/response) that the SDK never emits. Every release from 0.4 to 0.21 uses snake_case (to_agent/from_agent,model_config,usage.input_tokens, response spans'_input/_response). Because of that, these were all missing: handoff names,graph.node.parent_id, invocation parameters, token counts, and response/root input and output. Response spans now carry the model and token counts. Generation spans carry the output text and fall back to the Chat Completionsusageblock.exclusiveProcessoroption. The defaulttruekeeps today'ssetTraceProcessorsbehaviour, which replaces the SDK's OpenAI exporter.falseusesaddTraceProcessorand keeps it. This matchesexclusive_processorin the Python package.exports["."].import/modulepointed atdist/esm/index.js, but the build wrotedist/esm/src/index.jswith extensionless imports, soimport "@traceai/openai-agents"failed. The ESM and ESNext tsconfigs now userootDir: "src"and the shared ESM base config, like the other packages.manuallyInstrument()no longer throws on an ES module namespace (import * as agents from "@openai/agents").setTracerProvider().traceConfigandFI_HIDE_INPUTS/FI_HIDE_OUTPUTShad no effect.InstrumentationBasecallsenable()from its constructor, before the subclass storestraceConfig, so theFITracerwas built withundefined, and fi-core then returns its defaults without reading the environment. ThatFITraceralso kept the tracer it was created with, so a provider passed tosetTracerProvider()afterwards (the README order) was ignored and spans went to the global provider. The tracer is now rebuilt once the config is stored and again when the module is patched. The tracer always gets an options object, so the environment variables are read.CHANGELOG.mdandREADME.md(supported versions, quick start, exporter behaviour, captured spans, hide flags).Why?
The package could not be installed next to any
@openai/agentsrelease after 0.4.x. Even on 0.4.x it dropped handoffs, model settings, token usage and response input/output, because it read the wrong field names. A working package with reproducible compatibility evidence is also what theopenai-agents-jstracing-processors list asks for before it links an integration.How was it tested?
Unit tests added / updated (
jest; this package uses jest, not vitest)Integration tests pass (or N/A — no gateway behavior changed)
ruff check/mypy/npm run typecheck/npm run lintall pass. Type checking passes throughpnpm run buildand ts-jest.npm run lintcannot run onmain(see Notes).Public types, env vars, or SDK behavior changes are documented in the relevant README
New
src/__tests__/realSdk.test.tsruns a two-agent workflow (tool call, then a handoff, then the answer) through the realRunnerand OpenAI models against an in-process fake OpenAI server on 127.0.0.1, so it needs no API key and no network. It covers both the Responses API (response spans) and Chat Completions (generation spans). It asserts span names, parent links, the tool and handoff spans, model, invocation parameters and token counts, and that spans flush on shutdown.setTracerProvider(),manuallyInstrument()). They check that spans reach that provider, and thattraceConfigandFI_HIDE_*replaceinput.value/output.valuewith__REDACTED__. All three fail without the third commit.@openai/agents0.4.15, 0.11.8, 0.16.1 and 0.21.0.mainfails 2 of the first 3 tests.pnpm testin the package: 2 suites, 24 tests passed.The packed tarball was also run end to end with the README quick start, against a local fake OpenAI server and a local OTLP receiver. The receiver got 5 spans on
/tracer/v1/traceswithproject_name, and withFI_HIDE_INPUTS=true FI_HIDE_OUTPUTS=trueinput.valueandoutput.valuearrived as__REDACTED__.pnpm run build(CJS, ESM and ESNext) passes.pnpm pack, then a freshnpm install <tgz> @openai/agents@0.21.0in an empty directory: noERESOLVE. Bothrequire("@traceai/openai-agents")andimport ... from "@traceai/openai-agents"load.pnpm install --frozen-lockfilepasses with pnpm 10.30.1 (the pinnedpackageManager).Checklist
devfeat:,fix:,docs:,chore:…)docs/VOCABULARY.md(the file does not exist in the repo)Notes for reviewers
@openai/agents0.21.0 is now a devDependency, sopnpm-lock.yamlmoves from@openai/agents0.4.15 to 0.21.0 (withopenai7.x). pnpm also dedupes thewspeer from 8.21.0 to 8.22.0 across the workspace, which accounts for most of the 450-line lockfile diff. It was regenerated once frommain's lockfile; the commits apply cleanly ontodevandpnpm install --frozen-lockfilepasses there.strict: true, so the package does not addzodas a devDependency.<0.22.0, the last version the test ran on. The SDK ships a minor release every 1-3 weeks, so bump the bound together with the test whenever it does.@traceai/fi-core1.0.0 still exportsraw.input/raw.output(the request and response bodies) when hiding is on. This predates the PR. The fix is in feat(typescript): hide error details with the content hide flags #271 (fi-core 1.1.0), and the README says so. Merge and release feat(typescript): hide error details with the content hide flags #271 before advertising the hide flags for this package.--detectOpenHandlesfinds nothing. The cause is the SDK's ownBatchTraceProcessortimers (a 500 ms flush wait that is notunref'd, and a shutdown that keeps the loop alive). The tests still pass.npm run lint(eslint . --ext .ts) cannot run onmain: the repo has no ESLint config, and ESLint 9+ needseslint.config.*. TypeScript type checking ran through the build and ts-jest.@traceai/openai-agents@0.2.0to npm (npm has only 0.1.0).Verified on
dev(2026-10-25):pnpm --filter "@traceai/openai-agents..." run buildpassed (49 s) andpnpm --filter @traceai/openai-agents testpassed: 2 suites, 24 tests, includingrealSdk.test.tsagainst the real@openai/agents0.21 SDK (55 s).🤖 Generated with Claude Code