forked from quic-go/quic-go
pass a context to logging.Tracer.NewConnectionTracer
This context has the same value attached to it as the context returned by Session.Context(). In the case of a dialed connection, this context is derived from the context used for dialing.
This commit is contained in:
@@ -2,6 +2,7 @@ package qlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -59,7 +60,7 @@ func NewTracer(getLogWriter func(p logging.Perspective, connectionID []byte) io.
|
||||
return &tracer{getLogWriter: getLogWriter}
|
||||
}
|
||||
|
||||
func (t *tracer) TracerForConnection(p logging.Perspective, odcid protocol.ConnectionID) logging.ConnectionTracer {
|
||||
func (t *tracer) TracerForConnection(_ context.Context, p logging.Perspective, odcid protocol.ConnectionID) logging.ConnectionTracer {
|
||||
if w := t.getLogWriter(p, odcid.Bytes()); w != nil {
|
||||
return NewConnectionTracer(w, p, odcid)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package qlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
@@ -52,7 +53,7 @@ var _ = Describe("Tracing", func() {
|
||||
Context("tracer", func() {
|
||||
It("returns nil when there's no io.WriteCloser", func() {
|
||||
t := NewTracer(func(logging.Perspective, []byte) io.WriteCloser { return nil })
|
||||
Expect(t.TracerForConnection(logging.PerspectiveClient, logging.ConnectionID{1, 2, 3, 4})).To(BeNil())
|
||||
Expect(t.TracerForConnection(context.Background(), logging.PerspectiveClient, logging.ConnectionID{1, 2, 3, 4})).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -83,7 +84,7 @@ var _ = Describe("Tracing", func() {
|
||||
BeforeEach(func() {
|
||||
buf = &bytes.Buffer{}
|
||||
t := NewTracer(func(logging.Perspective, []byte) io.WriteCloser { return nopWriteCloser(buf) })
|
||||
tracer = t.TracerForConnection(logging.PerspectiveServer, logging.ConnectionID{0xde, 0xad, 0xbe, 0xef})
|
||||
tracer = t.TracerForConnection(context.Background(), logging.PerspectiveServer, logging.ConnectionID{0xde, 0xad, 0xbe, 0xef})
|
||||
})
|
||||
|
||||
It("exports a trace that has the right metadata", func() {
|
||||
|
||||
Reference in New Issue
Block a user