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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ supported:
- javascript.aws-lambda
- javascript.azure-functions
- javascript.connect
- javascript.deno
- javascript.express
- javascript.fastify
- javascript.gcp-functions
Expand All @@ -28,7 +29,8 @@ supported:

<Alert>

This integration only works in the Node.js, Cloudflare Workers, Vercel Edge Functions and Bun runtimes. Requires SDK version ``10.6.0` or higher.
Requires SDK version `10.6.0` or higher for Node.js, Cloudflare Workers, Vercel Edge Functions and Bun.
Requires SDK version `10.12.0` or higher for Deno.

</Alert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@ As a prerequisite to setting up AI Agent Monitoring with JavaScript, you'll need

The JavaScript SDK supports automatic instrumentation for some AI libraries. We recommend adding their integrations to your Sentry configuration to automatically capture spans for AI agents.

- <PlatformLink to="/configuration/integrations/vercelai/">
Vercel AI SDK
</PlatformLink>
- <PlatformLink to="/configuration/integrations/openai/">OpenAI</PlatformLink>
- <PlatformLink to="/configuration/integrations/anthropic/">Anthropic</PlatformLink>
- <PlatformLink to="/configuration/integrations/google-genai/">Google Gen AI SDK</PlatformLink>
<PlatformLink to="/configuration/integrations/vercelai/">
- Vercel AI SDK
</PlatformLink>
<PlatformLink
to="/configuration/integrations/openai/"
notSupported={["javascript.deno"]}
>
- OpenAI
</PlatformLink>
<PlatformLink
to="/configuration/integrations/anthropic/"
notSupported={["javascript.deno"]}
>
- Anthropic
</PlatformLink>
<PlatformLink
to="/configuration/integrations/google-genai/"
notSupported={["javascript.deno"]}
>
- Google Gen AI SDK
</PlatformLink>

## Manual Instrumentation

Expand Down
60 changes: 58 additions & 2 deletions src/components/platformLink.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,76 @@
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
import {getCurrentPlatformOrGuide, getPlatform} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';
import {Platform, PlatformGuide} from 'sentry-docs/types';

import {SmartLink} from './smartLink';

function getPlatformsWithFallback(
rootNode: any,
platformOrGuide: Platform | PlatformGuide
) {
const result = [platformOrGuide.key];
let curPlatform: Platform | PlatformGuide | undefined = platformOrGuide;
while (curPlatform?.fallbackPlatform) {
result.push(curPlatform.fallbackPlatform);
curPlatform = getPlatform(rootNode, curPlatform.fallbackPlatform);
}
return result;
}

const isSupported = (
platformKey: string,
supported: string[],
notSupported: string[]
): boolean | null => {
if (supported.length && supported.find(p => p === platformKey)) {
return true;
}
if (notSupported.length && notSupported.find(p => p === platformKey)) {
return false;
}
return null;
};

type Props = {
children: React.ReactNode;
notSupported?: string[];
supported?: string[];
to?: string;
};

export function PlatformLink({children, to}: Props) {
export function PlatformLink({children, to, supported = [], notSupported = []}: Props) {
if (!to) {
return children;
}

const {rootNode, path} = serverContext();
const currentPlatformOrGuide = getCurrentPlatformOrGuide(rootNode, path);

// Check platform support if we have a current platform and support constraints
if (currentPlatformOrGuide && (supported.length > 0 || notSupported.length > 0)) {
const platformsToSearch = getPlatformsWithFallback(rootNode, currentPlatformOrGuide);

let result: boolean | null = null;
// eslint-disable-next-line no-cond-assign
for (let platformKey: string, i = 0; (platformKey = platformsToSearch[i]); i++) {
if (!platformKey) {
continue;
}
result = isSupported(platformKey, supported, notSupported);
if (result === false) {
// Platform is not supported, hide completely
return null;
}
if (result === true) {
break;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Loop Terminates Early on Falsy Values

The for loop condition (platformKey = platformsToSearch[i]) terminates prematurely if any element in platformsToSearch is falsy (e.g., empty string, null, undefined). This prevents checking subsequent platforms in the fallback chain, potentially causing content to be hidden incorrectly. The if (!platformKey) { continue; } guard inside the loop is unreachable for these falsy values.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think they would ever be falsy :/ like noone is gonna put supported={["javascript.cloudflare", "", "javascript.nextjs"]}

if (result === null && supported.length) {
// No supported platform found, hide completely
return null;
}
}

let href: string;
if (currentPlatformOrGuide) {
href = currentPlatformOrGuide.url + to.slice(1);
Expand Down
Loading