chalice.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {t, tct} from 'sentry/locale';
  5. // Configuration Start
  6. export const steps = ({
  7. sentryInitContent,
  8. }: {
  9. sentryInitContent: string;
  10. }): LayoutProps['steps'] => [
  11. {
  12. type: StepType.INSTALL,
  13. description: (
  14. <p>
  15. {tct(
  16. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryBotteCode:chalice] extra:',
  17. {
  18. sentrySdkCode: <code />,
  19. sentryBotteCode: <code />,
  20. }
  21. )}
  22. </p>
  23. ),
  24. configurations: [
  25. {
  26. language: 'bash',
  27. code: 'pip install --upgrade sentry-sdk[chalice]',
  28. },
  29. ],
  30. },
  31. {
  32. type: StepType.CONFIGURE,
  33. description: t(
  34. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  35. ),
  36. configurations: [
  37. {
  38. language: 'python',
  39. code: `
  40. import sentry_sdk
  41. from chalice import Chalice
  42. from sentry_sdk.integrations.chalice import ChaliceIntegration
  43. sentry_sdk.init(
  44. ${sentryInitContent}
  45. )
  46. app = Chalice(app_name="appname")
  47. `,
  48. },
  49. ],
  50. },
  51. {
  52. type: StepType.VERIFY,
  53. description: (
  54. <p>{t('To verify that everything is working trigger an error on purpose:')}</p>
  55. ),
  56. configurations: [
  57. {
  58. language: 'python',
  59. code: `from chalice import Chalice
  60. sentry_sdk.init(
  61. ${sentryInitContent}
  62. )
  63. app = Chalice(app_name="helloworld")
  64. @app.schedule(Rate(1, unit=Rate.MINUTES))
  65. def every_minute(event):
  66. 1/0 # raises an error
  67. @app.route("/")
  68. def index():
  69. 1/0 # raises an error
  70. return {"hello": "world"}`,
  71. },
  72. ],
  73. additionalInfo: (
  74. <p>
  75. {tct(
  76. 'When you enter the [code:"/"] route or the scheduled task is run, an error event will be sent to Sentry.',
  77. {
  78. code: <code />,
  79. }
  80. )}
  81. </p>
  82. ),
  83. },
  84. ];
  85. // Configuration End
  86. export function GettingStartedWithChalice({dsn, ...props}: ModuleProps) {
  87. const otherConfigs: string[] = [];
  88. let sentryInitContent: string[] = [
  89. ` dsn="${dsn}",`,
  90. ` integrations=[ChaliceIntegration()],`,
  91. ];
  92. sentryInitContent = sentryInitContent.concat(otherConfigs);
  93. return (
  94. <Layout
  95. steps={steps({
  96. sentryInitContent: sentryInitContent.join('\n'),
  97. })}
  98. {...props}
  99. />
  100. );
  101. }
  102. export default GettingStartedWithChalice;