diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 56429c1..86d8580 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -49,7 +49,7 @@ jobs: --health-retries 5 steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 6f6788d..ca31b96 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -49,7 +49,7 @@ jobs: --health-retries 5 steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/Dockerfile b/Dockerfile index ac8b33e..a923aac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20-bookworm AS builder +FROM golang:1.21-bookworm AS builder WORKDIR /app diff --git a/captcha/answer.go b/captcha/answer.go index a6e11e7..c6e2a22 100644 --- a/captcha/answer.go +++ b/captcha/answer.go @@ -32,6 +32,11 @@ func (d *Dependencies) WaitForAnswer(ctx context.Context, m *tb.Message) { return } + span := sentry.StartSpan(ctx, "captcha.wait_for_answer", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha WaitForAnswer")) + defer span.Finish() + ctx = span.Context() + // Check if the answer is correct or not. // If not, ask them to give the correct answer and time remaining. // If yes, delete the message and remove the user from the captcha:users list. diff --git a/captcha/join.go b/captcha/join.go index ce78fc2..c26c859 100644 --- a/captcha/join.go +++ b/captcha/join.go @@ -5,9 +5,9 @@ import ( "context" "encoding/json" "errors" + "github.com/getsentry/sentry-go" "strconv" "strings" - "sync" "time" "teknologi-umum-captcha/shared" @@ -59,6 +59,10 @@ var DefaultQuestion = "Halo, {user}!\n\n" + // At the end of the function, it will create 2 goroutines in which // both of them are responsible for kicking the user out of the group. func (d *Dependencies) CaptchaUserJoin(ctx context.Context, m *tb.Message) { + span := sentry.StartSpan(ctx, "captcha.user_join") + defer span.Finish() + ctx = span.Context() + // Check if the user is an admin or bot first. // If they are, return. // If they're not, continue to execute the captcha. @@ -214,8 +218,7 @@ SENDMSG_RETRY: return } - cond := sync.NewCond(&sync.Mutex{}) - go d.waitOrDelete(ctx, m, cond) + d.waitOrDelete(ctx, m) } func sanitizeInput(inp string) string { diff --git a/captcha/leave.go b/captcha/leave.go index 646175d..3d6ad5c 100644 --- a/captcha/leave.go +++ b/captcha/leave.go @@ -3,6 +3,7 @@ package captcha import ( "context" "encoding/json" + "github.com/getsentry/sentry-go" "strconv" "teknologi-umum-captcha/shared" @@ -42,6 +43,11 @@ func (d *Dependencies) CaptchaUserLeave(ctx context.Context, m *tb.Message) { return } + span := sentry.StartSpan(ctx, "captcha.captcha_user_leave", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha CaptchaUserLeave")) + defer span.Finish() + ctx = span.Context() + // OK, they exist in the cache. Now we've got to delete // all the message that we've sent before. data, err := d.Memory.Get(strconv.FormatInt(m.Chat.ID, 10) + ":" + strconv.FormatInt(m.Sender.ID, 10)) diff --git a/captcha/non.go b/captcha/non.go index d338fc9..cd501be 100644 --- a/captcha/non.go +++ b/captcha/non.go @@ -3,6 +3,7 @@ package captcha import ( "context" "encoding/json" + "github.com/getsentry/sentry-go" "strconv" "time" @@ -28,6 +29,11 @@ func (d *Dependencies) NonTextListener(ctx context.Context, m *tb.Message) { return } + span := sentry.StartSpan(ctx, "captcha.non_text_listener", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha NonTextListener")) + defer span.Finish() + ctx = span.Context() + // Check if the answer is correct or not. // If not, ask them to give the correct answer and time remaining. // If yes, delete the message and remove the user from the captcha:users list. diff --git a/captcha/wait.go b/captcha/wait.go index 54a0748..7e1de4f 100644 --- a/captcha/wait.go +++ b/captcha/wait.go @@ -5,7 +5,6 @@ import ( "encoding/json" "strconv" "strings" - "sync" "time" "teknologi-umum-captcha/shared" @@ -17,13 +16,10 @@ import ( ) // waitOrDelete will start a timer. If the timer is expired, it will kick the user from the group. -func (d *Dependencies) waitOrDelete(ctx context.Context, msgUser *tb.Message, cond *sync.Cond) { +func (d *Dependencies) waitOrDelete(ctx context.Context, msgUser *tb.Message) { // Let's start the timer, shall we? t := time.NewTimer(Timeout) - // We need to wait for the timer to expire. - cond.L.Lock() - for _, ok := <-t.C; ok; { // Now, when the timer is already finished, we want to check // whether the User ID is still in the cache. @@ -149,12 +145,8 @@ func (d *Dependencies) waitOrDelete(ctx context.Context, msgUser *tb.Message, co shared.HandleBotError(ctx, err, d.Bot, msgUser) break } - - // We're done here. Let's send the value to the done channel. } break } - cond.Broadcast() - cond.L.Unlock() } diff --git a/captcha/welcome.go b/captcha/welcome.go index 52ee4f9..9dd05b4 100644 --- a/captcha/welcome.go +++ b/captcha/welcome.go @@ -3,6 +3,7 @@ package captcha import ( "context" "fmt" + "github.com/getsentry/sentry-go" "math/rand" "strconv" "strings" @@ -63,6 +64,9 @@ var regularWelcomeMessage = "Halo, {user}!\n\n" + // sendWelcomeMessage literally does what it's written. func (d *Dependencies) sendWelcomeMessage(ctx context.Context, m *tb.Message) error { + span := sentry.StartSpan(ctx, "captcha.send_welcome_message") + defer span.Finish() + var msgToSend string = regularWelcomeMessage if strconv.FormatInt(m.Chat.ID, 10) == d.TeknumID { diff --git a/cmd/cmd.go b/cmd/cmd.go index 9e7d3e6..0acc613 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -105,13 +105,18 @@ func (d *Dependency) OnUserJoinHandler(c tb.Context) error { ctx = sentry.SetHubOnContext(ctx, sentry.CurrentHub().Clone()) + span := sentry.StartSpan(ctx, "bot.on_user_join_handler", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha OnUserJoinHandler")) + defer span.Finish() + ctx = span.Context() + underAttack, err := d.underAttack.AreWe(ctx, c.Chat().ID) if err != nil { shared.HandleError(ctx, err) } if underAttack { - err := d.underAttack.Kicker(c) + err := d.underAttack.Kicker(ctx, c) if err != nil { shared.HandleBotError(ctx, err, d.Bot, c.Message()) } @@ -164,7 +169,7 @@ func (d *Dependency) AsciiCmdHandler(c tb.Context) error { return nil } -// BadWordsCmdHandler handle the /badwords command. +// BadWordHandler handle the /badwords command. // This can only be accessed by some users on Telegram // and only valid for private chats. func (d *Dependency) BadWordHandler(c tb.Context) error { diff --git a/go.mod b/go.mod index 723484b..2600f61 100644 --- a/go.mod +++ b/go.mod @@ -5,16 +5,16 @@ go 1.20 require ( github.com/aldy505/asciitxt v0.0.2 github.com/allegro/bigcache/v3 v3.1.0 - github.com/getsentry/sentry-go v0.23.0 + github.com/getsentry/sentry-go v0.25.0 github.com/go-chi/chi/v5 v5.0.10 github.com/jmoiron/sqlx v1.3.5 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 github.com/pkg/errors v0.9.1 - github.com/rs/cors v1.9.0 + github.com/rs/cors v1.10.1 github.com/unrolled/secure v1.13.0 - go.mongodb.org/mongo-driver v1.12.1 - gopkg.in/telebot.v3 v3.1.3 + go.mongodb.org/mongo-driver v1.13.1 + gopkg.in/telebot.v3 v3.2.1 ) require ( @@ -25,8 +25,8 @@ require ( github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect - golang.org/x/crypto v0.12.0 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect + golang.org/x/crypto v0.7.0 // indirect + golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 7d62d45..e2aabcb 100644 --- a/go.sum +++ b/go.sum @@ -118,13 +118,9 @@ github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/getsentry/sentry-go v0.20.0 h1:bwXW98iMRIWxn+4FgPW7vMrjmbym6HblXALmhjHmQaQ= -github.com/getsentry/sentry-go v0.20.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= -github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE= -github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= +github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= -github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -264,8 +260,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -289,16 +283,12 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.8 h1:3fdt97i/cwSU83+E0hZTC/Xpc9mTZxc6UWSCRcSbxiE= -github.com/lib/pq v1.10.8/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -369,12 +359,9 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= -github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE= -github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= +github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/crypt v0.6.0/go.mod h1:U8+INwJo3nBv1m6A/8OBXAq7Jnpspk5AxSgDyEQcea8= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -401,19 +388,13 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/unrolled/secure v1.13.0 h1:sdr3Phw2+f8Px8HE5sd1EHdj1aV3yUwed/uZXChLFsk= github.com/unrolled/secure v1.13.0/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= -github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= @@ -429,10 +410,8 @@ go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dY go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU= go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= -go.mongodb.org/mongo-driver v1.11.4 h1:4ayjakA013OdpGyL2K3ZqylTac/rMjrJOMZ1EHizXas= -go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= -go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= -go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= +go.mongodb.org/mongo-driver v1.13.1 h1:YIc7HTYsKndGK4RFzJ3covLz1byri52x0IoMB0Pt/vk= +go.mongodb.org/mongo-driver v1.13.1/go.mod h1:wcDf1JBCXy2mOW0bWHwO/IOYqdca1MPCwDtFu/Z9+eo= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -459,8 +438,6 @@ golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -579,8 +556,6 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -660,10 +635,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -677,10 +650,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -921,8 +892,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/telebot.v3 v3.1.3 h1:T+CTyOWpZMqp3ALHSweNgp1awQ9nMXdRAMpe/r6x9/s= -gopkg.in/telebot.v3 v3.1.3/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko= +gopkg.in/telebot.v3 v3.2.1 h1:3I4LohaAyJBiivGmkfB+CiVu7QFOWkuZ4+KHgO/G3rs= +gopkg.in/telebot.v3 v3.2.1/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index d2619c7..7994031 100644 --- a/main.go +++ b/main.go @@ -86,10 +86,12 @@ func init() { func main() { // Setup Sentry for error handling. err := sentry.Init(sentry.ClientOptions{ - Dsn: os.Getenv("SENTRY_DSN"), - AttachStacktrace: true, - Debug: os.Getenv("ENVIRONMENT") == "development", - Environment: os.Getenv("ENVIRONMENT"), + Dsn: os.Getenv("SENTRY_DSN"), + Debug: os.Getenv("ENVIRONMENT") == "development", + Environment: os.Getenv("ENVIRONMENT"), + SampleRate: 1.0, + TracesSampleRate: 0.2, + ProfilesSampleRate: 0.1, }) if err != nil { log.Fatal("during initiating a new sentry client:", errors.WithStack(err)) diff --git a/underattack/are_we.go b/underattack/are_we.go index 893613e..bdca8b3 100644 --- a/underattack/are_we.go +++ b/underattack/are_we.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "github.com/getsentry/sentry-go" "strconv" "time" @@ -12,6 +13,10 @@ import ( // AreWe ...on under attack mode? func (d *Dependency) AreWe(ctx context.Context, chatID int64) (bool, error) { + span := sentry.StartSpan(ctx, "underattack.are_we", sentry.WithTransactionName("Are we under attack?")) + defer span.Finish() + ctx = span.Context() + underAttackCache, err := d.Memory.Get("underattack:" + strconv.FormatInt(chatID, 10)) if err != nil && !errors.Is(err, bigcache.ErrEntryNotFound) { return false, err diff --git a/underattack/handler.go b/underattack/handler.go index 52b7b8a..2c44b40 100644 --- a/underattack/handler.go +++ b/underattack/handler.go @@ -19,6 +19,11 @@ func (d *Dependency) EnableUnderAttackModeHandler(ctx context.Context, c tb.Cont return nil } + span := sentry.StartSpan(ctx, "bot.enable_under_attack_mode_handler", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha EnableUnderAttackModeHandler")) + defer span.Finish() + ctx = span.Context() + sentry.GetHubFromContext(ctx).AddBreadcrumb(&sentry.Breadcrumb{ Type: "user", Category: "command.triggered", @@ -239,6 +244,11 @@ func (d *Dependency) DisableUnderAttackModeHandler(ctx context.Context, c tb.Con return nil } + span := sentry.StartSpan(ctx, "bot.disable_under_attack_mode_handler", sentry.WithTransactionSource(sentry.SourceTask), + sentry.WithTransactionName("Captcha DisableUnderAttackModeHandler")) + defer span.Finish() + ctx = span.Context() + admins, err := c.Bot().AdminsOf(c.Chat()) if err != nil { shared.HandleBotError(ctx, err, d.Bot, c.Message()) diff --git a/underattack/kicker.go b/underattack/kicker.go index 3902196..fbcc33d 100644 --- a/underattack/kicker.go +++ b/underattack/kicker.go @@ -1,7 +1,9 @@ package underattack import ( + "context" "fmt" + "github.com/getsentry/sentry-go" "strconv" "strings" "time" @@ -9,7 +11,10 @@ import ( tb "gopkg.in/telebot.v3" ) -func (d *Dependency) Kicker(c tb.Context) error { +func (d *Dependency) Kicker(ctx context.Context, c tb.Context) error { + span := sentry.StartSpan(ctx, "underattack.kicker") + defer span.Finish() + for { err := c.Bot().Ban(c.Chat(), &tb.ChatMember{User: c.Sender(), RestrictedUntil: tb.Forever()}) if err != nil { diff --git a/underattack/repo.go b/underattack/repo.go index 79c928f..73f506a 100644 --- a/underattack/repo.go +++ b/underattack/repo.go @@ -6,11 +6,15 @@ import ( "errors" "time" + "github.com/getsentry/sentry-go" "teknologi-umum-captcha/shared" ) // GetUnderAttackEntry will acquire under attack entry for specified groupID. func (d *Dependency) GetUnderAttackEntry(ctx context.Context, groupID int64) (underattack, error) { + span := sentry.StartSpan(ctx, "underattack.get_under_attack_entry") + defer span.Finish() + c, err := d.DB.Connx(ctx) if err != nil { return underattack{}, err @@ -127,6 +131,9 @@ func (d *Dependency) CreateNewEntry(ctx context.Context, groupID int64) error { // SetUnderAttackStatus will update the given groupID entry to the given parameters. // If the groupID entry does not exists, it will create a new one. func (d *Dependency) SetUnderAttackStatus(ctx context.Context, groupID int64, underAttack bool, expiresAt time.Time, notificationMessageID int64) error { + span := sentry.StartSpan(ctx, "underattack.set_under_attack_status") + defer span.Finish() + c, err := d.DB.Connx(ctx) if err != nil { return err diff --git a/underattack/underattack_test.go b/underattack/underattack_test.go index b518d3e..ca05cdc 100644 --- a/underattack/underattack_test.go +++ b/underattack/underattack_test.go @@ -3,6 +3,7 @@ package underattack_test import ( "context" "database/sql" + "github.com/getsentry/sentry-go" "log" "os" "testing" @@ -43,6 +44,8 @@ func TestMain(m *testing.M) { log.Fatal(err) } + _ = sentry.Init(sentry.ClientOptions{}) + dependency = &underattack.Dependency{ Memory: memory, DB: db,