Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/auto-typescript-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Zero-code agent (@traceai/auto) tests

# The registry test reads every typescript/packages/traceai_* manifest, and the
# integration tests load the built instrumentors, so the whole workspace is built.
on:
pull_request:
branches: [dev, main]
paths:
- 'typescript/packages/traceai_auto/**'
- 'typescript/packages/fi-core/**'
- 'typescript/packages/fi-semantic-conventions/**'
- 'typescript/packages/traceai_*/package.json'
- 'spec/auto-instrumentation/**'
- 'typescript/pnpm-lock.yaml'
- 'typescript/package.json'
- 'typescript/tsconfig*'
- '.github/workflows/auto-typescript-tests.yml'
push:
branches: [dev]
workflow_dispatch:

permissions:
contents: read

jobs:
auto:
name: '@traceai/auto suite'
runs-on: ubuntu-24.04
timeout-minutes: 45
defaults:
run:
working-directory: typescript
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '22'
- run: corepack enable
- name: Install the workspace
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Build every package in dependency order
run: pnpm run build:ordered
- name: Run the @traceai/auto suite
run: pnpm --filter @traceai/auto test
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"python/frameworks/weaviate": "0.1.2",
"python/frameworks/xai": "0.1.1",
"python/traceai": "0.1.0",
"typescript/packages/fi-core": "1.2.0",
"typescript/packages/fi-core": "1.2.1",
"typescript/packages/fi-semantic-conventions": "1.1.0",
"typescript/packages/traceai_anthropic": "0.1.5",
"typescript/packages/traceai_auto": "0.1.0",
Expand Down
5 changes: 5 additions & 0 deletions typescript/packages/fi-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.2.1] - pending release
### Fix
- **Spans no longer carry the process command line or the OS user.** 1.2.0 added OpenTelemetry's full process detector to every provider resource, so `process.command_args`, `process.command`, `process.owner`, `process.executable.path` and `process.pid` were exported with every span. Command-line flags can hold secrets. By default fi-core now detects only `process.runtime.name`, `process.runtime.version` and `process.runtime.description`, as it detected nothing before 1.2.0.
- To opt in, set the OpenTelemetry Node variable `OTEL_NODE_RESOURCE_DETECTORS` to a comma-separated list of `host`, `os` and `process`, or `all` / `none`. `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` are always applied.

## [1.2.0] - pending release
### Changed
- 1.2.0 exports the typed session.id set with setSession; other session-named attributes remain masked.
Expand Down
7 changes: 7 additions & 0 deletions typescript/packages/fi-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ Other provider structures have no new exception without catalog/source evidence.
resource identity, `OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES` and an optional
application `resource` are preserved.

Resource detection is minimal by default: the provider adds the Node.js runtime
name and version (`process.runtime.*`) and nothing that identifies the machine,
the OS user or the command line (which can hold secrets passed as flags). To add
OpenTelemetry's host, OS or full process attributes, set
`OTEL_NODE_RESOURCE_DETECTORS` to a comma-separated list of `host`, `os` and
`process`, or to `all`; `none` turns detection off.

