Skip to content

Commit 56f460d

Browse files
jerryliang64claude
andauthored
feat: add @eggjs/agent-tracing package for AI agent tracing (#412)
## Summary - Add new `@eggjs/agent-tracing` package for AI agent LLM call tracing - Support tracing LangGraph-based and Claude Agent SDK-based AI agent invocations with structured span/trace data - `LangGraphTracer`: extends LangChain `BaseTracer`, hooks into graph lifecycle events - `ClaudeAgentTracer`: converts Claude SDK messages to LangChain Run format, supports both batch and streaming modes - `TracingService`: shared log formatting, OSS upload, and log service sync - `AbstractOssClient`/`AbstractLogServiceClient`: IoC injection interfaces for pluggable backends Adapted from eggjs/egg#5822 for tegg monorepo conventions (CJS module system, mocha tests, lerna versioning). ## Test plan - [x] All 52 mocha tests passing (`npm test --workspace=core/agent-tracing`) - [x] TypeScript type checking passes (`tsc --noEmit`) - [x] Package structure follows existing `core/*` conventions 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added comprehensive tracing for Claude agents and LangGraph workflows with configurable agent naming. * Optional OSS uploads and log-service syncing for large trace fields and centralized trace management. * Published a new package with root and subpath exports for tracer consumers. * **Tests** * Added extensive unit and integration tests covering tracer behavior, sessions, env handling, and error cases. * **Chores** * Added TypeScript build configs and package manifest for the new tracing package. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d4d0006 commit 56f460d

17 files changed

+2299
-0
lines changed

core/agent-tracing/claude.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './index';
2+
export { ClaudeAgentTracer, TraceSession } from './src/ClaudeAgentTracer';

core/agent-tracing/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './src/types';
2+
export { AbstractOssClient } from './src/AbstractOssClient';
3+
export { AbstractLogServiceClient } from './src/AbstractLogServiceClient';

core/agent-tracing/langgraph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './index';
2+
export { LangGraphTracer } from './src/LangGraphTracer';

core/agent-tracing/package.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"name": "@eggjs/agent-tracing",
3+
"version": "3.72.0",
4+
"description": "Tracing support for AI agents (LangGraph, Claude Agent SDK)",
5+
"keywords": [
6+
"agent",
7+
"claude",
8+
"egg",
9+
"langchain",
10+
"langgraph",
11+
"tegg",
12+
"tracing",
13+
"typescript"
14+
],
15+
"main": "dist/index.js",
16+
"files": [
17+
"dist/**/*.js",
18+
"dist/**/*.d.ts"
19+
],
20+
"typings": "dist/index.d.ts",
21+
"exports": {
22+
".": {
23+
"types": "./dist/index.d.ts",
24+
"default": "./dist/index.js"
25+
},
26+
"./claude": {
27+
"types": "./dist/claude.d.ts",
28+
"default": "./dist/claude.js"
29+
},
30+
"./langgraph": {
31+
"types": "./dist/langgraph.d.ts",
32+
"default": "./dist/langgraph.js"
33+
},
34+
"./package.json": "./package.json"
35+
},
36+
"scripts": {
37+
"test": "node --eval \"process.exit(parseInt(process.versions.node) < 18 ? 0 : 1)\" || cross-env NODE_ENV=test NODE_OPTIONS='--no-deprecation' mocha",
38+
"clean": "tsc -b --clean",
39+
"tsc": "ut run clean && tsc -p ./tsconfig.json",
40+
"tsc:pub": "ut run clean && tsc -p ./tsconfig.pub.json",
41+
"prepublishOnly": "ut tsc:pub"
42+
},
43+
"homepage": "https://github.com/eggjs/tegg",
44+
"bugs": {
45+
"url": "https://github.com/eggjs/tegg/issues"
46+
},
47+
"repository": {
48+
"type": "git",
49+
"url": "git@github.com:eggjs/tegg.git",
50+
"directory": "core/agent-tracing"
51+
},
52+
"engines": {
53+
"node": ">=18.0.0"
54+
},
55+
"author": "killagu <killa123@126.com>",
56+
"license": "MIT",
57+
"dependencies": {
58+
"@eggjs/tegg-background-task": "^3.72.0",
59+
"@eggjs/core-decorator": "^3.72.0",
60+
"@eggjs/tegg-types": "^3.72.0",
61+
"onelogger": "^1.0.1"
62+
},
63+
"peerDependencies": {
64+
"@anthropic-ai/claude-agent-sdk": ">=0.2.52",
65+
"@langchain/core": ">=1.1.1"
66+
},
67+
"peerDependenciesMeta": {
68+
"@anthropic-ai/claude-agent-sdk": {
69+
"optional": true
70+
},
71+
"@langchain/core": {
72+
"optional": true
73+
}
74+
},
75+
"devDependencies": {
76+
"@anthropic-ai/claude-agent-sdk": "^0.2.52",
77+
"@anthropic-ai/sdk": "^0.78.0",
78+
"@eggjs/tegg-common-util": "^3.72.0",
79+
"@langchain/core": "^1.1.29",
80+
"@langchain/langgraph": "^0.2.74",
81+
"@types/mocha": "^10.0.1",
82+
"@types/node": "^20.2.4",
83+
"cross-env": "^7.0.3",
84+
"mocha": "^10.2.0",
85+
"ts-node": "^10.9.1",
86+
"typescript": "^5.0.4"
87+
},
88+
"publishConfig": {
89+
"access": "public"
90+
}
91+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Abstract log service client for dependency injection.
3+
*
4+
* To enable log service syncing in TracingService, implement this class in your application
5+
* and register it with Tegg IoC. The implementation class MUST be named `LogServiceClient`
6+
* (or use `@SingletonProto({ name: 'logServiceClient' })`) so the container can resolve it.
7+
*
8+
* @example
9+
* ```typescript
10+
* import { SingletonProto } from '@eggjs/core-decorator';
11+
* import { AccessLevel } from '@eggjs/tegg-types';
12+
* import { AbstractLogServiceClient } from '@eggjs/agent-tracing';
13+
*
14+
* // Class name must be LogServiceClient (registers as 'logServiceClient' in the IoC container)
15+
* @SingletonProto({ accessLevel: AccessLevel.PUBLIC })
16+
* export class LogServiceClient extends AbstractLogServiceClient {
17+
* async send(log: string): Promise<void> {
18+
* await fetch('https://log.example.com/api', {
19+
* method: 'POST',
20+
* headers: { 'content-type': 'application/json' },
21+
* body: JSON.stringify({ log }),
22+
* });
23+
* }
24+
* }
25+
* ```
26+
*
27+
* If no implementation is registered, log service syncing is silently skipped.
28+
*/
29+
export abstract class AbstractLogServiceClient {
30+
abstract send(log: string): Promise<void>;
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Abstract OSS client for dependency injection.
3+
*
4+
* To enable OSS uploads in TracingService, implement this class in your application
5+
* and register it with Tegg IoC. The implementation class MUST be named `OssClient`
6+
* (or use `@SingletonProto({ name: 'ossClient' })`) so the container can resolve it.
7+
*
8+
* @example
9+
* ```typescript
10+
* import { SingletonProto } from '@eggjs/core-decorator';
11+
* import { AccessLevel } from '@eggjs/tegg-types';
12+
* import { AbstractOssClient } from '@eggjs/agent-tracing';
13+
*
14+
* // Class name must be OssClient (registers as 'ossClient' in the IoC container)
15+
* @SingletonProto({ accessLevel: AccessLevel.PUBLIC })
16+
* export class OssClient extends AbstractOssClient {
17+
* async put(key: string, content: string | Buffer): Promise<void> {
18+
* // your OSS implementation here
19+
* }
20+
* }
21+
* ```
22+
*
23+
* If no implementation is registered, OSS uploads are silently skipped.
24+
*/
25+
export abstract class AbstractOssClient {
26+
abstract put(key: string, content: string | Buffer): Promise<void>;
27+
}

0 commit comments

Comments
 (0)