sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

NewClient mutates global Logger

Open rhcarvalho opened this issue 6 years ago • 4 comments

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 NewClient mutates a global logger and that's a problem in itself, the whole SDK depends on the global Logger, including Hub, Scope, Client, Transport implementations and integrations. We need to rethink logging with all of those in mind ⇒ #182.

rhcarvalho avatar Jan 27 '20 19:01 rhcarvalho

Checking in if this needs more discussion or ready to get into the implementation state?

YashishDua avatar Feb 09 '20 08:02 YashishDua

@YashishDua I think the goal here is clear. Thanks for chiming in!

rhcarvalho avatar Feb 10 '20 15:02 rhcarvalho

Perfect! Picking this up then.

YashishDua avatar Feb 12 '20 17:02 YashishDua

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 🥀

github-actions[bot] avatar Dec 07 '22 09:12 github-actions[bot]