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
5 changes: 5 additions & 0 deletions docs/platforms/javascript/common/agent-tracing/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ As of SDK version `11.0.0`, Sentry auto-instruments the most popular AI SDKs and
title: "Together AI",
icon: "together-ai",
},
{
to: "/configuration/integrations/typesafe/",
title: "TypeSafe",
icon: "typesafe-ai",
},
{
to: "/agent-tracing/mastra/",
href: "/platforms/javascript/guides/mastra/",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
title: TypeSafe
description: "Adds instrumentation for TypeSafe Jev evaluations. (default)"
supportedCategories:
- server
- serverless
notSupported:
- javascript.cloudflare
- javascript.mastra
---

<Alert>

Requires Sentry SDK version `11.1.0` or higher.

</Alert>

_Import name: `Sentry.typesafeIntegration`_

This integration is enabled by default when <PlatformLink to="/tracing/">tracing</PlatformLink> is enabled. To customize it, see [Modifying Default Integrations](./../#modifying-default-integrations).

The `typesafeIntegration` adds instrumentation for [`@typesafe-ai/sdk`](https://www.npmjs.com/package/@typesafe-ai/sdk) to capture <PlatformLink to="/agent-tracing/">agent tracing</PlatformLink> `gen_ai.evaluate` spans, recording model, token usage, latency, and (when enabled) evaluation inputs and answers.

If you call Jev through Vercel AI SDK's `experimental_evaluate()`, see the [Vercel AI integration](/platforms/javascript/guides/node/configuration/integrations/vercelai/#trace-jev-evaluations) instead.

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Tracing must be enabled for agent tracing to work
tracesSampleRate: 1.0,
integrations: [Sentry.typesafeIntegration()],
});
```

<PlatformSection supported={["javascript.nextjs"]}>

Run TypeSafe calls in the Node.js runtime. This automatic instrumentation isn't available in the Edge runtime.

</PlatformSection>

<PlatformSection supported={["javascript.deno"]}>

On Deno, preload Sentry's import hook so the TypeSafe SDK can be instrumented:

```bash
deno run --allow-net --allow-env --allow-read --allow-sys --allow-write --preload=npm:@sentry/deno/import app.ts
```

</PlatformSection>

<PlatformSection supported={["javascript.bun", "javascript.elysia"]}>

On Bun, automatic instrumentation requires a build with `sentryBunPlugin()` and `@typesafe-ai/sdk` included in the bundle:

```typescript {filename:build.ts}
import { sentryBunPlugin } from "@sentry/bun/plugin";

await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
target: "bun",
plugins: [sentryBunPlugin()],
});
```

For unbundled applications started with `bun run`, use [Manual Instrumentation](#manual-instrumentation).

</PlatformSection>

## Supported Operations

Tracing support is added to `TypeSafeClient.systemOne()` calls to evaluate state against a set of questions using Jev. Each call creates a `gen_ai.evaluate` span. Recorded answers include probabilities and confidence values when returned by TypeSafe.

## Supported Versions

- `@typesafe-ai/sdk`: `>=0.5.0 <1`

## Options

Evaluation state and answers can contain sensitive data. Input and output recording are enabled by default. To disable them for TypeSafe, configure the integration explicitly:

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
integrations: [
Sentry.typesafeIntegration({
recordInputs: false,
recordOutputs: false,
}),
],
});
```

### `recordInputs`

_Type: `boolean` (optional)_

Records evaluation `state` and `questions`. Defaults to `dataCollection.genAI.inputs`, which is `true` by default.

### `recordOutputs`

_Type: `boolean` (optional)_

Records evaluation `answers`. Defaults to `dataCollection.genAI.outputs`, which is `true` by default.

<PlatformSection notSupported={["javascript.deno", "javascript.solidstart"]}>

## Manual Instrumentation

_Import name: `Sentry.instrumentTypeSafeClient`_

If your application does not use automatic instrumentation, wrap your TypeSafe client after setting up Sentry. Use the returned client for your `systemOne()` calls.

<PlatformSection supported={["javascript.hono"]}>

Import Sentry from the entry point for your runtime: `@sentry/hono/node`, `@sentry/hono/bun`, or `@sentry/hono/cloudflare`.

</PlatformSection>

