-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(getting-started-docs): Add docs for node/azurefunctions (#53277)
closes(#52196)
- Loading branch information
1 parent
17d09c7
commit 653745a
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
static/app/gettingStartedDocs/node/azurefunctions.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import {StepTitle} from 'sentry/components/onboarding/gettingStartedDoc/step'; | ||
|
||
import {GettingStartedWithAzurefunctions, steps} from './azurefunctions'; | ||
|
||
describe('GettingStartedWithAzurefunctions', function () { | ||
it('renders doc correctly', function () { | ||
const {container} = render(<GettingStartedWithAzurefunctions dsn="test-dsn" />); | ||
|
||
// Steps | ||
for (const step of steps()) { | ||
expect( | ||
screen.getByRole('heading', {name: step.title ?? StepTitle[step.type]}) | ||
).toBeInTheDocument(); | ||
} | ||
|
||
expect(container).toSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout'; | ||
import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation'; | ||
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step'; | ||
import {PlatformKey} from 'sentry/data/platformCategories'; | ||
import {tct} from 'sentry/locale'; | ||
import type {Organization} from 'sentry/types'; | ||
|
||
type StepProps = { | ||
newOrg: boolean; | ||
organization: Organization; | ||
platformKey: PlatformKey; | ||
projectId: string; | ||
sentryInitContent: string; | ||
}; | ||
|
||
export const steps = ({ | ||
sentryInitContent, | ||
}: Partial<StepProps> = {}): LayoutProps['steps'] => [ | ||
{ | ||
type: StepType.INSTALL, | ||
description: ( | ||
<p>{tct('Add [code:@sentry/node] as a dependency:', {code: <code />})}</p> | ||
), | ||
configurations: [ | ||
{ | ||
language: 'bash', | ||
code: ` | ||
# Using yarn | ||
yarn add @sentry/node | ||
# Using npm | ||
npm install --save @sentry/node | ||
`, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: StepType.CONFIGURE, | ||
description: ( | ||
<p> | ||
{tct('To set up Sentry error logging for an Azure Function:', { | ||
code: <code />, | ||
})} | ||
</p> | ||
), | ||
configurations: [ | ||
{ | ||
language: 'javascript', | ||
code: ` | ||
"use strict"; | ||
const Sentry = require("@sentry/node"); | ||
Sentry.init({ | ||
${sentryInitContent}, | ||
}); | ||
module.exports = async function (context, req) { | ||
try { | ||
await notExistFunction(); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
await Sentry.flush(2000); | ||
} | ||
context.res = { | ||
status: 200, | ||
body: "Hello from Azure Cloud Function!", | ||
}; | ||
}; | ||
`, | ||
}, | ||
{ | ||
language: 'javascript', | ||
description: ( | ||
<p> | ||
{tct( | ||
'Note: You need to call both [code:captureException] and [code:flush] for captured events to be successfully delivered to Sentry.', | ||
{} | ||
)} | ||
</p> | ||
), | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export function GettingStartedWithAzurefunctions({ | ||
dsn, | ||
organization, | ||
newOrg, | ||
platformKey, | ||
projectId, | ||
}: ModuleProps) { | ||
const sentryInitContent: string[] = [`dsn: "${dsn}"`]; | ||
|
||
return ( | ||
<Layout | ||
steps={steps({ | ||
sentryInitContent: sentryInitContent.join('\n'), | ||
organization, | ||
newOrg, | ||
platformKey, | ||
projectId, | ||
})} | ||
newOrg={newOrg} | ||
platformKey={platformKey} | ||
/> | ||
); | ||
} | ||
|
||
export default GettingStartedWithAzurefunctions; |