`FITracer` applies the shared privacy policy before SDK attribute-value truncation.
Its library spans use the same deterministic count-limit projection as wire spans
(spec A7), including late output/usage updates. Protected attributes are reserved
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/fi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@traceai/fi-core",
"version": "1.2.0",
"version": "1.2.1",
"description": "OpenTelemetry tracing for AI applications: tracer setup, span helpers, and exporters for Future AGI.",
"main": "./dist/src/index.js",
"module": "./dist/esm/index.js",
Expand Down
2 changes: 2 additions & 0 deletions typescript/packages/fi-core/scripts/postbuild.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require('node:fs');
// tsc does not emit privacy.json (it is not in any tsconfig include), so these byte-exact copies are
// the only ones: a consumer's `tsc --build` reference to fi-core cannot reserialize them.
for (const dir of ['dist/src', 'dist/esm', 'dist/esnext']) {
fs.copyFileSync('src/privacy.json', `${dir}/privacy.json`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals';
import { userInfo } from 'node:os';
import { FITracerProvider } from '../otel';

jest.mock('@opentelemetry/exporter-trace-otlp-http', () => ({
OTLPTraceExporter: jest.fn().mockImplementation(() => ({
export: jest.fn((_spans: any, callback: any) => callback({ code: 0 })),
shutdown: jest.fn(() => Promise.resolve()),
forceFlush: jest.fn(() => Promise.resolve()),
})),
}));

// A secret passed on the command line, as `node app.js --api-key=...` would.
const SECRET_FLAG = '--api-key=sk-test-0000000000000000';

// The resource every exported span carries.
function exportedResourceAttributes(): Record<string, unknown> {
const provider = new FITracerProvider();
const span = provider.getTracer('resource-detection-test').startSpan('probe') as any;
span.end();
return { ...span.resource.attributes };
}

describe('FITracerProvider resource detection', () => {
const originalEnv = process.env;
const originalArgv = process.argv;

beforeEach(() => {
process.env = { ...originalEnv };
delete process.env.OTEL_NODE_RESOURCE_DETECTORS;
process.argv = [...originalArgv, SECRET_FLAG];
});

afterEach(() => {
process.env = originalEnv;
process.argv = originalArgv;
});

it('exports no command line, OS user, executable path or host by default', () => {
const attributes = exportedResourceAttributes();
for (const key of ['process.command', 'process.command_args', 'process.owner', 'process.executable.path', 'process.executable.name', 'process.pid', 'host.name', 'host.id', 'os.type']) {
expect(attributes).not.toHaveProperty([key]);
}
// service.name keeps OpenTelemetry's own default, unknown_service:<argv0>, so the
// executable path is checked by key above rather than by value.
const serialized = JSON.stringify(attributes);
expect(serialized).not.toContain('sk-test-0000000000000000');
expect(serialized).not.toContain(JSON.stringify(userInfo().username));
});

it('keeps the runtime name and version by default', () => {
const attributes = exportedResourceAttributes();
expect(attributes['process.runtime.name']).toBe('nodejs');
expect(attributes['process.runtime.version']).toBe(process.versions.node);
});

it('keeps OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES', () => {
process.env.OTEL_SERVICE_NAME = 'checkout';
process.env.OTEL_RESOURCE_ATTRIBUTES = 'deployment.environment.name=staging';
const attributes = exportedResourceAttributes();
expect(attributes['service.name']).toBe('checkout');
expect(attributes['deployment.environment.name']).toBe('staging');
});

it('adds full process detection only when OTEL_NODE_RESOURCE_DETECTORS asks for it', () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'env,process';
const attributes = exportedResourceAttributes();
expect(attributes['process.command_args']).toEqual(expect.arrayContaining([SECRET_FLAG]));
expect(attributes['process.pid']).toBe(process.pid);
expect(attributes).not.toHaveProperty(['host.name']);
});

it('treats all as host, os and process, and none as no detection', () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all';
const all = exportedResourceAttributes();
expect(all).toHaveProperty(['host.name']);
expect(all).toHaveProperty(['os.type']);
expect(all).toHaveProperty(['process.pid']);

process.env.OTEL_NODE_RESOURCE_DETECTORS = 'none';
process.env.OTEL_SERVICE_NAME = 'checkout';
const none = exportedResourceAttributes();
expect(Object.keys(none).filter((key) => /^(process|host|os)\./.test(key))).toEqual([]);
expect(none['service.name']).toBe('checkout');
});
});
21 changes: 19 additions & 2 deletions typescript/packages/fi-core/src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
SimpleSpanProcessor as OTelSimpleSpanProcessor,
IdGenerator,
} from "@opentelemetry/sdk-trace-node";
import { Resource, resourceFromAttributes, detectResources, defaultResource, envDetector, processDetector } from "@opentelemetry/resources";
import { Resource, ResourceDetector, resourceFromAttributes, detectResources, defaultResource, envDetector, hostDetector, osDetector, processDetector } from "@opentelemetry/resources";
import { privacyFilter, PrivacyOptions } from "./export-privacy";
import { credentialSecrets } from "./privacy-runtime";
import { seedSecrets } from "./secrets";
Expand Down Expand Up @@ -67,9 +67,26 @@ export function withExportPrivacy(exporter: SpanExporter, options: ExportPrivacy
privacyDestinations.add(guarded);
return guarded;
}
// The full process detector exports the command line (which can hold secrets passed as
// flags), the OS user name and the executable path. By default only the runtime is kept.
const runtimeDetector: ResourceDetector = {
detect(config) {
const attributes = processDetector.detect(config).attributes ?? {};
return { attributes: Object.fromEntries(Object.entries(attributes).filter(([key]) => key.startsWith("process.runtime."))) };
},
};
const OPT_IN_DETECTORS: Record<string, ResourceDetector> = { host: hostDetector, os: osDetector, process: processDetector };
// OTEL_NODE_RESOURCE_DETECTORS (the OpenTelemetry Node variable) opts in to host, os and
// process detection. OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES are always applied.
function resourceDetectors(): ResourceDetector[] {
const names = (process.env.OTEL_NODE_RESOURCE_DETECTORS ?? "").split(",").map((name) => name.trim().toLowerCase()).filter(Boolean);
if (!names.length) return [envDetector, runtimeDetector];
const chosen = names.includes("none") ? [] : names.includes("all") ? Object.keys(OPT_IN_DETECTORS) : names;
return [envDetector, ...chosen.flatMap((name) => OPT_IN_DETECTORS[name] ?? [])];
}
function applicationResource(resource?: Resource): Resource {
const application = resource && typeof (resource as any).getRawAttributes === "function" ? resource : resourceFromAttributes(resource?.attributes ?? {});
return defaultResource().merge(detectResources({ detectors: [envDetector, processDetector] })).merge(application);
return defaultResource().merge(detectResources({ detectors: resourceDetectors() })).merge(application);
}
import { v4 as uuidv4 } from "uuid"; // For UUID generation