<PlatformSection notSupported={["javascript.hono"]}>

```javascript
import * as Sentry from "___SDK_PACKAGE___";
```

</PlatformSection>

```javascript
import { TypeSafeClient, choice } from "@typesafe-ai/sdk";

const typesafe = new TypeSafeClient({ apiKey: "your-typesafe-api-key" });
const client = Sentry.instrumentTypeSafeClient(typesafe, {
recordInputs: false,
recordOutputs: false,
});

const result = await client.systemOne({
state: "I was charged twice. Please refund the extra charge.",
questions: {
department: choice("Which team should handle this?", {
billing: "Charges and refunds",
technical: "Bugs and outages",
}),
},
});
```

Use one instrumentation approach for each client. If automatic instrumentation is already active, you don't need to wrap the client.

</PlatformSection>
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,43 @@ By default, tracing support is added to the following `ai` functions:
- `embed()`
- `embedMany()`
- `rerank()`
- `experimental_evaluate()` — requires Sentry SDK `11.1.0` or higher and AI SDK 7

Plus `generate()` and `stream()` on [`ToolLoopAgent`](https://ai-sdk.dev/docs/agents/overview#toolloopagent-class).

## Trace Jev Evaluations

With Sentry SDK `11.1.0` or higher and AI SDK 7, `vercelAIIntegration` automatically traces `experimental_evaluate()` calls, including calls to TypeSafe's Jev model through Vercel AI Gateway. Keep your existing Sentry setup with tracing enabled; no additional integration or telemetry registration is needed.

Configure [AI Gateway authentication](https://ai-sdk.dev/docs/ai-sdk-core/evaluation#default-provider-strings) with `AI_GATEWAY_API_KEY` or Vercel OIDC, then call `experimental_evaluate()`:

```javascript
import { experimental_evaluate } from "ai";

const result = await experimental_evaluate({
model: "typesafe-ai/jev",
state: "I was charged twice. Please refund the extra charge.",
questions: {
department: {
type: "choice",
instructions: "Which team should handle this?",
criteria: {
billing: "Charges and refunds",
technical: "Bugs and outages",
},
},
},
});

console.log(result.answers.department);
```

Each call creates a `gen_ai.evaluate` span with model, latency, and token usage when available. When recording is enabled, Sentry captures `state` and `questions` as input messages and `answers` as output messages. For TypeSafe answers, Sentry also includes confidence values from `providerMetadata.typesafe.confidence` when present.

Evaluation inputs and outputs follow the same [`recordInputs`](#recordinputs) and [`recordOutputs`](#recordoutputs) options as other Vercel AI calls. Disable these options if evaluation state or answers contain sensitive data.

The AI SDK's [evaluation API](https://ai-sdk.dev/docs/ai-sdk-core/evaluation) is experimental and may change in patch releases. If you use `TypeSafeClient.systemOne()` directly instead, see the [TypeSafe integration](/platforms/javascript/guides/node/configuration/integrations/typesafe/).

## Supported Versions

- `ai`: `>=3.0.0 <=7`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`firebaseIntegration`](./firebase) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`amqplibIntegration`](./amqplib) | | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`firebaseIntegration`](./firebase) | ✓ | | ✓ | |
| [`bunRuntimeMetricsIntegration`](./bunruntimemetrics) | | | | ✓ |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | | ✓ |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`eventLoopBlockIntegration`](./event-loop-block) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`firebaseIntegration`](./firebase) | ✓ | | ✓ | |
| [`amqplibIntegration`](./amqplib) | | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`eventLoopBlockIntegration`](./event-loop-block) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
Comment thread
sentry-junior[bot] marked this conversation as resolved.
| [`firebaseIntegration`](./firebase) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ Depending on whether an integration enhances the functionality of a particular r
| [`mistralAIIntegration`](./mistral) | ✓ | | ✓ | |
| [`groqIntegration`](./groq) | ✓ | | ✓ | |
| [`togetherAIIntegration`](./together-ai) | ✓ | | ✓ | |
| [`typesafeIntegration`](./typesafe) | ✓ | | ✓ | |
| [`zodErrorsIntegration`](./zodErrors) | | | | ✓ |
| [`pinoIntegration`](./pino) | | ✓ | | |
Loading