NewClient mutates global Logger
All Clients (and the rest of the SDK) share a single global Logger:
https://github.com/getsentry/sentry-go/blob/763dc7f49323f467d4c62ec15804723ec5350b37/client.go#L20
That means that calling NewClient mutates global state in surprising ways:
https://github.com/getsentry/sentry-go/blob/763dc7f49323f467d4c62ec15804723ec5350b37/client.go#L105-L113
If a program has multiple clients, setting the Debug option affects all other clients:
go func() {
c1, err := NewClient(ClientOptions{
Debug: true,
})
if err != nil {
log.Fatal(err)
}
c1.CaptureMessage("message from c1")
}()
go func() {
c2, err := NewClient(ClientOptions{
Debug: false,
})
if err != nil {
log.Fatal(err)
}
c2.CaptureMessage("message from c2")
}()
The state of Debug logging for c2 is undefined, might be on, might be off. No way to turn it off unless messing with the global Logger value.
Updates:
- 2020-03-14:
- Changed title to remove suggestion of a specific solution.
- While
NewClientmutates a global logger and that's a problem in itself, the whole SDK depends on the globalLogger, includingHub,Scope,Client,Transportimplementations and integrations. We need to rethink logging with all of those in mind ⇒ #182.
Checking in if this needs more discussion or ready to get into the implementation state?
@YashishDua I think the goal here is clear. Thanks for chiming in!
Perfect! Picking this up then.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