From fa33fb45cedbc50f59aa636d71f06e87f9ca08f4 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:55:37 +0000 Subject: [PATCH 1/5] feat(develop-docs): Render span attributes from sentry-conventions Add a ConventionAttributes MDX component that reads attribute type, description, deprecation, and example from @sentry/conventions instead of copying them into Markdown tables. Unknown keys fail the build. Migrate the token usage and execute tool tables on the AI agents page. --- .../telemetry/traces/modules/ai-agents.mdx | 32 +++--- package.json | 1 + pnpm-lock.yaml | 9 ++ .../conventionAttributes/index.spec.tsx | 61 +++++++++++ src/components/conventionAttributes/index.tsx | 103 ++++++++++++++++++ src/mdxComponents.ts | 2 + 6 files changed, 194 insertions(+), 14 deletions(-) create mode 100644 src/components/conventionAttributes/index.spec.tsx create mode 100644 src/components/conventionAttributes/index.tsx diff --git a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx index af92d7395c8ee..c993888976aa1 100644 --- a/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx +++ b/develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx @@ -126,14 +126,16 @@ Additional attributes on the span: ### Token Usage Data -| Attribute | Type | Description | Example | -| :----------------------------------------- | :--- | :----------------------------------------------------------------------------------------------------------------------------- | :------ | -| `gen_ai.usage.input_tokens` | int | The number of tokens used in the AI input (prompt), including cached tokens. **[2]** | `60` | -| `gen_ai.usage.cache_read.input_tokens` | int | The number of cached tokens used in the AI input (prompt). | `50` | -| `gen_ai.usage.cache_creation.input_tokens` | int | Tokens written to cache when processing input. | `20` | -| `gen_ai.usage.output_tokens` | int | The number of tokens used in the AI output, including reasoning tokens. **[3]** | `130` | -| `gen_ai.usage.reasoning.output_tokens` | int | The number of tokens used for reasoning. | `30` | -| `gen_ai.usage.total_tokens` | int | The sum of `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. | `190` | + ## Execute Tool Span @@ -147,12 +149,14 @@ Describes a tool execution. Additional attributes on the span: -| Attribute | Type | Description | Example | -| :--------------------------- | :----- | :------------------------------------------------------------------------------------------------------------- | :----------------------------------------- | -| `gen_ai.tool.name` | string | Name of the tool executed. | `"random_number"` | -| `gen_ai.tool.description` | string | Description of the tool executed. | `"Tool returning a random number"` | -| `gen_ai.tool.call.arguments` | string | Arguments of the tool call (stringified). | `'{"max":10}'` | -| `gen_ai.tool.call.result` | string | Result of the tool call (stringified). | `"7"` | + ## Derived by Relay diff --git a/package.json b/package.json index e077145a96ce0..08a14972bd17b 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@radix-ui/themes": "^3.1.3", "@sentry-internal/global-search": "^1.3.0", "@sentry/browser": "11.6.0", + "@sentry/conventions": "^0.31.0", "@sentry/nextjs": "11.6.0", "@types/mdx": "^2.0.9", "algoliasearch": "^4.23.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be0bb14b16151..dccedbbb13d1c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: '@sentry/browser': specifier: 11.6.0 version: 11.6.0 + '@sentry/conventions': + specifier: ^0.31.0 + version: 0.31.0 '@sentry/nextjs': specifier: 11.6.0 version: 11.6.0(@babel/core@7.29.7)(next@15.5.24(@babel/core@7.29.7)(@opentelemetry/api@1.9.1)(@types/node@22.19.11)(babel-plugin-macros@3.1.0)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)(sass@1.98.0))(react@19.2.4)(webpack@5.105.2(esbuild@0.28.1)(postcss@8.5.23)) @@ -3115,6 +3118,10 @@ packages: resolution: {integrity: sha512-ttSRcoLf2kIENDIFzH12aJaVMdxnidMYLvVNwEX/JjXfXaQot8u5M47QmgAFOOhVJ4nQ2uU8wTCh+fwSPrrCfg==} engines: {node: '>=14'} + '@sentry/conventions@0.31.0': + resolution: {integrity: sha512-TOXB7z08JPVop4eiYLhZhgWitUYUMX6T1SjLCthaa8YLnNyA3+gbT1ccUinf2EWvzFwBuYPShPB7oYSkKeCFIQ==} + engines: {node: '>=14'} + '@sentry/core@11.6.0': resolution: {integrity: sha512-PbITT1kfJYKJiS9fH4ZtOcwIONKyt+tUsTZSPtcAjPdkUDOzMKT61MkUa1Ze07VzNtLALT24ZdUOc6d9K4YoKA==} engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'} @@ -10621,6 +10628,8 @@ snapshots: '@sentry/conventions@0.26.0': {} + '@sentry/conventions@0.31.0': {} + '@sentry/core@11.6.0': dependencies: '@sentry/conventions': 0.26.0 diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx new file mode 100644 index 0000000000000..d17402a031272 --- /dev/null +++ b/src/components/conventionAttributes/index.spec.tsx @@ -0,0 +1,61 @@ +import {ATTRIBUTE_METADATA} from '@sentry/conventions/attributes'; +import React from 'react'; +import {renderToStaticMarkup} from 'react-dom/server'; +import {describe, expect, it, vi} from 'vitest'; + +import {ConventionAttributes, conventionsUrl} from './index'; + +// Vitest compiles JSX with the classic runtime here (tsconfig `jsx: preserve`). +vi.stubGlobal('React', React); + +describe('ConventionAttributes', () => { + it('renders type and description from the conventions package', () => { + const html = renderToStaticMarkup( + + ); + + expect(html).toContain('gen_ai.tool.name'); + expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].type); + expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].brief); + }); + + it('appends page-specific notes to the description', () => { + const html = renderToStaticMarkup( + + ); + + expect(html).toContain('[2]'); + }); + + it('marks deprecated attributes with their replacement', () => { + const html = renderToStaticMarkup(); + + expect(html).toContain('Deprecated'); + expect(html).toContain('server.address'); + }); + + it('throws on unknown attributes so the build fails', () => { + expect(() => + renderToStaticMarkup() + ).toThrow('unknown attribute "gen_ai.not.a.thing"'); + }); +}); + +describe('conventionsUrl', () => { + it('links to the category page anchor', () => { + expect(conventionsUrl('gen_ai.usage.input_tokens')).toBe( + 'https://getsentry.github.io/sentry-conventions/attributes/gen_ai/#gen_ai-usage-input_tokens' + ); + }); + + it('handles keys without a namespace and dynamic suffixes', () => { + expect(conventionsUrl('environment')).toBe( + 'https://getsentry.github.io/sentry-conventions/attributes/general/#environment' + ); + expect(conventionsUrl('http.request.header.')).toBe( + 'https://getsentry.github.io/sentry-conventions/attributes/http/#http-request-header-key' + ); + }); +}); diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx new file mode 100644 index 0000000000000..5416f5e3544f8 --- /dev/null +++ b/src/components/conventionAttributes/index.tsx @@ -0,0 +1,103 @@ +import { + ATTRIBUTE_METADATA, + type AttributeMetadata, + type AttributeValue, +} from '@sentry/conventions/attributes'; +import {micromark} from 'micromark'; + +const CONVENTIONS_URL = 'https://getsentry.github.io/sentry-conventions/'; + +type AttributeRow = + | string + | { + key: string; + /** Markdown appended to the conventions description, such as footnote references. */ + notes?: string; + }; + +type Props = { + attributes: AttributeRow[]; +}; + +const metadata: Record = ATTRIBUTE_METADATA; + +/** + * Renders attribute details straight from `@sentry/conventions`, so pages don't copy + * types, descriptions, and examples that then drift from the source of truth. + * + * Page-specific context, such as footnotes, stays in the MDX and is passed per row. + */ +export function ConventionAttributes({attributes}: Props) { + const rows = attributes.map(row => { + const {key, notes} = typeof row === 'string' ? {key: row} : row; + const attribute = metadata[key]; + if (!attribute) { + // Fail the build so typos and removed attributes don't ship as empty rows. + throw new Error( + `: unknown attribute "${key}". Check ${CONVENTIONS_URL}attributes/` + ); + } + return {key, notes, attribute}; + }); + + return ( + + + + + + + + + + + {rows.map(({key, notes, attribute}) => ( + + + + + + + ))} + +
AttributeTypeDescriptionExample
+ + {key} + + {attribute.type} + + + {attribute.example !== undefined && ( + {formatExample(attribute.example)} + )} +
+ ); +} + +function describe(attribute: AttributeMetadata, notes?: string) { + const {deprecation} = attribute; + const deprecated = deprecation + ? `**Deprecated**${deprecation.replacement ? `, use \`${deprecation.replacement}\` instead` : ''}.` + : undefined; + return [deprecated, attribute.brief, notes].filter(Boolean).join(' '); +} + +function InlineMarkdown({source}: {source: string}) { + // Unwrap the single paragraph so table rows keep a compact, aligned layout. + const html = micromark(source) + .replace(/^

/, '') + .replace(/<\/p>$/, ''); + // Content comes from the pinned conventions package and our own MDX, not user input. + return ; +} + +// Mirrors attributeUrl() in sentry-conventions/docs/src/utils/attributeUrl.ts. +export function conventionsUrl(key: string) { + const category = key.includes('.') ? key.split('.')[0] : 'general'; + const slug = key.replace(/\./g, '-').replace(/[<>]/g, ''); + return `${CONVENTIONS_URL}attributes/${category}/#${slug}`; +} + +function formatExample(example: AttributeValue) { + return typeof example === 'string' ? `"${example}"` : JSON.stringify(example); +} diff --git a/src/mdxComponents.ts b/src/mdxComponents.ts index 13d823b180d63..27d17c1f72fe1 100644 --- a/src/mdxComponents.ts +++ b/src/mdxComponents.ts @@ -12,6 +12,7 @@ import {CommunitySupportedPlatforms} from './components/communitySupportedPlatfo import {ConfigKey} from './components/configKey'; import {ConfigValue} from './components/configValue'; import {ContentSeparator} from './components/contentSeparator'; +import {ConventionAttributes} from './components/conventionAttributes'; import {CopyableCard} from './components/copyableCard'; import {CreateGitHubAppForm} from './components/createGitHubAppForm'; import {DefinitionList} from './components/definitionList'; @@ -82,6 +83,7 @@ export function mdxComponents( CliChecksumTable, CommunitySupportedPlatforms, ContentSeparator, + ConventionAttributes, DevDocsCardGrid, PlatformFilter, CodeBlock, From d021e0c3dbff60110ef2a39495b3f6c76c77c980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Daxb=C3=B6ck?= Date: Thu, 5 Nov 2026 14:13:12 +0100 Subject: [PATCH 2/5] ref(develop-docs): Simplify ConventionAttributes component Keep the table close to the Markdown tables it replaces. Drop the per-key links, the deprecated prefix, and the InlineMarkdown wrapper, and shorten the unknown-attribute error. Add one link under each table to the attribute category page in Sentry Conventions instead. Co-Authored-By: Claude Opus 5.5 --- .../conventionAttributes/index.spec.tsx | 31 +---- src/components/conventionAttributes/index.tsx | 120 +++++++----------- 2 files changed, 52 insertions(+), 99 deletions(-) diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx index d17402a031272..ae1da6bb7c4af 100644 --- a/src/components/conventionAttributes/index.spec.tsx +++ b/src/components/conventionAttributes/index.spec.tsx @@ -3,13 +3,13 @@ import React from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import {describe, expect, it, vi} from 'vitest'; -import {ConventionAttributes, conventionsUrl} from './index'; +import {ConventionAttributes} from './index'; // Vitest compiles JSX with the classic runtime here (tsconfig `jsx: preserve`). vi.stubGlobal('React', React); describe('ConventionAttributes', () => { - it('renders type and description from the conventions package', () => { + it('renders attributes from the conventions package with a category link', () => { const html = renderToStaticMarkup( ); @@ -17,6 +17,9 @@ describe('ConventionAttributes', () => { expect(html).toContain('gen_ai.tool.name'); expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].type); expect(html).toContain(ATTRIBUTE_METADATA['gen_ai.tool.name'].brief); + expect(html).toContain( + 'href="https://getsentry.github.io/sentry-conventions/attributes/gen_ai/"' + ); }); it('appends page-specific notes to the description', () => { @@ -29,33 +32,9 @@ describe('ConventionAttributes', () => { expect(html).toContain('[2]'); }); - it('marks deprecated attributes with their replacement', () => { - const html = renderToStaticMarkup(); - - expect(html).toContain('Deprecated'); - expect(html).toContain('server.address'); - }); - it('throws on unknown attributes so the build fails', () => { expect(() => renderToStaticMarkup() ).toThrow('unknown attribute "gen_ai.not.a.thing"'); }); }); - -describe('conventionsUrl', () => { - it('links to the category page anchor', () => { - expect(conventionsUrl('gen_ai.usage.input_tokens')).toBe( - 'https://getsentry.github.io/sentry-conventions/attributes/gen_ai/#gen_ai-usage-input_tokens' - ); - }); - - it('handles keys without a namespace and dynamic suffixes', () => { - expect(conventionsUrl('environment')).toBe( - 'https://getsentry.github.io/sentry-conventions/attributes/general/#environment' - ); - expect(conventionsUrl('http.request.header.')).toBe( - 'https://getsentry.github.io/sentry-conventions/attributes/http/#http-request-header-key' - ); - }); -}); diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx index 5416f5e3544f8..2b82f8cd35472 100644 --- a/src/components/conventionAttributes/index.tsx +++ b/src/components/conventionAttributes/index.tsx @@ -4,100 +4,74 @@ import { type AttributeValue, } from '@sentry/conventions/attributes'; import {micromark} from 'micromark'; - -const CONVENTIONS_URL = 'https://getsentry.github.io/sentry-conventions/'; - -type AttributeRow = - | string - | { - key: string; - /** Markdown appended to the conventions description, such as footnote references. */ - notes?: string; - }; +import {Fragment} from 'react'; type Props = { - attributes: AttributeRow[]; + attributes: (string | {key: string; notes?: string})[]; }; const metadata: Record = ATTRIBUTE_METADATA; /** - * Renders attribute details straight from `@sentry/conventions`, so pages don't copy - * types, descriptions, and examples that then drift from the source of truth. - * - * Page-specific context, such as footnotes, stays in the MDX and is passed per row. + * Renders attribute details from `@sentry/conventions`, so pages don't copy + * types, descriptions, and examples that drift from the source of truth. */ export function ConventionAttributes({attributes}: Props) { const rows = attributes.map(row => { const {key, notes} = typeof row === 'string' ? {key: row} : row; const attribute = metadata[key]; if (!attribute) { - // Fail the build so typos and removed attributes don't ship as empty rows. - throw new Error( - `: unknown attribute "${key}". Check ${CONVENTIONS_URL}attributes/` - ); + throw new Error(`: unknown attribute "${key}"`); } - return {key, notes, attribute}; + const description = micromark([attribute.brief, notes].filter(Boolean).join(' ')) + .replace(/^

