-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
125 lines (102 loc) · 2.93 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"fmt"
"log"
"math/rand"
"os"
"time"
"github.com/getsentry/sentry-go"
)
func main() {
// Initializing Sentry with DSN from environment variables
dsn := os.Getenv("SENTRY_DSN")
if dsn == "" {
log.Fatal("SENTRY_DSN environment variable is required")
}
err := sentry.Init(sentry.ClientOptions{
Dsn: dsn,
TracesSampleRate: 1.0,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
defer sentry.Flush(2 * time.Second)
// Initialization of the random number generator
rand.Seed(time.Now().UnixNano())
// Infinite loop for generating and sending different types of errors
for {
var err error
switch rand.Intn(8) {
case 0:
err = &newCustomError{message: fmt.Sprintf("new custom error: %d", rand.Intn(1000))}
case 1:
err = &anotherNewCustomError{message: fmt.Sprintf("another new custom error: %d", rand.Intn(1000))}
case 2:
err = &yetAnotherNewCustomError{message: fmt.Sprintf("yet another new custom error: %d", rand.Intn(1000))}
case 3:
err = &complexNewCustomError{code: rand.Intn(100), message: fmt.Sprintf("complex new custom error: %d", rand.Intn(1000))}
case 4:
err = &yetAnotherComplexCustomError{code: rand.Intn(100), message: fmt.Sprintf("yet another complex custom error: %d", rand.Intn(1000))}
case 5:
err = &evenMoreComplexCustomError{code: rand.Intn(100), message: fmt.Sprintf("even more complex custom error: %d", rand.Intn(1000))}
case 6:
err = &simpleCustomError{message: fmt.Sprintf("simple custom error: %d", rand.Intn(1000))}
case 7:
err = &anotherSimpleCustomError{message: fmt.Sprintf("another simple custom error: %d", rand.Intn(1000))}
}
sentry.CaptureException(err)
log.Printf("Sent error: %v to Sentry", err)
time.Sleep(100 * time.Millisecond) // Delay to simulate real load
}
}
type newCustomError struct {
message string
}
func (e *newCustomError) Error() string {
return e.message
}
type anotherNewCustomError struct {
message string
}
func (e *anotherNewCustomError) Error() string {
return e.message
}
type yetAnotherNewCustomError struct {
message string
}
func (e *yetAnotherNewCustomError) Error() string {
return e.message
}
type complexNewCustomError struct {
code int
message string
}
func (e *complexNewCustomError) Error() string {
return fmt.Sprintf("code: %d, message: %s", e.code, e.message)
}
type yetAnotherComplexCustomError struct {
code int
message string
}
func (e *yetAnotherComplexCustomError) Error() string {
return fmt.Sprintf("code: %d, message: %s", e.code, e.message)
}
type evenMoreComplexCustomError struct {
code int
message string
}
func (e *evenMoreComplexCustomError) Error() string {
return fmt.Sprintf("code: %d, message: %s", e.code, e.message)
}
type simpleCustomError struct {
message string
}
func (e *simpleCustomError) Error() string {
return e.message
}
type anotherSimpleCustomError struct {
message string
}
func (e *anotherSimpleCustomError) Error() string {
return e.message
}