go.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. dsn,
  8. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  9. {
  10. type: StepType.INSTALL,
  11. description: (
  12. <p>
  13. {tct('Install our Go SDK using [code:go get]:', {
  14. code: <code />,
  15. })}
  16. </p>
  17. ),
  18. configurations: [
  19. {
  20. language: 'bash',
  21. code: 'go get github.com/getsentry/sentry-go',
  22. },
  23. ],
  24. },
  25. {
  26. type: StepType.CONFIGURE,
  27. description: t(
  28. "Import and initialize the Sentry SDK early in your application's setup:"
  29. ),
  30. configurations: [
  31. {
  32. language: 'go',
  33. code: `
  34. package main
  35. import (
  36. "log"
  37. "github.com/getsentry/sentry-go"
  38. )
  39. func main() {
  40. err := sentry.Init(sentry.ClientOptions{
  41. Dsn: "${dsn}",
  42. // Set TracesSampleRate to 1.0 to capture 100%
  43. // of transactions for performance monitoring.
  44. // We recommend adjusting this value in production,
  45. TracesSampleRate: 1.0,
  46. })
  47. if err != nil {
  48. log.Fatalf("sentry.Init: %s", err)
  49. }
  50. }
  51. `,
  52. },
  53. ],
  54. },
  55. {
  56. type: StepType.VERIFY,
  57. description: t(
  58. 'The quickest way to verify Sentry in your Go program is to capture a message:'
  59. ),
  60. configurations: [
  61. {
  62. language: 'go',
  63. code: `
  64. package main
  65. import (
  66. "log"
  67. "time"
  68. "github.com/getsentry/sentry-go"
  69. )
  70. func main() {
  71. err := sentry.Init(sentry.ClientOptions{
  72. Dsn: "___PUBLIC_DSN___",
  73. // Set TracesSampleRate to 1.0 to capture 100%
  74. // of transactions for performance monitoring.
  75. // We recommend adjusting this value in production,
  76. TracesSampleRate: 1.0,
  77. })
  78. if err != nil {
  79. log.Fatalf("sentry.Init: %s", err)
  80. }
  81. // Flush buffered events before the program terminates.
  82. defer sentry.Flush(2 * time.Second)
  83. sentry.CaptureMessage("It works!")
  84. }
  85. `,
  86. },
  87. ],
  88. },
  89. ];
  90. // Configuration End
  91. export function GettingStartedWithGo({dsn, ...props}: ModuleProps) {
  92. return <Layout steps={steps({dsn})} {...props} />;
  93. }
  94. export default GettingStartedWithGo;