Skip to content

Commit

Permalink
feat: Add PlatformOrGuideName and PlatformSdkPackageName components
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Feb 22, 2024
1 parent dc72070 commit dd5820a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/platforms/javascript/common/profiling/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Note that since the profiling API is currently only exposed in Chromium, profile

To get started with JavaScript browser profiling, you'll need to:

- Install the @sentry/browser SDK, minimum version 7.60.0
- Install the <PlatformSdkPackageName fallback="@sentry/browser"/> SDK, minimum version 7.60.0
- Configure the document response header to include `Document-Policy: js-profiling`
- Configure the SDK to use the `BrowserProfilingIntegration` and set `profilesSampleRate`

## Step 1: Install the JavaScript Browser SDK
## Step 1: Install the <PlatformOrGuideName/> SDK

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

Install our JavaScript browser SDK using either `yarn` or `npm`, the minimum version that supports profiling is **7.60.0**.
Install our <PlatformOrGuideName/> SDK using either `yarn` or `npm`, the minimum version that supports profiling is **7.60.0**.

</PlatformSection>

Expand Down
25 changes: 25 additions & 0 deletions src/components/platformOrGuideName.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';

type PlatformOrGuideNameProps = {
/**
* The fallback value to display if the platform or guide name is not found.
* @default 'Sentry'
*/
fallback?: string;
};

/**
* Displays a readable name of the currently selected platform or guide.
* Example: `Next.js`.
*/
export function PlatformOrGuideName({fallback}: PlatformOrGuideNameProps) {
const fallbackName = fallback || 'Sentry';
const {rootNode, path} = serverContext();
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path);
if (!platformOrGuide) {
return 'fallbackName ';
}

return `${platformOrGuide.title || fallbackName} `;
}
40 changes: 40 additions & 0 deletions src/components/platformSdkPackageName.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import getPackageRegistry from 'sentry-docs/build/packageRegistry';
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';

type PlatformSdkPackageNameProps = {
/**
* The fallback value to display if the SDK package name is not found.
* @default 'Sentry'
*/
fallback?: string;
};

/**
* Displays the SDK package name for the current platform or guide.
* Example: `@sentry/react`
*/
export async function PlatformSdkPackageName({fallback}: PlatformSdkPackageNameProps) {
const fallbackName = fallback || 'Sentry';
const {rootNode, path} = serverContext();
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path);
if (!platformOrGuide) {
return <code>{fallbackName} </code>;
}

const packageRegistry = await getPackageRegistry();
const allSdks = packageRegistry.data;
const entries = Object.entries(allSdks || {});
const pair: any = entries.find(([sdkName]) => sdkName === platformOrGuide.sdk);
if (!pair) {
return <code>{fallbackName} </code>;
}
const [, sdkData] = pair;
if (!sdkData) {
return <code>{fallbackName} </code>;
}

const prettifiedName = sdkData.canonical.replace(/^npm:/, '');

return <code>{prettifiedName || fallbackName} </code>;
}
4 changes: 4 additions & 0 deletions src/mdxComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {PlatformGrid} from './components/platformGrid';
import {PlatformIdentifier} from './components/platformIdentifier';
import {PlatformLink} from './components/platformLink';
import {PlatformLinkWithLogo} from './components/platformLinkWithLogo';
import {PlatformOrGuideName} from './components/platformOrGuideName';
import {PlatformSdkPackageName} from './components/platformSdkPackageName';
import {PlatformSection} from './components/platformSection';
import {RelayMetrics} from './components/relayMetrics';
import {SandboxLink} from './components/sandboxLink';
Expand Down Expand Up @@ -55,6 +57,8 @@ export function mdxComponents(
PlatformLink,
PlatformLinkWithLogo,
PlatformSection,
PlatformOrGuideName,
PlatformSdkPackageName,
RelayMetrics,
SandboxLink,
SignInNote,
Expand Down

0 comments on commit dd5820a

Please sign in to comment.