Skip to content

feat: PowerShell support (frontend) #67576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 4, 2024
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Sentry is a developer-first error tracking and performance monitoring platform t
- [Elixir](https://github.com/getsentry/sentry-elixir)
- [Unity](https://github.com/getsentry/sentry-unity)
- [Unreal Engine](https://github.com/getsentry/sentry-unreal)
- [PowerShell](https://github.com/getsentry/sentry-powershell)

# Resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const BLOCK_COMMENT_SYNTAX_BY_LANGUAGE: Record<string, BlockCommentSyntax[]> = {
julia: [{start: '#=', end: '=#'}],
lua: [{start: '--[[', end: ']]'}],
perl: [{start: {example: '=comment', search: /^\s*?=\S+/m}, end: '=cut'}],
powershell: [{start: '<#', end: '#>'}],
python: [
{start: '"""', end: '"""'},
{start: "'''", end: "'''"},
Expand Down
1 change: 1 addition & 0 deletions static/app/data/platformCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const backend: PlatformKey[] = [
'php-laravel',
'php-monolog',
'php-symfony',
'powershell',
'python',
'python-aiohttp',
'python-asgi',
Expand Down
1 change: 1 addition & 0 deletions static/app/data/platformPickerCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const server: Set<PlatformKey> = new Set([
'php',
'php-laravel',
'php-symfony',
'powershell',
'python',
'python-aiohttp',
'python-asgi',
Expand Down
7 changes: 7 additions & 0 deletions static/app/data/platforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ export const platforms: PlatformIntegration[] = [
language: 'php',
link: 'https://docs.sentry.io/platforms/php/guides/symfony/',
},
{
id: 'powershell',
name: 'PowerShell',
type: 'language',
language: 'powershell',
link: 'https://docs.sentry.io/platforms/powershell/',
},
{
id: 'python',
name: 'Python',
Expand Down
35 changes: 35 additions & 0 deletions static/app/gettingStartedDocs/powershell/powershell.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
import {screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';

import docs from './powershell';

describe('powershell onboarding docs', function () {
it('renders docs correctly', async function () {
renderWithOnboardingLayout(docs, {
releaseRegistry: {
'sentry.powershell': {
version: '1.99.9',
},
},
});

// 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();
expect(
screen.getByRole('heading', {name: 'Performance Monitoring'})
).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Samples'})).toBeInTheDocument();

// Renders SDK version from registry
expect(
await screen.findByText(
textWithMarkupMatcher(
/Install-Module -Name Sentry -Repository PSGallery -RequiredVersion 1\.99\.9/
)
)
).toBeInTheDocument();
});
});
197 changes: 197 additions & 0 deletions static/app/gettingStartedDocs/powershell/powershell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import ExternalLink from 'sentry/components/links/externalLink';
import List from 'sentry/components/list';
import ListItem from 'sentry/components/list/listItem';
import altCrashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/altCrashReportCallout';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import type {
Docs,
DocsParams,
OnboardingConfig,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import {
getCrashReportApiIntroduction,
getCrashReportInstallDescription,
} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
import {t, tct} from 'sentry/locale';
import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';

type Params = DocsParams;

const getConfigureSnippet = (params: Params) => `
# You need to import the module once in a script.
Import-Module Sentry

# Start the Sentry SDK with the default options.
# It may be helpful when investigating issues with your setup to pass \`-Debug\` to \`Start-Sentry\`.
# This enables debug logging (\`Write-Debug\`) for the Sentry client.
# We enable it here for demonstration purposes when first trying Sentry.
# You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
Start-Sentry -Debug {
# A Sentry Data Source Name (DSN) is required.
# See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
# You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
$_.Dsn = '${params.dsn}'

# This option will enable Sentry's tracing features. You still need to start transactions and spans.
# For example, setting the rate to 0.1 would capture 10% of transactions.
$_.TracesSampleRate = 1.0
}

# Later on in your production script, you should omit the \`-Debug\` flag.:
Start-Sentry {
$_.Dsn = '${params.dsn}'
$_.TracesSampleRate = 0.1
}`;

const getPerformanceMonitoringSnippet = () => `
# Transaction can be started by providing, at minimum, the name and the operation
$transaction = Start-SentryTransaction 'test-transaction-name' 'test-transaction-operation'

# Transactions can have child spans (and those spans can have child spans as well)
$span = $transaction.StartChild("test-child-operation")
# ...
# (Perform the operation represented by the span/transaction)
# ...
$span.Finish() # Mark the span as finished

$span = $transaction.StartChild("another-span")
# ...
$span.Finish()

$transaction.Finish() # Mark the transaction as finished and send it to Sentry`;

const onboarding: OnboardingConfig = {
introduction: () =>
t(
'Sentry for PowerShell module supports PowerShell 7.2+ on Windows, macOS, and Linux as well as Windows PowerShell 5.1+.'
),
install: params => [
{
type: StepType.INSTALL,
description: t('Install the module:'),
configurations: [
{
partialLoading: params.sourcePackageRegistries.isLoading,
code: [
{
language: 'powershell',
label: 'Install Module',
value: 'powershellget',
code: `Install-Module -Name Sentry -Repository PSGallery -RequiredVersion ${getPackageVersion(params, 'sentry.powershell', '1.0.0')} -Force`,
},
],
},
],
},
],
configure: params => [
{
type: StepType.CONFIGURE,
description: tct('Initialize the SDK as early as possible.'),
configurations: [
{
language: 'powershell',
code: getConfigureSnippet(params),
},
],
},
],
verify: () => [
{
type: StepType.VERIFY,
description: t('Verify Sentry is correctly configured by sending a message:'),
configurations: [
{
language: 'powershell',
code: '"Something went wrong" | Out-Sentry',
},
],
},
{
title: t('Performance Monitoring'),
description: t(
'You can measure the performance of your code by capturing transactions and spans.'
),
configurations: [
{
language: 'powershell',
code: getPerformanceMonitoringSnippet(),
},
],
additionalInfo: tct(
'Check out [link:the documentation] to learn more about the API and instrumentations.',
{
link: (
<ExternalLink href="https://docs.sentry.io/platforms/powershell/performance/instrumentation/" />
),
}
),
},
{
title: t('Samples'),
description: t('You can find sample usage of the SDK:'),
configurations: [
{
description: (
<List symbol="bullet">
<ListItem>
{tct('[link:Samples in the [code:powershell] SDK repository]', {
link: (
<ExternalLink href="https://github.com/getsentry/sentry-powershell/tree/main/samples" />
),
code: <code />,
})}
</ListItem>
<ListItem>
{tct(
'[link:Many more samples in the [code:dotnet] SDK repository] [strong:(C#)]',
{
link: (
<ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
),
code: <code />,
strong: <strong />,
}
)}
</ListItem>
</List>
),
},
],
},
],
};

export const powershellFeedbackOnboarding: OnboardingConfig = {
introduction: () => getCrashReportApiIntroduction(),
install: () => [
{
type: StepType.INSTALL,
description: getCrashReportInstallDescription(),
configurations: [
{
code: [
{
label: 'PowerShell',
value: 'powershell',
language: 'powershell',
code: `$eventId = "An event that will receive user feedback." | Out-Sentry
[Sentry.SentrySdk]::CaptureUserFeedback($eventId, "user@example.com", "It broke.", "The User")`,
},
],
},
],
additionalInfo: altCrashReportCallout(),
},
],
configure: () => [],
verify: () => [],
nextSteps: () => [],
};

const docs: Docs = {
onboarding,
feedbackOnboardingCrashApi: powershellFeedbackOnboarding,
};

export default docs;
1 change: 1 addition & 0 deletions static/app/types/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export type PlatformKey =
| 'php-monolog'
| 'php-symfony'
| 'php-symfony2'
| 'powershell'
| 'python'
| 'python-aiohttp'
| 'python-asgi'
Expand Down
2 changes: 2 additions & 0 deletions static/app/utils/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const platforms = [
'node',
'perl',
'php',
'powershell',
'python',
'react-native',
'ruby',
Expand All @@ -32,6 +33,7 @@ const performancePlatforms: DocPlatform[] = [
'javascript',
'node',
'php',
'powershell',
'python',
'react-native',
'ruby',
Expand Down
1 change: 1 addition & 0 deletions static/app/utils/fileExtension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const FILE_EXTENSION_TO_PLATFORM = {
fs: 'fsharp',
vb: 'visualbasic',
ps1: 'powershell',
psd1: 'powershell',
psm1: 'powershell',
kt: 'kotlin',
dart: 'dart',
Expand Down
Loading