MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / initSentry

Function initSentry

main.go:49–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47}
48
49func 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
101func getEnvironment() string {
102 if version.BuildVersion == "dev" {

Callers 1

mainFunction · 0.85

Calls 7

LoadConfigFunction · 0.92
getEnvironmentFunction · 0.85
errorFingerprintFunction · 0.85
cleanExceptionTypeFunction · 0.85
setUserContextFunction · 0.85
getInstanceIDFunction · 0.85
InitMethod · 0.45

Tested by

no test coverage detected