Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Pass request context to frame observer
Browse files Browse the repository at this point in the history
This allows the frame observer to access the context passed to
gocql.
  • Loading branch information
martin-sucha committed Oct 30, 2023
1 parent fb119cd commit ab841b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,9 @@ func (c *Conn) exec(ctx context.Context, req frameBuilder, tracer Tracer) (*fram
if v := resp.framer.header.version.version(); v != c.version {
return nil, NewErrProtocol("unexpected protocol version in response: got %d expected %d", v, c.version)
}
if resp.framer != nil {
resp.framer.observer.reqCtx = ctx
}

return resp.framer, nil
case <-timeoutCh:
Expand Down
7 changes: 6 additions & 1 deletion frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ type framer struct {
type frameParseObserver struct {
head ObservedFrameHeader
frameObserver FrameObserver
reqCtx context.Context
}

func (fpo *frameParseObserver) observeFrame(ff *framer, f frame) {
Expand All @@ -425,7 +426,11 @@ func (fpo *frameParseObserver) observeFrame(ff *framer, f frame) {
of.RowCount = rows.numRows
of.RowsSize = rows.rowsContentSize
}
fpo.frameObserver.ObserveFrame(context.TODO(), of)
ctx := fpo.reqCtx
if ctx == nil {
ctx = context.TODO()
}
fpo.frameObserver.ObserveFrame(ctx, of)
}

func newFramer(compressor Compressor, version byte) *framer {
Expand Down

0 comments on commit ab841b4

Please sign in to comment.