/, '') + .replace(/<\/p>$/, ''); + return {key, attribute, description}; }); + const firstKey = rows[0].key; + const category = firstKey.includes('.') ? firstKey.split('.')[0] : 'general'; return ( - - - - - - - - - - - {rows.map(({key, notes, attribute}) => ( - - - - - + +
AttributeTypeDescriptionExample
- - {key} - - {attribute.type} - - - {attribute.example !== undefined && ( - {formatExample(attribute.example)} - )} -
+ + + + + + - ))} - -
AttributeTypeDescriptionExample
+ + + {rows.map(({key, attribute, description}) => ( + + + {key} + + {attribute.type} + + + {attribute.example !== undefined && ( + {formatExample(attribute.example)} + )} + + + ))} + + +

+ See all{' '} + + {category} attributes in Sentry Conventions + + . +

+ ); } -function describe(attribute: AttributeMetadata, notes?: string) { - const {deprecation} = attribute; - const deprecated = deprecation - ? `**Deprecated**${deprecation.replacement ? `, use \`${deprecation.replacement}\` instead` : ''}.` - : undefined; - return [deprecated, attribute.brief, notes].filter(Boolean).join(' '); -} - -function InlineMarkdown({source}: {source: string}) { - // Unwrap the single paragraph so table rows keep a compact, aligned layout. - const html = micromark(source) - .replace(/^

/, '') - .replace(/<\/p>$/, ''); - // Content comes from the pinned conventions package and our own MDX, not user input. - return ; -} - -// Mirrors attributeUrl() in sentry-conventions/docs/src/utils/attributeUrl.ts. -export function conventionsUrl(key: string) { - const category = key.includes('.') ? key.split('.')[0] : 'general'; - const slug = key.replace(/\./g, '-').replace(/[<>]/g, ''); - return `${CONVENTIONS_URL}attributes/${category}/#${slug}`; -} - function formatExample(example: AttributeValue) { return typeof example === 'string' ? `"${example}"` : JSON.stringify(example); } From 418cb56985559a27ee26866ddc0371f596da6b64 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 08:51:43 +0000 Subject: [PATCH 3/5] feat(develop-docs): Render attribute notes from sentry-conventions Replace the hand-written notes prop with the additionalContext notes from @sentry/conventions. Notes render as a numbered list under the table, and attributes that share a note link to the same number, so pages no longer maintain footnotes for attributes the component renders. --- .../conventionAttributes/index.spec.tsx | 21 ++++++-- src/components/conventionAttributes/index.tsx | 53 +++++++++++++++---- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx index ae1da6bb7c4af..4c335d3fc89e0 100644 --- a/src/components/conventionAttributes/index.spec.tsx +++ b/src/components/conventionAttributes/index.spec.tsx @@ -22,14 +22,25 @@ describe('ConventionAttributes', () => { ); }); - it('appends page-specific notes to the description', () => { + it('renders additional context as numbered notes, shared notes once', () => { + const keys = ['gen_ai.usage.input_tokens', 'gen_ai.usage.output_tokens']; + const html = renderToStaticMarkup(); + const notes = [ + ...new Set(keys.flatMap(key => ATTRIBUTE_METADATA[key].additionalContext ?? [])), + ]; + + expect(notes.length).toBeGreaterThan(0); + expect(html.match(/

  • { const html = renderToStaticMarkup( - + ); - expect(html).toContain('[2]'); + expect(html).not.toContain('
      '); }); it('throws on unknown attributes so the build fails', () => { diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx index 2b82f8cd35472..ed7cfa25ce218 100644 --- a/src/components/conventionAttributes/index.tsx +++ b/src/components/conventionAttributes/index.tsx @@ -7,29 +7,33 @@ import {micromark} from 'micromark'; import {Fragment} from 'react'; type Props = { - attributes: (string | {key: string; notes?: string})[]; + attributes: string[]; }; const metadata: Record = ATTRIBUTE_METADATA; /** * Renders attribute details from `@sentry/conventions`, so pages don't copy - * types, descriptions, and examples that drift from the source of truth. + * types, descriptions, examples, and notes that drift from the source of truth. + * Each attribute's `additionalContext` becomes a numbered note under the table. + * Attributes that share a note point to the same number. */ export function ConventionAttributes({attributes}: Props) { - const rows = attributes.map(row => { - const {key, notes} = typeof row === 'string' ? {key: row} : row; + const notes: string[] = []; + const rows = attributes.map(key => { const attribute = metadata[key]; if (!attribute) { throw new Error(`: unknown attribute "${key}"`); } - const description = micromark([attribute.brief, notes].filter(Boolean).join(' ')) - .replace(/^

      /, '') - .replace(/<\/p>$/, ''); - return {key, attribute, description}; + const noteNumbers = (attribute.additionalContext ?? []).map(note => { + const index = notes.indexOf(note); + return index === -1 ? notes.push(note) : index + 1; + }); + return {key, attribute, noteNumbers}; }); const firstKey = rows[0].key; const category = firstKey.includes('.') ? firstKey.split('.')[0] : 'general'; + const noteId = (n: number) => `${firstKey.replace(/\./g, '-')}-note-${n}`; return ( @@ -43,13 +47,25 @@ export function ConventionAttributes({attributes}: Props) { - {rows.map(({key, attribute, description}) => ( + {rows.map(({key, attribute, noteNumbers}) => ( {key} {attribute.type} - + + + {noteNumbers.map(n => ( + + {' '} + + [{n}] + + + ))} + {attribute.example !== undefined && ( {formatExample(attribute.example)} @@ -59,6 +75,17 @@ export function ConventionAttributes({attributes}: Props) { ))} + {notes.length > 0 && ( +

        + {notes.map((note, i) => ( +
      1. + ))} +
      + )}

      See all{' '} /, '') + .replace(/<\/p>$/, ''); +} + function formatExample(example: AttributeValue) { return typeof example === 'string' ? `"${example}"` : JSON.stringify(example); } From 23302c901e5b83bfb229b41f98051f4678144ab7 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 08:52:51 +0000 Subject: [PATCH 4/5] ref(develop-docs): Render attribute note markers as superscript --- src/components/conventionAttributes/index.spec.tsx | 4 +++- src/components/conventionAttributes/index.tsx | 9 +++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx index 4c335d3fc89e0..4e86ef4125b64 100644 --- a/src/components/conventionAttributes/index.spec.tsx +++ b/src/components/conventionAttributes/index.spec.tsx @@ -31,7 +31,9 @@ describe('ConventionAttributes', () => { expect(notes.length).toBeGreaterThan(0); expect(html.match(/

    1. [1]' + ); expect(html).toContain('id="gen_ai-usage-input_tokens-note-1"'); }); diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx index ed7cfa25ce218..d3c2f60ddb196 100644 --- a/src/components/conventionAttributes/index.tsx +++ b/src/components/conventionAttributes/index.tsx @@ -58,12 +58,9 @@ export function ConventionAttributes({attributes}: Props) { dangerouslySetInnerHTML={{__html: inlineMarkdown(attribute.brief)}} /> {noteNumbers.map(n => ( - - {' '} - - [{n}] - - + + [{n}] + ))} From f5522cbeb612c25d558fdaf8df1c536433d19d36 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:05:08 +0000 Subject: [PATCH 5/5] fix(develop-docs): Quote stringified JSON examples in ConventionAttributes String examples were wrapped in raw double quotes, so JSON strings such as gen_ai.tool.call.arguments rendered as broken nested quotes. Single-quote strings that contain double quotes, matching the Markdown tables, and use JSON.stringify for everything else. --- src/components/conventionAttributes/index.spec.tsx | 10 ++++++++++ src/components/conventionAttributes/index.tsx | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/conventionAttributes/index.spec.tsx b/src/components/conventionAttributes/index.spec.tsx index 4e86ef4125b64..e2a9f6d933399 100644 --- a/src/components/conventionAttributes/index.spec.tsx +++ b/src/components/conventionAttributes/index.spec.tsx @@ -45,6 +45,16 @@ describe('ConventionAttributes', () => { expect(html).not.toContain('
        '); }); + it('single-quotes string examples that contain double quotes', () => { + const html = renderToStaticMarkup( + + ); + const example = String(ATTRIBUTE_METADATA['gen_ai.tool.call.arguments'].example); + + expect(example).toContain('"'); + expect(html).toContain(`'${example.replace(/"/g, '"')}'`); + }); + it('throws on unknown attributes so the build fails', () => { expect(() => renderToStaticMarkup() diff --git a/src/components/conventionAttributes/index.tsx b/src/components/conventionAttributes/index.tsx index d3c2f60ddb196..c88e76da4c3cd 100644 --- a/src/components/conventionAttributes/index.tsx +++ b/src/components/conventionAttributes/index.tsx @@ -102,6 +102,11 @@ function inlineMarkdown(text: string) { .replace(/<\/p>$/, ''); } +// Single-quote strings that contain double quotes, such as stringified JSON, +// so they read as `'{"max":10}'` instead of escaped JSON. function formatExample(example: AttributeValue) { - return typeof example === 'string' ? `"${example}"` : JSON.stringify(example); + if (typeof example === 'string' && example.includes('"') && !example.includes("'")) { + return `'${example}'`; + } + return JSON.stringify(example); }