flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.78k stars 365 forks source link

Capture exceptions to Sentry service #164

Open lord-alfred opened 5 years ago

lord-alfred commented 5 years ago

I want to try to introduce Sentry service into my installation of this package. Here is its documentation: https://docs.sentry.io/platforms/go/ Advise where it is better to insert it (I did not study Golang, but I know Python)?

Maybe in: https://github.com/flashmob/go-guerrilla/blob/master/cmd/guerrillad/main.go or https://github.com/flashmob/go-guerrilla/blob/master/cmd/guerrillad/serve.go ?

PS: If fatal errors come to me in this service, then I will talk about them. I think it will be useful - as a code review.

flashmob commented 5 years ago

Note that Sentry and other such tools would really be out of my knowledge domain, also not sure where to place them.

Errors are always captured in the error log. Not sure about Sentry, but probably there is a way to get it to read your log, instead of modifying the code?

lord-alfred commented 5 years ago

You did not use Sentry? Try it, it's a great service where there is a free plan for developers. It is difficult to explain what is good in it, you need to try! The main thing is not to publish the access key (DSN URL) here. After registration you may test service via button "Create a sample event", screens from my account: https://imgur.com/a/OVTMmrP

I will try to add this to https://github.com/flashmob/go-guerrilla/blob/master/cmd/guerrillad/serve.go

PS: Sentry not know how to read the log file. It catches errors (I think with panic in golang) in real time and sends notifications (It is necessary for fast reaction, not for post-factum analysis).

flashmob commented 5 years ago

Been using New Relic at work, similar tool - very useful indeed.

Unfortunately can't use something like that on Guerrillamail because there are so many logs generated, it would send the bill through the roof! Also, have no time to maintain additional software, just keeping the stack lean. So can only dream about it.

BTW, There is currently a PR open to refactor the logging so that it will be more useful for these type of tools, and also, to make it less dependant on Logrus. Will be working on this after finishing the stream based backed system.

On Thu., 15 Aug. 2019, 19:40 Lord Alfred, notifications@github.com wrote:

Have you ever used Sentry? Try it, it's a great service where there is a free plan for developers. It is difficult to explain what is good in it, you need to try! The main thing is not to publish the access key (DSN URL) here.

I will try to add this to https://github.com/flashmob/go-guerrilla/blob/master/cmd/guerrillad/serve.go

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/164?email_source=notifications&email_token=AAE6MP2R7EVTDKRQQ5IWEVDQEUXB3A5CNFSM4IJNNBVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4LPLBY#issuecomment-521598343, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MPYE6WG2T4MUS6A673DQEUXB3ANCNFSM4IJNNBVA .

lord-alfred commented 5 years ago

