powershell.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import List from 'sentry/components/list';
  3. import ListItem from 'sentry/components/list/listItem';
  4. import altCrashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/altCrashReportCallout';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {
  12. getCrashReportApiIntroduction,
  13. getCrashReportInstallDescription,
  14. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  15. import {t, tct} from 'sentry/locale';
  16. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  17. type Params = DocsParams;
  18. const getConfigureSnippet = (params: Params) => `
  19. # You need to import the module once in a script.
  20. Import-Module Sentry
  21. # Start the Sentry SDK with the default options.
  22. # It may be helpful when investigating issues with your setup to pass \`-Debug\` to \`Start-Sentry\`.
  23. # This enables debug logging (\`Write-Debug\`) for the Sentry client.
  24. # We enable it here for demonstration purposes when first trying Sentry.
  25. # You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
  26. Start-Sentry -Debug {
  27. # A Sentry Data Source Name (DSN) is required.
  28. # See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
  29. # You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
  30. $_.Dsn = '${params.dsn.public}'
  31. # This option will enable Sentry's tracing features. You still need to start transactions and spans.
  32. # For example, setting the rate to 0.1 would capture 10% of transactions.
  33. $_.TracesSampleRate = 1.0
  34. }
  35. # Later on in your production script, you should omit the \`-Debug\` flag.:
  36. Start-Sentry {
  37. $_.Dsn = '${params.dsn.public}'
  38. $_.TracesSampleRate = 0.1
  39. }`;
  40. const getPerformanceMonitoringSnippet = () => `
  41. # Transaction can be started by providing, at minimum, the name and the operation
  42. $transaction = Start-SentryTransaction 'test-transaction-name' 'test-transaction-operation'
  43. # Transactions can have child spans (and those spans can have child spans as well)
  44. $span = $transaction.StartChild("test-child-operation")
  45. # ...
  46. # (Perform the operation represented by the span/transaction)
  47. # ...
  48. $span.Finish() # Mark the span as finished
  49. $span = $transaction.StartChild("another-span")
  50. # ...
  51. $span.Finish()
  52. $transaction.Finish() # Mark the transaction as finished and send it to Sentry`;
  53. const onboarding: OnboardingConfig = {
  54. introduction: () =>
  55. t(
  56. 'Sentry for PowerShell module supports PowerShell 7.2+ on Windows, macOS, and Linux as well as Windows PowerShell 5.1+.'
  57. ),
  58. install: params => [
  59. {
  60. type: StepType.INSTALL,
  61. description: t('Install the module:'),
  62. configurations: [
  63. {
  64. partialLoading: params.sourcePackageRegistries.isLoading,
  65. code: [
  66. {
  67. language: 'powershell',
  68. label: 'Install Module',
  69. value: 'powershellget',
  70. code: `Install-Module -Name Sentry -Repository PSGallery -RequiredVersion ${getPackageVersion(params, 'sentry.dotnet.powershell', '0.0.2')} -Force`,
  71. },
  72. ],
  73. },
  74. ],
  75. },
  76. ],
  77. configure: params => [
  78. {
  79. type: StepType.CONFIGURE,
  80. description: t('Initialize the SDK as early as possible.'),
  81. configurations: [
  82. {
  83. language: 'powershell',
  84. code: getConfigureSnippet(params),
  85. },
  86. ],
  87. },
  88. ],
  89. verify: () => [
  90. {
  91. type: StepType.VERIFY,
  92. description: t('Verify Sentry is correctly configured by sending a message:'),
  93. configurations: [
  94. {
  95. language: 'powershell',
  96. code: '"Something went wrong" | Out-Sentry',
  97. },
  98. ],
  99. },
  100. {
  101. title: t('Tracing'),
  102. description: t(
  103. 'You can measure the performance of your code by capturing transactions and spans.'
  104. ),
  105. configurations: [
  106. {
  107. language: 'powershell',
  108. code: getPerformanceMonitoringSnippet(),
  109. },
  110. ],
  111. additionalInfo: tct(
  112. 'Check out [link:the documentation] to learn more about the API and instrumentations.',
  113. {
  114. link: (
  115. <ExternalLink href="https://docs.sentry.io/platforms/powershell/tracing/instrumentation/" />
  116. ),
  117. }
  118. ),
  119. },
  120. {
  121. title: t('Samples'),
  122. description: t('You can find sample usage of the SDK:'),
  123. configurations: [
  124. {
  125. description: (
  126. <List symbol="bullet">
  127. <ListItem>
  128. {tct('[link:Samples in the [code:powershell] SDK repository]', {
  129. link: (
  130. <ExternalLink href="https://github.com/getsentry/sentry-powershell/tree/main/samples" />
  131. ),
  132. code: <code />,
  133. })}
  134. </ListItem>
  135. <ListItem>
  136. {tct(
  137. '[link:Many more samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  138. {
  139. link: (
  140. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  141. ),
  142. code: <code />,
  143. strong: <strong />,
  144. }
  145. )}
  146. </ListItem>
  147. </List>
  148. ),
  149. },
  150. ],
  151. },
  152. ],
  153. };
  154. export const powershellFeedbackOnboarding: OnboardingConfig = {
  155. introduction: () => getCrashReportApiIntroduction(),
  156. install: () => [
  157. {
  158. type: StepType.INSTALL,
  159. description: getCrashReportInstallDescription(),
  160. configurations: [
  161. {
  162. code: [
  163. {
  164. label: 'PowerShell',
  165. value: 'powershell',
  166. language: 'powershell',
  167. code: `$eventId = "An event that will receive user feedback." | Out-Sentry
  168. [Sentry.SentrySdk]::CaptureUserFeedback($eventId, "user@example.com", "It broke.", "The User")`,
  169. },
  170. ],
  171. },
  172. ],
  173. additionalInfo: altCrashReportCallout(),
  174. },
  175. ],
  176. configure: () => [],
  177. verify: () => [],
  178. nextSteps: () => [],
  179. };
  180. const docs: Docs = {
  181. onboarding,
  182. feedbackOnboardingCrashApi: powershellFeedbackOnboarding,
  183. };
  184. export default docs;