go.tsx 2.3 KB

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