From 2d3ce7b383c955986d9e2635584a5baf524c5d83 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:23:34 -0700 Subject: [PATCH 01/19] Add key for storing values in context.Context --- client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client.go b/client.go index cc18da7..4786a78 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,8 @@ import ( "strings" ) +const honeybadgerCtxKey = "honeybadger-go-ctx" + // The Payload interface is implemented by any type which can be handled by the // Backend interface. type Payload interface { From 4469ff654d14b5d37967fa674d42a80bf969f6c9 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:52:10 -0700 Subject: [PATCH 02/19] Add error for when casting fails --- client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client.go b/client.go index 4786a78..a8bd116 100644 --- a/client.go +++ b/client.go @@ -1,12 +1,15 @@ package honeybadger import ( + "fmt" "net/http" "strings" ) const honeybadgerCtxKey = "honeybadger-go-ctx" +var noCastErr = fmt.Errorf("unable to cast value from context properly") + // The Payload interface is implemented by any type which can be handled by the // Backend interface. type Payload interface { From 701467c3e84c8418737067f23c95ee21d4233d3d Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:52:39 -0700 Subject: [PATCH 03/19] Update `Client.SetContext` to require `context.Context` To keep the Honeybadger context scoped to a single request, store the `*contextSync` value in a `context.Context`. This way there's no possibility of the request context data being overwritten due to the function being called in a concurrent setting. --- client.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index a8bd116..f9c2931 100644 --- a/client.go +++ b/client.go @@ -1,6 +1,7 @@ package honeybadger import ( + "context" "fmt" "net/http" "strings" @@ -39,8 +40,25 @@ func (client *Client) Configure(config Configuration) { } // SetContext updates the client context with supplied context. -func (client *Client) SetContext(context Context) { - client.context.Update(context) +func (client *Client) SetContext(ctx context.Context, val Context) context.Context { + var clientContext *contextSync + + tmp := ctx.Value(honeybadgerCtxKey) + if tmp == nil { + clientContext = &contextSync{ + internal: Context{}, + } + } else { + if cc, ok := tmp.(*contextSync); ok { + clientContext = cc + } else { + panic(noCastErr) + } + } + + clientContext.Update(val) + + return context.WithValue(ctx, honeybadgerCtxKey, clientContext) } // Flush blocks until the worker has processed its queue. From 2b9ad5e8dcc0d041be5dc65a161fcb045b0f6f4d Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:54:33 -0700 Subject: [PATCH 04/19] Update `Client.Notify` to require `context.Context` In order to get the context stored in the `Client.SetContext` call, need to require a context as the first argument. --- client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index f9c2931..02fe4e1 100644 --- a/client.go +++ b/client.go @@ -74,8 +74,14 @@ func (client *Client) BeforeNotify(handler func(notice *Notice) error) { } // Notify reports the error err to the Honeybadger service. -func (client *Client) Notify(err interface{}, extra ...interface{}) (string, error) { - extra = append([]interface{}{client.context.internal}, extra...) +func (client *Client) Notify(ctx context.Context, err interface{}, extra ...interface{}) (string, error) { + val, ok := ctx.Value(honeybadgerCtxKey).(*contextSync) + if ok { + val.Lock() + extra = append([]interface{}{val.internal}, extra...) + val.Unlock() + } + notice := newNotice(client.Config, newError(err, 2), extra...) for _, handler := range client.beforeNotifyHandlers { if err := handler(notice); err != nil { From 0eee8d02ae724b4281d49c26d443f14536bd1618 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:55:29 -0700 Subject: [PATCH 05/19] Update Monitor to require `context.Context` Same as other functions, `client.Notify` requires a `context.Context` as the first argument so Monitor has to be updated as well. Does mean that a panic won't have the context information unless it's called within the function that might panic instead of at the top level. Ie: ``` func main(){ ctx := context.Background() defer honeybadger.Monitor(ctx) // set up http handlers and whatnot } ``` Won't be able to get the values set unless it's called like so: ``` func handler(w http.ResponseWriter, r *http.Request){ defer honeybadger.Monitor(r.Context()) // rest of handler } ``` --- client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 02fe4e1..105048a 100644 --- a/client.go +++ b/client.go @@ -103,9 +103,9 @@ func (client *Client) Notify(ctx context.Context, err interface{}, extra ...inte // Monitor automatically reports panics which occur in the function it's called // from. Must be deferred. -func (client *Client) Monitor() { +func (client *Client) Monitor(ctx context.Context) { if err := recover(); err != nil { - client.Notify(newError(err, 2)) + client.Notify(ctx, newError(err, 2)) client.Flush() panic(err) } From b4e01f1fa06cf92afee6bbf4621488f6e789eba3 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:59:30 -0700 Subject: [PATCH 06/19] No more need for `Client.context`, so removing it --- client.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 105048a..45f74f5 100644 --- a/client.go +++ b/client.go @@ -29,7 +29,6 @@ type noticeHandler func(*Notice) error // the configuration and implements the public API. type Client struct { Config *Configuration - context *contextSync worker worker beforeNotifyHandlers []noticeHandler } @@ -135,9 +134,8 @@ func New(c Configuration) *Client { worker := newBufferedWorker(config) client := Client{ - Config: config, - worker: worker, - context: newContextSync(), + Config: config, + worker: worker, } return &client From 6f6033de9624f1368ac214275cd39cbcd703fb94 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 12:59:44 -0700 Subject: [PATCH 07/19] Update `Client.Handler` to use `r.Context()` --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 45f74f5..77ce1e6 100644 --- a/client.go +++ b/client.go @@ -119,7 +119,7 @@ func (client *Client) Handler(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { defer func() { if err := recover(); err != nil { - client.Notify(newError(err, 2), Params(r.Form), getCGIData(r), *r.URL) + client.Notify(r.Context(), newError(err, 2), Params(r.Form), getCGIData(r), *r.URL) panic(err) } }() From bce4a853b02741e9779245b085cde2048fdce4e7 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:00:24 -0700 Subject: [PATCH 08/19] Update functions to require `context.Context` --- honeybadger.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/honeybadger.go b/honeybadger.go index 0797d87..013f7a0 100644 --- a/honeybadger.go +++ b/honeybadger.go @@ -55,8 +55,8 @@ func Configure(c Configuration) { } // SetContext merges c Context into the Context of the global client. -func SetContext(c Context) { - DefaultClient.SetContext(c) +func SetContext(ctx context.Context, c Context) context.Context { + return DefaultClient.SetContext(ctx, c) } // Notify reports the error err to the Honeybadger service. @@ -66,8 +66,8 @@ func SetContext(c Context) { // // It returns a string UUID which can be used to reference the error from the // Honeybadger service, and an error as a second argument. -func Notify(err interface{}, extra ...interface{}) (string, error) { - return DefaultClient.Notify(newError(err, 2), extra...) +func Notify(ctx context.Context, err interface{}, extra ...interface{}) (string, error) { + return DefaultClient.Notify(ctx, newError(err, 2), extra...) } // Monitor is used to automatically notify Honeybadger service of panics which From e0ad81e97267a2500b6a598058b2f52b37cc646e Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:00:44 -0700 Subject: [PATCH 09/19] Use `context.Background` in `Monitor()` --- honeybadger.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/honeybadger.go b/honeybadger.go index 013f7a0..5a4f34a 100644 --- a/honeybadger.go +++ b/honeybadger.go @@ -79,9 +79,32 @@ func Notify(ctx context.Context, err interface{}, extra ...interface{}) (string, // } // The Monitor function re-panics after the notification has been sent, so it's // still up to the user to recover from panics if desired. +// +// The Monitor function doesn't have access to any set context from `SetContext` +// calls. func Monitor() { if err := recover(); err != nil { - DefaultClient.Notify(newError(err, 2)) + ctx := context.Background() + DefaultClient.Notify(ctx, newError(err, 2)) + DefaultClient.Flush() + panic(err) + } +} + +// MonitorCtx is used to automatically notify Honeybadger service of panics which +// happen inside the current function. In order to monitor for panics, defer a +// call to MonitorCtx. For example: +// func handler(ctx context.Context) { +// defer honeybadger.MonitorCtx(ctx) +// // Do risky stuff... +// } +// The MonitorCtx function re-panics after the notification has been sent, so it's +// still up to the user to recover from panics if desired. +// +// Has access to any context set when using `SetCtx` +func MonitorCtx(ctx context.Context) { + if err := recover(); err != nil { + DefaultClient.Notify(ctx, newError(err, 2)) DefaultClient.Flush() panic(err) } From d22f292c7752a071092ef739ad162047f4ba979a Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:29:25 -0700 Subject: [PATCH 10/19] Update godoc comment --- honeybadger.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/honeybadger.go b/honeybadger.go index 5a4f34a..7bab038 100644 --- a/honeybadger.go +++ b/honeybadger.go @@ -118,6 +118,8 @@ func Flush() { // Handler returns an http.Handler function which automatically reports panics // to Honeybadger and then re-panics. +// +// The request context is what's passed to notify. func Handler(h http.Handler) http.Handler { return DefaultClient.Handler(h) } From e178ad8b14ee0ad998d3eb63f1fa2fc789b9bfa6 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:29:34 -0700 Subject: [PATCH 11/19] Add import --- honeybadger.go | 1 + 1 file changed, 1 insertion(+) diff --git a/honeybadger.go b/honeybadger.go index 7bab038..59a3403 100644 --- a/honeybadger.go +++ b/honeybadger.go @@ -1,6 +1,7 @@ package honeybadger import ( + "context" "encoding/json" "net/http" "net/url" From 7893ff7bae2187ee57db73a9db6f9ef2f8c78747 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:29:47 -0700 Subject: [PATCH 12/19] Update tests so they pass --- client_test.go | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/client_test.go b/client_test.go index 9f07250..c785577 100644 --- a/client_test.go +++ b/client_test.go @@ -1,8 +1,10 @@ package honeybadger import ( + "context" "testing" - "sync" + + "github.com/davecgh/go-spew/spew" ) func TestNewConfig(t *testing.T) { @@ -32,41 +34,27 @@ func TestConfigureClientEndpoint(t *testing.T) { func TestClientContext(t *testing.T) { client := New(Configuration{}) - client.SetContext(Context{"foo": "bar"}) - client.SetContext(Context{"bar": "baz"}) + ctx := context.Background() - context := client.context.internal + ctx = client.SetContext(ctx, Context{"foo": "bar"}) + ctx = client.SetContext(ctx, Context{"bar": "baz"}) - if context["foo"] != "bar" { - t.Errorf("Expected client to merge global context. expected=%#v actual=%#v", "bar", context["foo"]) + var context Context + if tmp, ok := ctx.Value(honeybadgerCtxKey).(*contextSync); ok { + context = tmp.internal } - if context["bar"] != "baz" { - t.Errorf("Expected client to merge global context. expected=%#v actual=%#v", "baz", context["bar"]) + if context == nil { + spew.Dump(ctx) + t.Errorf("context value not placed in context.Context") + t.FailNow() } -} - -func TestClientConcurrentContext(t *testing.T) { - var wg sync.WaitGroup - - client := New(Configuration{}) - newContext := Context{"foo":"bar"} - - wg.Add(2) - - go updateContext(&wg, client, newContext) - go updateContext(&wg, client, newContext) - - wg.Wait() - - context := client.context.internal if context["foo"] != "bar" { - t.Errorf("Expected context value. expected=%#v result=%#v", "bar", context["foo"]) + t.Errorf("Expected client to merge global context. expected=%#v actual=%#v", "bar", context["foo"]) } -} -func updateContext(wg *sync.WaitGroup, client *Client, context Context) { - client.SetContext(context) - wg.Done() + if context["bar"] != "baz" { + t.Errorf("Expected client to merge global context. expected=%#v actual=%#v", "baz", context["bar"]) + } } From 76e8aa8d0e8129f51f38babef22406dad5927a27 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:29:54 -0700 Subject: [PATCH 13/19] Version bump -- v0.5.0 --- honeybadger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/honeybadger.go b/honeybadger.go index 59a3403..cc0c74c 100644 --- a/honeybadger.go +++ b/honeybadger.go @@ -8,7 +8,7 @@ import ( ) // VERSION defines the version of the honeybadger package. -const VERSION = "0.4.0" +const VERSION = "0.5.0" var ( // client is a pre-defined "global" client. From 93032638b7777c04bf94b80b592d6caf74c68cd2 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:31:49 -0700 Subject: [PATCH 14/19] Update tests --- honeybadger_test.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/honeybadger_test.go b/honeybadger_test.go index 2388c1b..71c1c69 100644 --- a/honeybadger_test.go +++ b/honeybadger_test.go @@ -1,6 +1,7 @@ package honeybadger import ( + "context" "encoding/json" "errors" "fmt" @@ -85,7 +86,9 @@ func TestNotify(t *testing.T) { setup(t) defer teardown() - res, _ := Notify(errors.New("Cobras!")) + ctx := context.Background() + + res, _ := Notify(ctx, errors.New("Cobras!")) if uuid.Parse(res) == nil { t.Errorf("Expected Notify() to return a UUID. actual=%#v", res) @@ -104,8 +107,9 @@ func TestNotifyWithContext(t *testing.T) { setup(t) defer teardown() + ctx := context.Background() context := Context{"foo": "bar"} - Notify("Cobras!", context) + Notify(ctx, "Cobras!", context) Flush() if !testRequestCount(t, 1) { @@ -124,7 +128,8 @@ func TestNotifyWithErrorClass(t *testing.T) { setup(t) defer teardown() - Notify("Cobras!", ErrorClass{"Badgers"}) + ctx := context.Background() + Notify(ctx, "Cobras!", ErrorClass{"Badgers"}) Flush() if !testRequestCount(t, 1) { @@ -149,7 +154,8 @@ func TestNotifyWithTags(t *testing.T) { setup(t) defer teardown() - Notify("Cobras!", Tags{"timeout", "http"}) + ctx := context.Background() + Notify(ctx, "Cobras!", Tags{"timeout", "http"}) Flush() if !testRequestCount(t, 1) { @@ -174,7 +180,8 @@ func TestNotifyWithFingerprint(t *testing.T) { setup(t) defer teardown() - Notify("Cobras!", Fingerprint{"Badgers"}) + ctx := context.Background() + Notify(ctx, "Cobras!", Fingerprint{"Badgers"}) Flush() if !testRequestCount(t, 1) { @@ -222,7 +229,8 @@ func TestNotifyWithHandler(t *testing.T) { n.Fingerprint = "foo bar baz" return nil }) - Notify(errors.New("Cobras!")) + ctx := context.Background() + Notify(ctx, errors.New("Cobras!")) Flush() payload := requests[0].decodeJSON() @@ -248,7 +256,8 @@ func TestNotifyWithHandlerError(t *testing.T) { BeforeNotify(func(n *Notice) error { return err }) - _, notifyErr := Notify(errors.New("Cobras!")) + ctx := context.Background() + _, notifyErr := Notify(ctx, errors.New("Cobras!")) Flush() if !testRequestCount(t, 0) { From 5dd20b6d43a81d349f733ba63700bd48326d7a7a Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 25 Oct 2018 13:39:47 -0700 Subject: [PATCH 15/19] Remove `spew.Dump` from tests --- client_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/client_test.go b/client_test.go index c785577..6567d71 100644 --- a/client_test.go +++ b/client_test.go @@ -3,8 +3,6 @@ package honeybadger import ( "context" "testing" - - "github.com/davecgh/go-spew/spew" ) func TestNewConfig(t *testing.T) { @@ -45,7 +43,6 @@ func TestClientContext(t *testing.T) { } if context == nil { - spew.Dump(ctx) t.Errorf("context value not placed in context.Context") t.FailNow() } From cba695c59c5f66fe38505a5aa383b4017fba687a Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Wed, 31 Oct 2018 18:51:46 -0700 Subject: [PATCH 16/19] Update readme to reflect changes --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f44730d..b47b010 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ To report an error manually, use `honeybadger.Notify`: ```go if err != nil { - honeybadger.Notify(err) + honeybadger.Notify(ctx, err) } ``` @@ -113,7 +113,7 @@ The following options are available to you: ## Public Interface -### `honeybadger.Notify()`: Send an error to Honeybadger. +### `honeybadger.Notify(context,Context, interface{}, ...interface{})`: Send an error to Honeybadger. If you've handled a panic in your code, but would still like to report the error to Honeybadger, this is the method for you. @@ -121,7 +121,7 @@ If you've handled a panic in your code, but would still like to report the error ```go if err != nil { - honeybadger.Notify(err) + honeybadger.Notify(ctx, err) } ``` @@ -129,7 +129,7 @@ You can also add local context using an optional second argument when calling `honeybadger.Notify`: ```go -honeybadger.Notify(err, honeybadger.Context{"user_id": 2}) +honeybadger.Notify(ctx, err, honeybadger.Context{"user_id": 2}) ``` Honeybadger uses the error's class name to group similar errors together. If @@ -137,26 +137,26 @@ your error classes are often generic (such as `errors.errorString`), you can improve grouping by overriding the default with something more unique: ```go -honeybadger.Notify(err, honeybadger.ErrorClass{"CustomClassName"}) +honeybadger.Notify(ctx, err, honeybadger.ErrorClass{"CustomClassName"}) ``` To override grouping entirely, you can send a custom fingerprint. All errors with the same fingerprint will be grouped together: ```go -honeybadger.Notify(err, honeybadger.Fingerprint{"A unique string"}) +honeybadger.Notify(ctx, err, honeybadger.Fingerprint{"A unique string"}) ``` To tag errors in Honeybadger: ```go -honeybadger.Notify(err, honeybadger.Tags{"timeout", "http"}) +honeybadger.Notify(ctx, err, honeybadger.Tags{"timeout", "http"}) ``` --- -### `honeybadger.SetContext()`: Set metadata to be sent if an error occurs +### `honeybadger.SetContext(context.Context, map[string]interface{})`: Set metadata to be sent if an error occurs This method lets you set context data that will be sent if an error should occur. @@ -167,7 +167,7 @@ For example, it's often useful to record the current user's ID when an error occ #### Examples: ```go -honeybadger.SetContext(honeybadger.Context{ +honeybadger.SetContext(ctx, honeybadger.Context{ "user_id": 1, }) ``` From da918035d9f6b8052f5879e56b569c392efa2388 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 1 Nov 2018 15:57:23 -0700 Subject: [PATCH 17/19] Add information to honeybadger context before calling handler Because contexts are not modifiable in-place (eg, calling `context.WithValue` returns a new context, it doesn't return the same context you've passed in with the value set), need to set some data in the Honeybadger HTTP middleware. Unfortunately, any additional info set with `SetContext` within the handler is lost if the handler panics. --- client.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 77ce1e6..950ea27 100644 --- a/client.go +++ b/client.go @@ -117,13 +117,27 @@ func (client *Client) Handler(h http.Handler) http.Handler { h = http.DefaultServeMux } fn := func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + ctx = SetContext(ctx, map[string]interface{}{ + "path": r.URL.String(), + "host": r.Host, + "header": r.Header, + "user-agent": r.UserAgent(), + "content-length": r.ContentLength, + "method": r.Method, + "proto": r.Proto, + "remote-address": r.RemoteAddr, + "request-uri": r.RequestURI, + }) + req := r.WithContext(ctx) + defer func() { if err := recover(); err != nil { - client.Notify(r.Context(), newError(err, 2), Params(r.Form), getCGIData(r), *r.URL) + client.Notify(req.Context(), newError(err, 2), Params(r.Form), getCGIData(r), *r.URL) panic(err) } }() - h.ServeHTTP(w, r) + h.ServeHTTP(w, req) } return http.HandlerFunc(fn) } From 3fc78e0574b6883e8c59e9318826f29d372c415d Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Thu, 1 Nov 2018 16:13:36 -0700 Subject: [PATCH 18/19] Fix `SetContext` call --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 950ea27..a3f7bfc 100644 --- a/client.go +++ b/client.go @@ -118,7 +118,7 @@ func (client *Client) Handler(h http.Handler) http.Handler { } fn := func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - ctx = SetContext(ctx, map[string]interface{}{ + ctx = client.SetContext(ctx, map[string]interface{}{ "path": r.URL.String(), "host": r.Host, "header": r.Header, From ff8bb5616b5ea4a8c35135c51b740b7cd5efb333 Mon Sep 17 00:00:00 2001 From: Sean Patrick Hagen Date: Fri, 4 Jan 2019 14:57:26 -0800 Subject: [PATCH 19/19] Go modules, use gofrs uuid library instead --- go.mod | 7 +++++++ go.sum | 6 ++++++ notice.go | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f1ec191 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/seanhagen/honeybadger-go + +require ( + github.com/gofrs/uuid/v3 v3.1.2 + github.com/shirou/gopsutil v2.18.12+incompatible + golang.org/x/sys v0.0.0-20190102155601-82a175fd1598 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..84eb89f --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/gofrs/uuid/v3 v3.1.2 h1:V3IBv1oU82x6YIr5txe3azVHgmOKYdyKQTowm9moBlY= +github.com/gofrs/uuid/v3 v3.1.2/go.mod h1:xPwMqoocQ1L5G6pXX5BcE7N5jlzn2o19oqAKxwZW/kI= +github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM= +github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +golang.org/x/sys v0.0.0-20190102155601-82a175fd1598 h1:S8GOgffXV1X3fpVG442QRfWOt0iFl79eHJ7OPt725bo= +golang.org/x/sys v0.0.0-20190102155601-82a175fd1598/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/notice.go b/notice.go index b780b58..186f3fe 100644 --- a/notice.go +++ b/notice.go @@ -7,7 +7,7 @@ import ( "regexp" "time" - "github.com/pborman/uuid" + "github.com/gofrs/uuid/v3" "github.com/shirou/gopsutil/load" "github.com/shirou/gopsutil/mem" ) @@ -143,10 +143,12 @@ func composeStack(stack []*Frame, root string) (frames []*Frame) { } func newNotice(config *Configuration, err Error, extra ...interface{}) *Notice { + tkn, _ := uuid.NewV4() + notice := Notice{ APIKey: config.APIKey, Error: err, - Token: uuid.NewRandom().String(), + Token: tkn.String(), ErrorMessage: err.Message, ErrorClass: err.Class, Env: config.Env,