Skip to content

Commit

Permalink
ref(onboarding): Convert platforms dotnet aspnetcore & gcpfunctions t…
Browse files Browse the repository at this point in the history
…o new structure (#58239)

- relates to #56549
  • Loading branch information
ArthurKnaus authored Oct 19, 2023
1 parent 763b9f5 commit 37cdb15
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 307 deletions.
35 changes: 23 additions & 12 deletions static/app/gettingStartedDocs/dotnet/awslambda.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import {render, screen} from 'sentry-test/reactTestingLibrary';
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
import {screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';

import {StepTitle} from 'sentry/components/onboarding/gettingStartedDoc/step';
import docs from './awslambda';

import {GettingStartedAwsLambda, steps} from './awslambda';
describe('awslambda onboarding docs', function () {
it('renders docs correctly', async function () {
renderWithOnboardingLayout(docs, {
releaseRegistry: {
'sentry.dotnet.aspnetcore': {
version: '1.99.9',
},
},
});

describe('GettingStartedAwsLambda', function () {
it('renders doc correctly', function () {
render(<GettingStartedAwsLambda dsn="test-dsn" projectSlug="test-project" />);
// Renders main headings
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Verify'})).toBeInTheDocument();

// Steps
for (const step of steps()) {
expect(
screen.getByRole('heading', {name: step.title ?? StepTitle[step.type]})
).toBeInTheDocument();
}
// Renders SDK version from registry
expect(
await screen.findByText(
textWithMarkupMatcher(/Install-Package Sentry.AspNetCore -Version 1\.99\.9/)
)
).toBeInTheDocument();
});
});
255 changes: 127 additions & 128 deletions static/app/gettingStartedDocs/dotnet/awslambda.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,32 @@
import {Fragment} from 'react';

import ExternalLink from 'sentry/components/links/externalLink';
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 type {
Docs,
DocsParams,
OnboardingConfig,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {t, tct} from 'sentry/locale';
import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';

// Configuration Start
const introduction = (
<p>
{tct(
'Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.',
{
link: <ExternalLink href="https://www.nuget.org/packages/Sentry.AspNetCore" />,
}
)}
</p>
);
export const steps = ({
dsn,
sourcePackageRegistries,
}: Partial<
Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
> = {}): LayoutProps['steps'] => [
{
type: StepType.INSTALL,
description: t('Add the Sentry dependency:'),
configurations: [
{
language: 'powershell',
partialLoading: sourcePackageRegistries?.isLoading,
code: `Install-Package Sentry.AspNetCore -Version ${
sourcePackageRegistries?.isLoading
? t('\u2026loading')
: sourcePackageRegistries?.data?.['sentry.dotnet.aspnetcore']?.version ??
'3.34.0'
}`,
},
{
language: 'shell',
partialLoading: sourcePackageRegistries?.isLoading,
code: `dotnet add package Sentry.AspNetCore -v ${
sourcePackageRegistries?.isLoading
? t('\u2026loading')
: sourcePackageRegistries?.data?.['sentry.dotnet.aspnetcore']?.version ??
'3.34.0'
}`,
},
],
additionalInfo: (
<p>
{tct(
'You can combine this integration with a logging library like [strong:log4net, NLog, or Serilog] to include both request data as well as your logs as breadcrumbs. The logging ingrations also capture events when an error is logged.',
{strong: <strong />}
)}
</p>
),
},
{
type: StepType.CONFIGURE,
description: (
<Fragment>
<p>
{tct(
'All [code:ASP.NET Core] configurations are valid here. But one configuration in particular is relevant.',
{
code: <code />,
}
)}
</p>
<p>
{tct(
'[code:FlushOnCompletedRequest] ensures all events are flushed out. This is because the general ASP.NET Core hooks for when the process is exiting are not guaranteed to run in a serverless environment. This setting ensures that no event is lost if AWS recycles the process.',
{
code: <code />,
}
)}
</p>
</Fragment>
),
configurations: [
{
language: 'csharp',
code: `
type Params = DocsParams;

const getInstallSnippetPackageManager = (params: Params) => `
Install-Package Sentry.AspNetCore -Version ${getPackageVersion(
params,
'sentry.dotnet.aspnetcore',
'3.34.0'
)}`;

const getInstallSnippetCoreCli = (params: Params) => `
dotnet add package Sentry.AspNetCore -v ${getPackageVersion(
params,
'sentry.dotnet.aspnetcore',
'3.34.0'
)}`;

const getConfigureSnippet = (params: Params) => `
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
Expand All @@ -91,7 +35,7 @@ public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFu
// Add Sentry
.UseSentry(o =>
{
o.Dsn = "${dsn}";
o.Dsn = "${params.dsn}";
// When configuring for the first time, to see what the SDK is doing:
o.Debug = true;
// Required in Serverless environments
Expand All @@ -102,60 +46,115 @@ public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFu
})
.UseStartup<Startup>();
}
}
`,
},
],
},
{
type: StepType.VERIFY,
description: t('You can verify your setup by throwing an exception from a function:'),
configurations: [
{
language: 'csharp',
code: `
}`;

const getVerifySnippet = () => `
[Route("api/[controller]")]
public class BadController
{
[HttpGet]
public string Get() => throw null;
}
`,
},
}`;

const onboarding: OnboardingConfig = {
introduction: () =>
tct(
'Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.',
{
language: 'shell',
description: t('And make a request to that lambda:'),
code: 'curl -X GET -I https://url.of.server.aws/api/bad',
},
],
additionalInfo: (
<p>
{tct(
'Check out the [link:Sentry ASP.NET Core] documentation for the complete set of options.',
{
link: (
<ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/" />
),
}
)}
</p>
link: <ExternalLink href="https://www.nuget.org/packages/Sentry.AspNetCore" />,
}
),
},
];
// Configuration End
install: params => [
{
type: StepType.INSTALL,
description: t('Add the Sentry dependency:'),
configurations: [
{
partialLoading: params.sourcePackageRegistries.isLoading,
code: [
{
language: 'powershell',
label: 'Package Manager',
value: 'packageManager',
code: getInstallSnippetPackageManager(params),
},
{
language: 'shell',
label: '.NET Core CLI',
value: 'coreCli',
code: getInstallSnippetCoreCli(params),
},
],
},
],
additionalInfo: tct(
'You can combine this integration with a logging library like [strong:log4net, NLog, or Serilog] to include both request data as well as your logs as breadcrumbs. The logging ingrations also capture events when an error is logged.',
{strong: <strong />}
),
},
],
configure: params => [
{
type: StepType.CONFIGURE,
description: (
<Fragment>
<p>
{tct(
'All [code:ASP.NET Core] configurations are valid here. But one configuration in particular is relevant.',
{
code: <code />,
}
)}
</p>
<p>
{tct(
'[code:FlushOnCompletedRequest] ensures all events are flushed out. This is because the general ASP.NET Core hooks for when the process is exiting are not guaranteed to run in a serverless environment. This setting ensures that no event is lost if AWS recycles the process.',
{
code: <code />,
}
)}
</p>
</Fragment>
),
configurations: [
{
language: 'csharp',
code: getConfigureSnippet(params),
},
],
},
],
verify: () => [
{
type: StepType.VERIFY,
description: t(
'You can verify your setup by throwing an exception from a function:'
),
configurations: [
{
language: 'csharp',
code: getVerifySnippet(),
},
{
language: 'shell',
description: t('And make a request to that lambda:'),
code: 'curl -X GET -I https://url.of.server.aws/api/bad',
},
],
additionalInfo: tct(
'Check out the [link:Sentry ASP.NET Core] documentation for the complete set of options.',
{
link: (
<ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/" />
),
}
),
},
],
};

export function GettingStartedAwsLambda({
dsn,
sourcePackageRegistries,
...props
}: ModuleProps) {
return (
<Layout
steps={steps({dsn, sourcePackageRegistries})}
introduction={introduction}
{...props}
/>
);
}
const docs: Docs = {
onboarding,
};

export default GettingStartedAwsLambda;
export default docs;
10 changes: 5 additions & 5 deletions static/app/gettingStartedDocs/dotnet/dotnet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ExternalLink from 'sentry/components/links/externalLink';
import List from 'sentry/components/list';
import ListItem from 'sentry/components/list/listItem';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {
import type {
Docs,
DocsParams,
OnboardingConfig,
Expand All @@ -14,10 +14,10 @@ import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersi

type Params = DocsParams;

const installSnippetPackageManager = (params: Params) => `
const getInstallSnippetPackageManager = (params: Params) => `
Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;

const installSnippetCoreCli = (params: Params) => `
const getInstallSnippetCoreCli = (params: Params) => `
dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;

const getConfigureSnippet = (params: Params) => `
Expand Down Expand Up @@ -87,13 +87,13 @@ const onboarding: OnboardingConfig = {
language: 'shell',
label: 'Package Manager',
value: 'packageManager',
code: installSnippetPackageManager(params),
code: getInstallSnippetPackageManager(params),
},
{
language: 'shell',
label: '.NET Core CLI',
value: 'coreCli',
code: installSnippetCoreCli(params),
code: getInstallSnippetCoreCli(params),
},
],
},
Expand Down
Loading

0 comments on commit 37cdb15

Please sign in to comment.