Open zalgonoise opened 3 months ago
@microsoft-github-policy-service agree
currently in Draft to fix the data races raised when reading the (pointer) elements of *frames.PerformFlow
(and possibly other frames), when their String
method is called when parsing a slog.Attr
for any type, or when calling the frames' String
method directly when available.
I will address it, then release the PR from draft once again :D
addressed the issue with the race condition on *frames.PerformFlow
; documented in the PRs description
Hi folks :D
This PR adds support for configurable logging in
go-amqp
usinglog/slog
.The logger is kept in a global state, within the
internal/debug
package, as before. However, it is initialized with a no-op implementation of aslog.Handler
. Doing so, allows sane defaults (disabled logging) while allowing the caller to still register their ownslog.Handler
if they desire.This is done via a
RegisterLogger
ininternal/debug
which is then made public in a top-leveldebug.go
file. We're able to discuss the approach to this change, if you'd maybe prefer to ditchinternal/debug
all together, moving that logic into top-leveldebug.go
.The signature of
Log
is changed to allow consuming contexts, defining level withslog.Level
values, just likeAssert
which should work like before, but the caller is also able to pass arguments (likeslog.Attr
), and makingAssertf
no longer necessary. Minimal tests added for both of these functions.The new log levels respect the verbosity as defined before, but we can also discuss any changes you'd like to see in that regard.
As for a client or consumer of this library, they are able to enable and disable logging by registering a
slog.Handler
usingamqp.RegisterLogger
. This is in line of strategies seen in libraries likeopentelemetry-go
. Provided that the global-state objects are initialized with sane defaults, I don't perceive any particular issue with this approach, but curious on your input on this.Calling
amqp.RegisterLogger
could happen from themain.go
file for the client application that usesgo-amqp
, if the app sends and / or receives messages using this library; or by a client library that wrapsgo-amqp
A race condition on
*frames.PerformFlow
was found after publishing this PR, since this frame is overwritten in a*Session.mux
call. With this implementation, passing frames asslog.Attr
attributes, it causes it to be read and written to at the same time in certain occasions. This may not have been noticeable before due to the (complete) no-op implementation of the debug logging function.Added a (private)
*sync.Mutex
to*frames.PerformFlow
, alongside aframes.NewPerformFlow
constructor and*frames.PerformFlow.Lock
and*frames.PerformFlow.Unlock
methodsCloses #138