Skip to content

Commit e4bce99

Browse files
committed
more fixes
1 parent 64ef6be commit e4bce99

File tree

9 files changed

+136
-45
lines changed

9 files changed

+136
-45
lines changed

docs/platforms/javascript/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ platformTitle: JavaScript
33
caseStyle: camelCase
44
supportLevel: production
55
sdk: 'sentry.javascript.browser'
6+
language: typescript
67
categories:
78
- javascript
89
- browser

docs/platforms/python/apis.mdx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: APIs
3+
description: "Learn more about APIs of the SDK."
4+
customCanonicalTag: "/platforms/python/apis/"
5+
sidebar_order: 3
6+
---
7+
8+
This page shows all available to-level APIs of the SDK. You can use them like this:
9+
10+
```javascript
11+
import * as Sentry from "@sentry/browser";
12+
13+
Sentry.setTag("tag", "value");
14+
```
15+
16+
## Available Options
17+
18+
<TableOfContents ignoreIds={["available-options"]} />
19+
20+
## Capturing Events
21+
22+
<SdkApi
23+
name="captureException"
24+
signature={`capture_exception(exception: Exception, hint: Optional[CaptureContext] = None) -> EventId`}
25+
parameters={[
26+
{
27+
name: "exception",
28+
required: true,
29+
type: "unknown",
30+
description: "The exception to capture. This is usually an Error object.",
31+
},
32+
{
33+
name: "captureContext",
34+
type: {
35+
name: "CaptureContext",
36+
properties: [
37+
{
38+
name: "user",
39+
type: {
40+
name: "User",
41+
properties: [
42+
{ name: "id", type: "string | number" },
43+
{ name: "email", type: "string" },
44+
{ name: "ip_address", type: "string" },
45+
{ name: "username", type: "string" },
46+
],
47+
},
48+
},
49+
{
50+
name: "level",
51+
type: '"fatal" | "error" | "warning" | "log" | "info" | "debug"',
52+
},
53+
{
54+
name: "extra",
55+
type: "Record<string, unknown>",
56+
description:
57+
"Additional data that should be sent with the exception.",
58+
},
59+
{
60+
name: "tags",
61+
type: "Record<string, string>",
62+
description:
63+
"Additional tags that should be sent with the exception.",
64+
},
65+
{ name: "contexts", type: "Record<string, Record<string, unknown>>" },
66+
{ name: "fingerprint", type: "string[]" },
67+
],
68+
},
69+
description:
70+
"A hint object containing additional information about the exception.",
71+
},
72+
]}
73+
>
74+
Capture an exception event and send it to Sentry.
75+
</SdkApi>

docs/platforms/python/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ caseStyle: snake_case
55
supportLevel: production
66
sdk: sentry.python
77
showIntegrationsInSearch: true
8+
language: python
89
categories:
910
- server
1011
- serverless

src/components/apiExamples/apiExamples.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
'use client';
22

33
import {Fragment, useEffect, useState} from 'react';
4-
import {jsx, jsxs} from 'react/jsx-runtime';
54
import {Clipboard} from 'react-feather';
6-
import {toJsxRuntime} from 'hast-util-to-jsx-runtime';
7-
import {Nodes} from 'hastscript/lib/create-h';
8-
import bash from 'refractor/lang/bash.js';
9-
import json from 'refractor/lang/json.js';
10-
import typescript from 'refractor/lang/typescript.js';
11-
import {refractor} from 'refractor/lib/core.js';
125

136
import {type API} from 'sentry-docs/build/resolveOpenAPI';
147

@@ -17,10 +10,7 @@ import styles from './apiExamples.module.scss';
1710

1811
import {CodeBlock} from '../codeBlock';
1912
import {CodeTabs} from '../codeTabs';
20-
21-
refractor.register(bash);
22-
refractor.register(json);
23-
refractor.register(typescript);
13+
import {codeToJsx} from '../highlightCode';
2414

