@@ -16,9 +16,11 @@ import (
1616 "time"
1717
1818 "github.com/sirupsen/logrus"
19+ "go.opencensus.io/trace"
1920 "golang.org/x/sys/windows"
2021
2122 "github.com/Microsoft/hcsshim/internal/log"
23+ "github.com/Microsoft/hcsshim/internal/oc"
2224)
2325
2426const (
@@ -258,6 +260,9 @@ func (brdg *bridge) recvLoopRoutine() {
258260}
259261
260262func readMessage (r io.Reader ) (int64 , msgType , []byte , error ) {
263+ _ , span := oc .StartSpan (context .Background (), "bridge receive read message" , oc .WithClientSpanKind )
264+ defer span .End ()
265+
261266 var h [hdrSize ]byte
262267 _ , err := io .ReadFull (r , h [:])
263268 if err != nil {
@@ -266,6 +271,10 @@ func readMessage(r io.Reader) (int64, msgType, []byte, error) {
266271 typ := msgType (binary .LittleEndian .Uint32 (h [hdrOffType :]))
267272 n := binary .LittleEndian .Uint32 (h [hdrOffSize :])
268273 id := int64 (binary .LittleEndian .Uint64 (h [hdrOffID :]))
274+ span .AddAttributes (
275+ trace .StringAttribute ("type" , typ .String ()),
276+ trace .Int64Attribute ("message-id" , id ))
277+
269278 if n < hdrSize || n > maxMsgSize {
270279 return 0 , 0 , nil , fmt .Errorf ("invalid message size %d" , n )
271280 }
@@ -298,7 +307,8 @@ func (brdg *bridge) recvLoop() error {
298307 brdg .log .WithFields (logrus.Fields {
299308 "payload" : string (b ),
300309 "type" : typ .String (),
301- "message-id" : id }).Debug ("bridge receive" )
310+ "message-id" : id }).Trace ("bridge receive" )
311+
302312 switch typ & msgTypeMask {
303313 case msgTypeResponse :
304314 // Find the request associated with this response.
@@ -372,19 +382,27 @@ func (brdg *bridge) sendLoop() {
372382}
373383
374384func (brdg * bridge ) writeMessage (buf * bytes.Buffer , enc * json.Encoder , typ msgType , id int64 , req interface {}) error {
385+ var err error
386+ _ , span := oc .StartSpan (context .Background (), "bridge send" , oc .WithClientSpanKind )
387+ defer span .End ()
388+ defer func () { oc .SetSpanStatus (span , err ) }()
389+ span .AddAttributes (
390+ trace .StringAttribute ("type" , typ .String ()),
391+ trace .Int64Attribute ("message-id" , id ))
392+
375393 // Prepare the buffer with the message.
376394 var h [hdrSize ]byte
377395 binary .LittleEndian .PutUint32 (h [hdrOffType :], uint32 (typ ))
378396 binary .LittleEndian .PutUint64 (h [hdrOffID :], uint64 (id ))
379397 buf .Write (h [:])
380- err : = enc .Encode (req )
398+ err = enc .Encode (req )
381399 if err != nil {
382400 return fmt .Errorf ("bridge encode: %w" , err )
383401 }
384402 // Update the message header with the size.
385403 binary .LittleEndian .PutUint32 (buf .Bytes ()[hdrOffSize :], uint32 (buf .Len ()))
386404
387- if brdg .log .Logger .GetLevel () >= logrus .DebugLevel {
405+ if brdg .log .Logger .GetLevel () > logrus .DebugLevel {
388406 b := buf .Bytes ()[hdrSize :]
389407 switch typ {
390408 // container environment vars are in rpCreate for linux; rpcExecuteProcess for windows
@@ -399,7 +417,7 @@ func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgTy
399417 brdg .log .WithFields (logrus.Fields {
400418 "payload" : string (b ),
401419 "type" : typ .String (),
402- "message-id" : id }).Debug ("bridge send" )
420+ "message-id" : id }).Trace ("bridge send" )
403421 }
404422
405423 // Write the message.
0 commit comments