Repository: quic-go/quic-go
Pull request #4297 (2024-02-01 23:11:17)

logging: add a Debug function to the Tracer

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) Report
Attention: `5 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`0582e93`)](https://app.codecov.io/gh/quic-go/quic-go/commit/0582e931a554020c5091350fdc9e2988bf9c5ab8?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) 84.17% compared to head [(`ddbf145`)](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) 84.16%.
> Report is 1 commits behind head on master.

> :exclamation: Current head ddbf145 differs from pull request most recent head e5563ca. Consider uploading reports for the commit e5563ca to get more accurate results

| [Files](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) | Patch % | Lines |
|---|---|---|
| [logging/tracer.go](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go#diff-bG9nZ2luZy90cmFjZXIuZ28=) | 0.00% | [5 Missing :warning: ](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4297      +/-   ##
==========================================
- Coverage   84.17%   84.16%   -0.01%     
==========================================
  Files         149      146       -3     
  Lines       15397    15352      -45     
==========================================
- Hits        12959    12920      -39     
+ Misses       1939     1936       -3     
+ Partials      499      496       -3     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/quic-go/quic-go/pull/4297?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).


Patch:
diff --git a/internal/mocks/logging/internal/tracer.go b/internal/mocks/logging/internal/tracer.go
index e11764c2..88c3b645 100644
--- a/internal/mocks/logging/internal/tracer.go
+++ b/internal/mocks/logging/internal/tracer.go
@@ -41,6 +41,42 @@ func (m *MockTracer) EXPECT() *MockTracerMockRecorder {
 	return m.recorder
 }
 
+// Debug mocks base method.
+func (m *MockTracer) Debug(arg0, arg1 string) {
+	m.ctrl.T.Helper()
+	m.ctrl.Call(m, "Debug", arg0, arg1)
+}
+
+// Debug indicates an expected call of Debug.
+func (mr *MockTracerMockRecorder) Debug(arg0, arg1 any) *TracerDebugCall {
+	mr.mock.ctrl.T.Helper()
+	call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockTracer)(nil).Debug), arg0, arg1)
+	return &TracerDebugCall{Call: call}
+}
+
+// TracerDebugCall wrap *gomock.Call
+type TracerDebugCall struct {
+	*gomock.Call
+}
+
+// Return rewrite *gomock.Call.Return
+func (c *TracerDebugCall) Return() *TracerDebugCall {
+	c.Call = c.Call.Return()
+	return c
+}
+
+// Do rewrite *gomock.Call.Do
+func (c *TracerDebugCall) Do(f func(string, string)) *TracerDebugCall {
+	c.Call = c.Call.Do(f)
+	return c
+}
+
+// DoAndReturn rewrite *gomock.Call.DoAndReturn
+func (c *TracerDebugCall) DoAndReturn(f func(string, string)) *TracerDebugCall {
+	c.Call = c.Call.DoAndReturn(f)
+	return c
+}
+
 // DroppedPacket mocks base method.
 func (m *MockTracer) DroppedPacket(arg0 net.Addr, arg1 logging.PacketType, arg2 protocol.ByteCount, arg3 logging.PacketDropReason) {
 	m.ctrl.T.Helper()
diff --git a/internal/mocks/logging/mockgen.go b/internal/mocks/logging/mockgen.go
index a86be9b1..fb58e117 100644
--- a/internal/mocks/logging/mockgen.go
+++ b/internal/mocks/logging/mockgen.go
@@ -14,6 +14,7 @@ type Tracer interface {
 	SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame)
 	SentVersionNegotiationPacket(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, _ []logging.VersionNumber)
 	DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason)
+	Debug(name, msg string)
 }
 
 //go:generate sh -c "go run go.uber.org/mock/mockgen -typed -build_flags=\"-tags=gomock\" -package internal -destination internal/connection_tracer.go github.com/quic-go/quic-go/internal/mocks/logging ConnectionTracer"
diff --git a/internal/mocks/logging/tracer.go b/internal/mocks/logging/tracer.go
index 115f578a..66e210a5 100644
--- a/internal/mocks/logging/tracer.go
+++ b/internal/mocks/logging/tracer.go
@@ -25,5 +25,8 @@ func NewMockTracer(ctrl *gomock.Controller) (*logging.Tracer, *MockTracer) {
 		DroppedPacket: func(remote net.Addr, typ logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) {
 			t.DroppedPacket(remote, typ, size, reason)
 		},
+		Debug: func(name, msg string) {
+			t.Debug(name, msg)
+		},
 	}, t
 }
diff --git a/logging/tracer.go b/logging/tracer.go
index 5918f30f..735ec3de 100644
--- a/logging/tracer.go
+++ b/logging/tracer.go
@@ -7,6 +7,7 @@ type Tracer struct {
 	SentPacket                   func(net.Addr, *Header, ByteCount, []Frame)
 	SentVersionNegotiationPacket func(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber)
 	DroppedPacket                func(net.Addr, PacketType, ByteCount, PacketDropReason)
+	Debug                        func(name, msg string)
 }
 
 // NewMultiplexedTracer creates a new tracer that multiplexes events to multiple tracers.
@@ -39,5 +40,12 @@ func NewMultiplexedTracer(tracers ...*Tracer) *Tracer {
 				}
 			}
 		},
+		Debug: func(name, msg string) {
+			for _, t := range tracers {
+				if t.Debug != nil {
+					t.Debug(name, msg)
+				}
+			}
+		},
 	}
 }


Test patch:
diff --git a/logging/multiplex_test.go b/logging/multiplex_test.go
index 94604096..96cd1185 100644
--- a/logging/multiplex_test.go
+++ b/logging/multiplex_test.go
@@ -64,6 +64,12 @@ var _ = Describe("Tracing", func() {
 				tr2.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate)
 				tracer.DroppedPacket(remote, PacketTypeRetry, 1024, PacketDropDuplicate)
 			})
+
+			It("traces the Debug event", func() {
+				tr1.EXPECT().Debug("foo", "bar")
+				tr2.EXPECT().Debug("foo", "bar")
+				tracer.Debug("foo", "bar")
+			})
 		})
 	})