2515
const strFormat = (str: string) => {
2616
const s = str.trim();
@@ -34,10 +24,6 @@ type Props = {
3424
api: API;
3525
};
3626

37-
const codeToJsx = (code: string, lang = 'json') => {
38-
return toJsxRuntime(refractor.highlight(code, lang) as Nodes, {Fragment, jsx, jsxs});
39-
};
40-
4127
export function ApiExamples({api}: Props) {
4228
const apiExample = [
4329
`curl ${api.server}${api.apiPath}`,

src/components/highlightCode.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {Fragment} from 'react';
2+
import {jsx, jsxs} from 'react/jsx-runtime';
3+
import {toJsxRuntime} from 'hast-util-to-jsx-runtime';
4+
import {Nodes} from 'hastscript/lib/create-h';
5+
import bash from 'refractor/lang/bash.js';
6+
import c from 'refractor/lang/c.js';
7+
import cpp from 'refractor/lang/cpp.js';
8+
import csharp from 'refractor/lang/csharp.js';
9+
import go from 'refractor/lang/go.js';
10+
import java from 'refractor/lang/java.js';
11+
import json from 'refractor/lang/json.js';
12+
import kotlin from 'refractor/lang/kotlin.js';
13+
import objectivec from 'refractor/lang/objectivec.js';
14+
import php from 'refractor/lang/php.js';
15+
import python from 'refractor/lang/python.js';
16+
import ruby from 'refractor/lang/ruby.js';
17+
import rust from 'refractor/lang/rust.js';
18+
import swift from 'refractor/lang/swift.js';
19+
import typescript from 'refractor/lang/typescript.js';
20+
import {refractor} from 'refractor/lib/core.js';
21+
22+
refractor.register(bash);
23+
refractor.register(json);
24+
refractor.register(typescript);
25+
refractor.register(python);
26+
refractor.register(java);
27+
refractor.register(c);
28+
refractor.register(cpp);
29+
refractor.register(kotlin);
30+
refractor.register(csharp);
31+
refractor.register(rust);
32+
refractor.register(swift);
33+
refractor.register(ruby);
34+
refractor.register(objectivec);
35+
refractor.register(php);
36+
refractor.register(go);
37+
38+
export function codeToJsx(code: string, lang = 'json') {
39+
return toJsxRuntime(refractor.highlight(code, lang) as Nodes, {Fragment, jsx, jsxs});
40+
}

src/components/nestedObject.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
'use client';
22

33
import {Fragment, useState} from 'react';
4-
import {jsx, jsxs} from 'react/jsx-runtime';
54
import {MinusCircledIcon, PlusCircledIcon} from '@radix-ui/react-icons';
6-
import {toJsxRuntime} from 'hast-util-to-jsx-runtime';
7-
import {Nodes} from 'hastscript/lib/create-h';
8-
import {refractor} from 'refractor/lib/core.js';
95

6+
import {codeToJsx} from './highlightCode';
107
import {ParameterDef} from './sdkApi';
118

12-
const codeToJsx = (code: string, lang = 'json') => {
13-
return toJsxRuntime(refractor.highlight(code, lang) as Nodes, {Fragment, jsx, jsxs});
14-
};
159

1610
export function RenderNestedObject({
1711
name,
@@ -24,6 +18,8 @@ export function RenderNestedObject({
2418
}) {
2519
const [expanded, setExpanded] = useState(false);
2620

21+
// NOTE: For now, we always render the nested object in typescript
22+
2723
return (
2824
<div>
2925
<div className="flex items-center gap-2">
@@ -50,14 +46,14 @@ export function RenderNestedObject({
5046
<div key={prop.name}>
5147
{prop.description && (
5248
<div>
53-
<code>{codeToJsx(`// ${prop.description}`, language)}</code>
49+
<code>{codeToJsx(`// ${prop.description}`, 'typescript')}</code>
5450
</div>
5551
)}
5652
<div>
5753
{typeof prop.type === 'string' ? (
5854
<Fragment>
5955
<code>{prop.name}{!prop.required ? '?' : ''}: </code>
60-
<code>{codeToJsx(prop.type, language)},</code>
56+
<code>{codeToJsx(prop.type, 'typescript')},</code>
6157
</Fragment>
6258
) : (
6359
<RenderNestedObject

src/components/sdkApi.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import {Fragment} from 'react';
2-
import {jsx, jsxs} from 'react/jsx-runtime';
3-
import {toJsxRuntime} from 'hast-util-to-jsx-runtime';
4-
import {Nodes} from 'hastscript/lib/create-h';
5-
import bash from 'refractor/lang/bash.js';
6-
import json from 'refractor/lang/json.js';
7-
import typescript from 'refractor/lang/typescript.js';
8-
import {refractor} from 'refractor/lib/core.js';
9-
1+
import {getCurrentPlatform} from 'sentry-docs/docTree';
2+
import {serverContext} from 'sentry-docs/serverContext';
103
import {PlatformCategory} from 'sentry-docs/types';
114

125
import {Expandable} from './expandable';
6+
import {codeToJsx} from './highlightCode';
137
import {RenderNestedObject} from './nestedObject';
148
import {SdkDefinition} from './sdkDefinition';
159

@@ -35,32 +29,27 @@ type Props = {
3529
language?: string;
3630
};
3731

38-
refractor.register(bash);
39-
refractor.register(json);
40-
refractor.register(typescript);
41-
42-
const codeToJsx = (code: string, lang = 'json') => {
43-
return toJsxRuntime(refractor.highlight(code, lang) as Nodes, {Fragment, jsx, jsxs});
44-
};
45-
4632
export function SdkApi({
4733
name,
4834
children,
4935
signature,
5036
parameters = [],
51-
// TODO: How to handle this default better?
52-
language = 'typescript',
37+
language,
5338
categorySupported = [],
5439
}: Props) {
40+
const {rootNode, path} = serverContext();
41+
const platform = getCurrentPlatform(rootNode, path);
42+
const lang = language || platform?.language || 'typescript';
43+
5544
return (
5645
<SdkDefinition name={name} categorySupported={categorySupported}>
57-
<pre className="mt-2 mb-2 text-sm">{codeToJsx(signature, language)}</pre>
46+
<pre className="mt-2 mb-2 text-sm">{codeToJsx(signature, lang)}</pre>
5847

5948
{parameters.length ? (
6049
<Expandable title="Parameters">
6150
<div className="space-y-3">
6251
{parameters.map(param => (
63-
<ApiParameterDef key={param.name} language={language} {...param} />
52+
<ApiParameterDef key={param.name} language={lang} {...param} />
6453
))}
6554
</div>
6655
</Expandable>

src/docTree.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ function nodeToPlatform(n: DocNode): Platform {
263263
caseStyle,
264264
sdk: n.frontmatter.sdk,
265265
fallbackPlatform: n.frontmatter.fallbackPlatform,
266+
language: n.frontmatter.language,
266267
categories: n.frontmatter.categories,
267268
keywords: n.frontmatter.keywords,
268269
guides,

src/types/platform.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export interface PlatformConfig {
118118
* Keywords used for search etc.
119119
*/
120120
keywords?: string[];
121+
/** The name of the programming language that should be used for formatting the SDK API docs. */
122+
language?: string;
121123
/**
122124
* The title of the platform as it should be displayed in the sidebar.
123125
* In most cases, you do not need to define this, as the title is used.

0 commit comments

Comments
 (0)