()
| 47 | } |
| 48 | |
| 49 | func initSentry() error { |
| 50 | // DSN is injected at build time - if empty, Sentry is disabled |
| 51 | if version.SentryDSN == "" { |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | // Load config for user context only |
| 56 | cfg, _ := cmd.LoadConfig() |
| 57 | |
| 58 | err := sentry.Init(sentry.ClientOptions{ |
| 59 | Dsn: version.SentryDSN, |
| 60 | Environment: getEnvironment(), |
| 61 | Release: fmt.Sprintf("thunder-cli@%s", version.BuildVersion), |
| 62 | Debug: false, |
| 63 | AttachStacktrace: true, |
| 64 | SampleRate: 1.0, |
| 65 | TracesSampleRate: 0.1, |
| 66 | EnableTracing: true, |
| 67 | BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event { |
| 68 | if len(event.Exception) > 0 { |
| 69 | msg := event.Exception[0].Value |
| 70 | event.Fingerprint = []string{errorFingerprint(msg, hint.OriginalException)} |
| 71 | cleanExceptionType(event, hint) |
| 72 | } |
| 73 | return event |
| 74 | }, |
| 75 | }) |
| 76 | if err != nil { |
| 77 | return fmt.Errorf("failed to initialize Sentry: %w", err) |
| 78 | } |
| 79 | |
| 80 | // Set user context (privacy-safe) |
| 81 | if cfg != nil && cfg.Token != "" { |
| 82 | setUserContext(cfg.Token) |
| 83 | } |
| 84 | |
| 85 | // Set global context tags |
| 86 | sentry.ConfigureScope(func(scope *sentry.Scope) { |
| 87 | scope.SetTag("os", runtime.GOOS) |
| 88 | scope.SetTag("arch", runtime.GOARCH) |
| 89 | scope.SetTag("go_version", runtime.Version()) |
| 90 | scope.SetTag("build_commit", version.BuildCommit) |
| 91 | scope.SetTag("service", "thunder-cli") |
| 92 | scope.SetTag("instance_id", getInstanceID()) |
| 93 | if cfg != nil { |
| 94 | scope.SetTag("api_url", cfg.APIURL) |
| 95 | } |
| 96 | }) |
| 97 | |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | func getEnvironment() string { |
| 102 | if version.BuildVersion == "dev" { |
no test coverage detected