I would like to test Sentry in my guerrilla (I don't have much data). But for several days there were no events, although I saw errors in the log like:

time="2019-08-16T14:01:01+03:00" level=error msg="There was a problem the insert" error="Error 1366: Incorrect string value: '\xF0\x9F\x8D\x9F |...' for column 'subject' at row 1"

time="2019-08-16T14:19:16+03:00" level=error msg="There was a problem the insert" error="invalid connection"

[mysql] 2019/08/15 15:34:04 packets.go:36: unexpected EOF

Maybe I installed Sentry/guerrilla incorrectly? I am doing the installation of guerrilla something like this:

go get github.com/flashmob/go-guerrilla
cd $GOPATH/src/github.com/flashmob/go-guerrilla
go install
mv -f ~/go-guerrilla/cmd/guerrillad/serve.go $GOPATH/src/github.com/flashmob/go-guerrilla/cmd/guerrillad/serve.go
mv -f ~/go-guerrilla/backends/my_backend_name.go $GOPATH/src/github.com/flashmob/go-guerrilla/backends/my_backend_name.go
go get -u github.com/golang/dep/cmd/dep
go get github.com/getsentry/sentry-go
dep ensure
make guerrillad
make test
# copy guerrillad & copy config & install certbot & install monit and other & run guerrillad service 

In file ~/go-guerrilla/cmd/guerrillad/serve.go (copy https://github.com/flashmob/go-guerrilla/blob/master/cmd/guerrillad/serve.go#L105-L108 ), I did the following:

import (

// ...

"github.com/getsentry/sentry-go"
)

// ...

func serve(cmd *cobra.Command, args []string) {
    sentry.Init(sentry.ClientOptions{
        Dsn: "https://KEY@sentry.io/ID",
    })

    logVersion()
    d = guerrilla.Daemon{Logger: mainlog}
    c, err := readConfig(configPath, pidFile)

// ...

I think I could be wrong and sentry.Init needs to be initialized elsewhere. Maybe you have thoughts where to do this?

flashmob commented 5 years ago

The errors look like database errors, have you checked your schema? "Incorrect value" sounds like the column is expecting some kind of specific type of value, but getting something else.

Not sure about Sentry though...

On Sat., 17 Aug. 2019, 16:02 Lord Alfred, notifications@github.com wrote:

I would like to test 111 in my 222 (I don't have much data). But for several days there were no events, although I saw errors in the log like:

time="2019-08-16T14:01:01+03:00" level=error msg="There was a problem the insert" error="Error 1366: Incorrect string value: '\xF0\x9F\x8D\x9F |...' for column 'subject' at row 1"

time="2019-08-16T14:19:16+03:00" level=error msg="There was a problem the insert" error="invalid connection"

[mysql] 2019/08/15 15:34:04 packets.go:36: unexpected EOF

Maybe I installed Sentry/guerrilla incorrectly? I am doing the installation of guerrilla something like this:

go get github.com/flashmob/go-guerrillacd $GOPATH/src/github.com/flashmob/go-guerrilla go install mv -f ~/go-guerrilla/cmd/guerrillad/serve.go $GOPATH/src/github.com/flashmob/go-guerrilla/cmd/guerrillad/serve.go go get -u github.com/golang/dep/cmd/dep go get github.com/getsentry/sentry-go dep ensure make guerrillad# test & copy guerrillad & and other

In file ~/go-guerrilla/cmd/guerrillad/serve.go, I did the following:

import (// ..."github.com/getsentry/sentry-go" )// ...func serve(cmd *cobra.Command, args []string) { sentry.Init(sentry.ClientOptions{ Dsn: "https://KEY@sentry.io/ID", })

logVersion() d = guerrilla.Daemon{Logger: mainlog} c, err := readConfig(configPath, pidFile)// ...

I think I could be wrong and sentry.Init needs to be initialized elsewhere. Maybe you have thoughts where to do this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/164?email_source=notifications&email_token=AAE6MPZM34KCSXE7BSBIKVDQE6PBRA5CNFSM4IJNNBVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QFDEQ#issuecomment-522211730, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MPZFNBY6JBAH4OG35MLQE6PBRANCNFSM4IJNNBVA .

lord-alfred commented 5 years ago

I think that these errors could be due to the absence of &charset=utf8mb4&collation=utf8mb4_unicode_ci in the connection line to mysql. Yesterday I added them and there was not a single such error during the night (but I will follow further).

Those errors were most likely caused by the fact that I use DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci in table creation syntax (and I use COLLATE utf8mb4_unicode_ci for varchar columns). By the way, why do you use DEFAULT CHARSET=utf8 in table creation on the wiki? I previously used utf8 and have problems with various symbols (like emoji), so I started using utf8mb4 and everything was fine. ( see: https://stackoverflow.com/questions/30074492/what-is-the-difference-between-utf8mb4-and-utf8-charsets-in-mysql/30074553 )

PS: If there are ideas about Sentry - write, please. I don’t understand yet whether it works with such initialization or whether it needs to be moved to another place. Although there may simply have been no panic errors, therefore, he did not receive events.

flashmob commented 5 years ago

Oh. Will update to utf8mb4_unicode_ci

Not getting errors myself probably because MySQL strict mode has been disabled.

On Sat., 17 Aug. 2019, 18:48 Lord Alfred, notifications@github.com wrote:

I think that these errors could be due to the absence of &charset=utf8mb4&collation=utf8mb4_unicode_ci in the connection line to mysql. Yesterday I added them and there was not a single such error during the night (but I will follow further).

Those errors were most likely caused by the fact that I use DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci in table creation syntax (and I use COLLATE utf8mb4_unicode_ci for varchar columns). By the way, why do you use DEFAULT CHARSET=utf8 in table creation on the wiki? I previously used utf8 and have problems with various symbols (like emoji), so I started using utf8mb4 and everything was fine. ( see: https://stackoverflow.com/questions/30074492/what-is-the-difference-between-utf8mb4-and-utf8-charsets-in-mysql/30074553 )

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/164?email_source=notifications&email_token=AAE6MP7PXB2U564JVEYBYQDQE7CM7A5CNFSM4IJNNBVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QHY2I#issuecomment-522222697, or mute the thread https://github.com/notifications/unsubscribe-auth/AAE6MP3SZBP7VXOIIP6HIZDQE7CM7ANCNFSM4IJNNBVA .