serverless.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  7. import {t, tct} from 'sentry/locale';
  8. // Configuration Start
  9. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  10. # of transactions for performance monitoring.
  11. traces_sample_rate=1.0,`;
  12. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  13. # of sampled transactions.
  14. # We recommend adjusting this value in production.
  15. profiles_sample_rate=1.0,`;
  16. export const steps = ({
  17. sentryInitContent,
  18. }: {
  19. sentryInitContent: string;
  20. }): LayoutProps['steps'] => [
  21. {
  22. type: StepType.INSTALL,
  23. description: (
  24. <Fragment>
  25. <p>
  26. {tct(
  27. 'It is recommended to use an [link:integration for your particular serverless environment if available], as those are easier to use and capture more useful information.',
  28. {
  29. link: (
  30. <ExternalLink href="https://docs.sentry.io/platforms/python/#serverless" />
  31. ),
  32. }
  33. )}
  34. </p>
  35. {t(
  36. 'If you use a serverless provider not directly supported by the SDK, you can use this generic integration.'
  37. )}
  38. </Fragment>
  39. ),
  40. configurations: [
  41. {
  42. language: 'python',
  43. description: (
  44. <p>
  45. {tct(
  46. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  47. {code: <code />}
  48. )}
  49. </p>
  50. ),
  51. code: `
  52. import sentry_sdk
  53. from sentry_sdk.integrations.serverless import serverless_function
  54. sentry_sdk.init(
  55. ${sentryInitContent}
  56. )
  57. @serverless_function
  58. def my_function(...): ...
  59. `,
  60. },
  61. ],
  62. },
  63. {
  64. type: StepType.VERIFY,
  65. description: (
  66. <p>
  67. {tct(
  68. 'Wrap a functions with the [code:serverless_function] that triggers an error:',
  69. {
  70. code: <code />,
  71. }
  72. )}
  73. </p>
  74. ),
  75. configurations: [
  76. {
  77. language: 'python',
  78. code: `import sentry_sdk
  79. from sentry_sdk.integrations.serverless import serverless_function
  80. sentry_sdk.init(
  81. ${sentryInitContent}
  82. )
  83. @serverless_function
  84. def my_function(...):
  85. 1/0 # raises an error
  86. `,
  87. },
  88. ],
  89. additionalInfo: (
  90. <p>
  91. {tct(
  92. 'Now deploy your function. When you now run your function an error event will be sent to Sentry.',
  93. {}
  94. )}
  95. </p>
  96. ),
  97. },
  98. ];
  99. // Configuration End
  100. export function GettingStartedWithServerless({
  101. dsn,
  102. activeProductSelection = [],
  103. ...props
  104. }: ModuleProps) {
  105. const otherConfigs: string[] = [];
  106. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  107. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  108. otherConfigs.push(performanceConfiguration);
  109. }
  110. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  111. otherConfigs.push(profilingConfiguration);
  112. }
  113. sentryInitContent = sentryInitContent.concat(otherConfigs);
  114. return (
  115. <Layout
  116. steps={steps({
  117. sentryInitContent: sentryInitContent.join('\n'),
  118. })}
  119. {...props}
  120. />
  121. );
  122. }
  123. export default GettingStartedWithServerless;