Expand Down
3 changes: 1 addition & 2 deletions typescript/packages/fi-core/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"resolveJsonModule": true
},
"include": [
"src/**/*.ts",
"src/**/*.json"
"src/**/*.ts"
],
"references": [],
"exclude": [
Expand Down
3 changes: 1 addition & 2 deletions typescript/packages/fi-core/tsconfig.esnext.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"resolveJsonModule": true
},
"include": [
"src/**/*.ts",
"src/**/*.json"
"src/**/*.ts"
],
"references": [],
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/fi-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"baseUrl": "./src",
"resolveJsonModule": true
},
"include": ["src/**/*.ts", "src/**/*.json", "test/**/*.ts"],
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["src/**/*.test.ts", "src/**/__tests__/**", "test/**/*.ts"],
"references": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./dist/index.d.ts",
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
"files": ["dist", "plugin", "LICENSE"],
"scripts": {"build": "tsc -p tsconfig.json && node build.cjs", "test": "node --test test/*.test.cjs"},
"scripts": {"prepare": "pnpm run build", "build": "tsc -p tsconfig.json && node build.cjs", "test": "node --test test/*.test.cjs"},
"dependencies": {"@traceai/agent-core": "workspace:^", "proper-lockfile": "4.1.2"},
"devDependencies": {"@types/node": "^22.15.29", "typescript": "^5.8.3", "esbuild": "0.25.5"},
"engines": {"node": ">=22.16.0"},
Expand Down
8 changes: 7 additions & 1 deletion typescript/packages/traceai_auto/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ test.each(["api_key", "secret_key"])("S7 ignored %s from every config/profile so
});
test("registry covers every instrumentation package and records exported class and targets", () => {
const packages = resolve(__dirname, "../..");
const paths = readdirSync(packages).filter(p => p.startsWith("traceai_") && p !== "traceai_auto");
// Coding-agent tracers (@traceai/agent-core and the hook plugins built on it) are set up
// with `npx @traceai/agents`, not loaded by the zero-code agent, so they are not listed here.
const codingAgent = (path: string) => {
const manifest = JSON.parse(readFileSync(join(packages, path, "package.json"), "utf8"));
return manifest.name === "@traceai/agent-core" || "@traceai/agent-core" in (manifest.dependencies ?? {});
};
const paths = readdirSync(packages).filter(p => p.startsWith("traceai_") && p !== "traceai_auto" && !codingAgent(p));
expect(integrations).toHaveLength(paths.length);
for (const path of paths) {
const manifest = JSON.parse(readFileSync(join(packages, path, "package.json"), "utf8"));
Expand Down
6 changes: 3 additions & 3 deletions typescript/packages/traceai_auto/test/safety.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test("consumer cancellation is OK with partial output and incomplete marker", as
expect(spans[0].attributes["error.type"]).toBeUndefined();
});
test.each([["gzip", gzipSync], ["deflate", deflateSync]] as const)("encoded %s responses decode before parsing but retain application bytes", async (encoding, compress) => {
const bytes = compress(partial); globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "text/event-stream", "content-encoding": encoding } })); const h = hook();
const bytes = compress(partial); globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "text/event-stream", "content-encoding": encoding } })); const h = hook();
expect(Buffer.from(await (await fetch(url, init)).arrayBuffer())).toEqual(bytes); await Promise.all([...h.pending]);
expect(spans[0].attributes["output.value"]).toBe("partial"); expect(spans[0].attributes["traceai.wire.undecoded_encoding"]).toBeUndefined();
});
Expand Down Expand Up @@ -93,7 +93,7 @@ test("native fetch response metadata prevents re-decoding plain-text transcripti
});
test("decompressed output is bounded independently of compressed size", async () => {
const bytes = gzipSync('data: {"choices":[{"delta":{"content":"' + "x".repeat(10000) + '"}}]}\n\n');
globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "text/event-stream", "content-encoding": "gzip" } })); const h = hook(512);
globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "text/event-stream", "content-encoding": "gzip" } })); const h = hook(512);
await (await fetch(url, init)).arrayBuffer(); await Promise.all([...h.pending]);
expect(spans[0].attributes["traceai.wire.truncated"]).toBe(true); expect(spans[0].attributes["output.value"]).toBeUndefined();
});
Expand Down Expand Up @@ -164,7 +164,7 @@ test("cloning a mutable custom Response preserves metadata and independent heade
});
test.each([["gzip", gzipSync], ["deflate", deflateSync], ["br", brotliCompressSync]] as const)("%s ElevenLabs JSON audio decodes before base64 counting", async (encoding, compress) => {
const text = JSON.stringify({ audio_base64: Buffer.alloc(128).toString("base64") }), bytes = compress(text);
globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "application/json", "content-encoding": encoding } })); const h = hook();
globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "application/json", "content-encoding": encoding } })); const h = hook();
const target = "https://api.elevenlabs.io/v1/text-to-speech/voice/with-timestamps";
expect(Buffer.from(await (await fetch(target, { ...init, body: '{"text":"hello","model_id":"tts"}' })).arrayBuffer())).toEqual(bytes);
await Promise.all([...h.pending]); expect(spans).toHaveLength(1);
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_claude_code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"README.md"
],
"scripts": {
"prepare": "pnpm run build",
"build": "tsc -p tsconfig.json && esbuild src/hook.ts --bundle --platform=node --format=cjs --main-fields=module,main --outfile=dist/hook.cjs",
"test": "node --test test/*.test.cjs",
"test:binary": "node test/binary.cjs"
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_codex_plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"LICENSE"
],
"scripts": {
"prepare": "pnpm run build",
"build": "tsc -p tsconfig.json && node build.cjs",
"test": "node --test test/*.test.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_cursor_plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
},
"scripts": {
"prepare": "pnpm run build",
"build": "tsc -p tsconfig.json && node build.cjs",
"test": "node --test test/*.test.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_goose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"README.md"
],
"scripts": {
"prepare": "pnpm run build",
"build": "tsc -p tsconfig.json && esbuild src/hook.ts --bundle --platform=node --format=cjs --target=node22 --outfile=dist/hook.cjs",
"test": "node --test test/*.test.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_grok_plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"LICENSE"
],
"scripts": {
"prepare": "pnpm run build",
"build": "tsc -p tsconfig.json",
"test": "node --test test/*.test.cjs"
},
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/traceai_openclaw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./dist/index.d.ts",
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
"files": ["dist", "native", "README.md", "LICENSE"],
"scripts": { "build": "tsc -p tsconfig.json", "test": "node --test test/*.test.cjs" },
"scripts": { "prepare": "pnpm run build", "build": "tsc -p tsconfig.json", "test": "node --test test/*.test.cjs" },
"engines": { "node": ">=24.16.0 <25" },
"dependencies": {
"@traceai/agent-core": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/traceai_opencode_plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "./dist/index.d.ts",
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
"files": ["dist", "README.md", "LICENSE"],
"scripts": { "build": "tsc -p tsconfig.json", "test": "node --test test/*.test.mjs" },
"scripts": { "prepare": "pnpm run build", "build": "tsc -p tsconfig.json", "test": "node --test test/*.test.mjs" },
"engines": { "node": ">=22.16.0" },
"dependencies": { "@opencode/plugin": "2.2.5", "@opencode/client": "2.2.5", "@traceai/agent-core": "workspace:^" },
"devDependencies": { "typescript": "^5.8.3", "@types/node": "^22.15.29" },
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/traceai_vscode_extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"files": ["dist", "extension.vsix", "LICENSE"],
"scripts": {
"build": "tsc -p tsconfig.json && node scripts/package.cjs",
"prepare": "pnpm run build",
"test": "node --test test/*.test.cjs"
},
"engines": {"node": ">=22.16.0"},
Expand Down
Loading