Skip to content

Commit 5117a12

Browse files
committed
feat: added wandb tracing to the agent
1 parent 10cd696 commit 5117a12

File tree

7 files changed

+434
-160
lines changed

7 files changed

+434
-160
lines changed

bun.lock

Lines changed: 51 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
"@hono/zod-validator": "^0.4.3",
4040
"@inkjs/ui": "^2.0.0",
4141
"@modelcontextprotocol/sdk": "^1.12.1",
42+
"@opentelemetry/api": "^1.9.0",
43+
"@opentelemetry/exporter-trace-otlp-proto": "^0.210.0",
44+
"@opentelemetry/sdk-trace-base": "^2.1.0",
4245
"@pppp606/ink-chart": "^0.2.4",
4346
"chalk": "^5.4.1",
4447
"commander": "^13.1.0",

scripts/trace-test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Diagnostic: verify OTel spans reach W&B Weave end-to-end
3+
*
4+
* Usage: WANDB_API_KEY=<key> WANDB_PROJECT_ID=<entity/project> bun run scripts/trace-test.ts
5+
*/
6+
import { maybeSetOtelProviders } from '@google/adk';
7+
import { trace } from '@opentelemetry/api';
8+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
9+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
10+
11+
const apiKey = process.env.WANDB_API_KEY;
12+
const projectId = process.env.WANDB_PROJECT_ID;
13+
14+
if (!apiKey || !projectId) {
15+
console.error('Set WANDB_API_KEY and WANDB_PROJECT_ID');
16+
process.exit(1);
17+
}
18+
19+
const url = 'https://trace.wandb.ai/otel/v1/traces';
20+
const auth = Buffer.from(`api:${apiKey}`).toString('base64');
21+
22+
console.log('Config:');
23+
console.log(' url:', url);
24+
console.log(' project_id:', projectId);
25+
26+
const otlpExporter = new OTLPTraceExporter({
27+
url,
28+
headers: {
29+
Authorization: `Basic ${auth}`,
30+
project_id: projectId,
31+
},
32+
});
33+
34+
// Use BatchSpanProcessor directly (no WeaveSpanProcessor) to test raw export
35+
const batchProcessor = new BatchSpanProcessor(otlpExporter);
36+
maybeSetOtelProviders([{ spanProcessors: [batchProcessor] }]);
37+
38+
const tracer = trace.getTracer('solenoid');
39+
40+
// Test span with sanitized name (no special chars) + Weave thread attributes
41+
const span = tracer.startSpan('diagnostic_agent_run');
42+
span.setAttribute('gen_ai.agent.name', 'diagnostic_agent');
43+
span.setAttribute('gen_ai.operation.name', 'invoke_agent');
44+
span.setAttribute('wandb.thread_id', 'test-thread-123');
45+
span.setAttribute('wandb.is_turn', true);
46+
span.end();
47+
48+
console.log('Span created and ended. Flushing to Weave...');
49+
50+
// Call forceFlush directly to surface any export errors
51+
try {
52+
await batchProcessor.forceFlush();
53+
console.log('Export OK! Check: https://wandb.ai/' + projectId + '/weave/traces');
54+
} catch (e) {
55+
console.error('Export FAILED:', e);
56+
}
57+
58+
await batchProcessor.shutdown();

0 commit comments

Comments
 (0)