serverless.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  10. # of sampled transactions.
  11. # We recommend adjusting this value in production.
  12. profiles_sample_rate=1.0,`;
  13. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  14. # of transactions for performance monitoring.
  15. # We recommend adjusting this value in production.
  16. traces_sample_rate=1.0,`;
  17. export const steps = ({
  18. sentryInitContent,
  19. }: {
  20. sentryInitContent: string;
  21. }): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: (
  25. <Fragment>
  26. <p>
  27. {tct(
  28. '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.',
  29. {
  30. link: (
  31. <ExternalLink href="https://docs.sentry.io/platforms/python/#serverless" />
  32. ),
  33. }
  34. )}
  35. </p>
  36. {t(
  37. 'If you use a serverless provider not directly supported by the SDK, you can use this generic integration.'
  38. )}
  39. </Fragment>
  40. ),
  41. configurations: [
  42. {
  43. language: 'python',
  44. description: (
  45. <p>
  46. {tct(
  47. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  48. {code: <code />}
  49. )}
  50. </p>
  51. ),
  52. code: `
  53. import sentry_sdk
  54. from sentry_sdk.integrations.serverless import serverless_function
  55. sentry_sdk.init(
  56. ${sentryInitContent}
  57. )
  58. @serverless_function
  59. def my_function(...): ...
  60. `,
  61. },
  62. ],
  63. },
  64. ];
  65. // Configuration End
  66. export function GettingStartedWithServerless({
  67. dsn,
  68. activeProductSelection = [],
  69. ...props
  70. }: ModuleProps) {
  71. const otherConfigs: string[] = [];
  72. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  73. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  74. otherConfigs.push(performanceConfiguration);
  75. }
  76. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  77. otherConfigs.push(profilingConfiguration);
  78. }
  79. sentryInitContent = sentryInitContent.concat(otherConfigs);
  80. return (
  81. <Layout
  82. steps={steps({
  83. sentryInitContent: sentryInitContent.join('\n'),
  84. })}
  85. {...props}
  86. />
  87. );
  88. }
  89. export default GettingStartedWithServerless;