You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **Observe** stage is about understanding how your deployed generative AI capabilities perform in the real world. After creating and evaluating a capability, observing its production behavior is crucial for identifying unexpected issues, tracking costs, and gathering the data needed for future improvements.
10
11
@@ -22,7 +23,39 @@ The easiest way to get started is by wrapping your existing AI model client. The
22
23
23
24
The `wrapAISDKModel` function takes an existing AI model object and returns an instrumented version that will automatically generate trace data for every call.
@@ -46,7 +96,7 @@ While `wrapAISDKModel` handles the automatic instrumentation, the `withSpan` fun
46
96
47
97
import { withSpan } from'@axiomhq/ai';
48
98
import { generateText } from'ai';
49
-
import { geminiFlash } from'@/shared/gemini';
99
+
import { gpt4o } from'@/shared/openai';
50
100
51
101
exportdefaultasyncfunction Page() {
52
102
const userId =123;
@@ -57,7 +107,7 @@ export default async function Page() {
57
107
span.setAttribute('user_id', userId);
58
108
59
109
returngenerateText({
60
-
model: geminiFlash, // Use the wrapped model
110
+
model: gpt4o, // Use the wrapped model
61
111
messages: [
62
112
{
63
113
role: 'user',
@@ -71,46 +121,118 @@ export default async function Page() {
71
121
}
72
122
```
73
123
124
+
### Instrumenting tool calls with `wrapTool`
74
125
75
-
## Setting up instrumentation
126
+
For many AI capabilities, the LLM call is only part of the story. If your capability uses tools to interact with external data or services, observing the performance and outcome of those tools is critical. The Axiom AI SDK provides the `wrapTool` and `wrapTools` functions to automatically instrument your Vercel AI SDK tool definitions.
76
127
77
-
The Axiom AI SDK is built on the OpenTelemetry standard. To send traces, you need to configure a Node.js or edge-compatible tracer that exports data to Axiom.
128
+
The `wrapTool` helper takes your tool's name and its definition and returns an instrumented version. This wrapper creates a dedicated child span for every tool execution, capturing its arguments, output, and any errors.
78
129
79
-
### Configuring the tracer
130
+
```typescript
131
+
// src/app/generate-text/page.tsx
132
+
import { tool } from'ai';
133
+
import { z } from'zod';
134
+
import { wrapTool } from'@axiomhq/ai';
135
+
import { generateText } from'ai';
136
+
import { gpt4o } from'@/shared/openai';
137
+
138
+
// In your generateText call, provide wrapped tools
139
+
const { text, toolResults } =awaitgenerateText({
140
+
model: gpt4o,
141
+
messages: [
142
+
{ role: 'system', content: 'You are a helpful assistant.' },
143
+
{ role: 'user', content: 'How do I get from Paris to Berlin?' },
144
+
],
145
+
tools: {
146
+
// Wrap each tool with its name
147
+
findDirections: wrapTool(
148
+
'findDirections', // The name of the tool
149
+
tool({
150
+
description: 'Find directions to a location',
151
+
inputSchema: z.object({
152
+
from: z.string(),
153
+
to: z.string(),
154
+
}),
155
+
execute: async (params) => {
156
+
// Your tool logic here...
157
+
return { directions: `To get from ${params.from} to ${params.to}, use a teleporter.` };
158
+
},
159
+
})
160
+
)
161
+
}
162
+
});
163
+
```
80
164
81
-
You must configure an OTLP trace exporter pointing to your Axiom instance. This is typically done in a dedicated instrumentation file that is loaded before your application starts.
165
+
### Complete instrumentation example
166
+
167
+
<Accordiontitle="Full end-to-end code example">
168
+
Here's how all three instrumentation functions work together in a single, real-world example:
// You have access to the OTel span to add custom attributes
203
+
span.setAttribute('user_id', userId);
204
+
205
+
returngenerateText({
206
+
model: gpt4o, // Use the wrapped model
207
+
messages: [
208
+
{ role: 'system', content: 'You are a helpful assistant.' },
209
+
{ role: 'user', content: 'How do I get from Paris to Berlin?' },
210
+
],
211
+
tools: {
212
+
findDirections: findDirectionsTool, // Use the wrapped tool
213
+
},
214
+
});
215
+
});
109
216
110
-
// Initialize the Axiom AI SDK with the tracer
111
-
initAxiomAI({ tracer });
217
+
return <p>{text}</p>;
218
+
}
112
219
```
113
220
221
+
This demonstrates the three key steps to rich observability:
222
+
1.**`wrapAISDKModel`**: Automatically captures telemetry for the LLM provider call
223
+
2.**`wrapTool`**: Instruments the tool execution with detailed spans
224
+
3.**`withSpan`**: Creates a parent span that ties everything together under a business capability
225
+
</Accordion>
226
+
227
+
## Setting up instrumentation
228
+
229
+
The Axiom AI SDK is built on the OpenTelemetry standard. To send traces, you need to configure a Node.js or edge-compatible tracer that exports data to Axiom.
230
+
231
+
### Configuring the tracer
232
+
233
+
You must configure an OTLP trace exporter pointing to your Axiom instance. This is typically done in a dedicated instrumentation file that is loaded before your application starts.
234
+
235
+
<AIEngineeringInstrumentationSnippet />
114
236
115
237
Your Axiom credentials (`AXIOM_TOKEN` and `AXIOM_DATASET`) should be set as environment variables.
116
238
@@ -129,6 +251,9 @@ Key attributes include:
129
251
*`gen_ai.prompt`: The full, rendered prompt or message history sent to the model (as a JSON string).
130
252
*`gen_ai.completion`: The full response from the model, including tool calls (as a JSON string).
131
253
*`gen_ai.response.finish_reasons`: The reason the model stopped generating tokens (e.g., `stop`, `tool-calls`).
254
+
***`gen_ai.tool.name`**: The name of the executed tool.
255
+
***`gen_ai.tool.arguments`**: The arguments passed to the tool (as a JSON string).
256
+
***`gen_ai.tool.message`**: The result returned by the tool (as a JSON string).
Copy file name to clipboardExpand all lines: ai-engineering/overview.mdx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The core stages are:
21
21
22
22
***Create**: Define a new AI capability, prototype it with various models, and gather reference examples to establish ground truth.
23
23
***Measure**: Systematically evaluate the capability's performance against reference data using custom graders to score for accuracy, quality, and cost.
24
-
***Observe**: Cultivate the capability in production by collecting rich telemetry on every execution. Use online evaluations to monitor for performance degradation and discover edge cases.
24
+
***Observe**: Cultivate the capability in production by collecting rich telemetry on every LLM call and tool execution. Use online evaluations to monitor for performance degradation and discover edge cases.
25
25
***Iterate**: Use insights from production to refine prompts, augment reference datasets, and improve the capability over time.
This guide provides the steps to install and configure the [`@axiomhq/ai`](https://github.com/axiomhq/ai) SDK. Once configured, you can follow the Rudder workflow to create, measure, observe, and iterate on your AI capabilities.
8
10
9
11
## Prerequisites
@@ -98,41 +100,7 @@ bun add \
98
100
99
101
</CodeGroup>
100
102
101
-
```typescript
102
-
// src/instrumentation.ts
103
-
104
-
import'dotenv/config'; // Make sure to load environment variables
0 commit comments