Skip to content

Commit

Permalink
fix: add trace for StreamStatus (#2081)
Browse files Browse the repository at this point in the history
This adds a trace for the code that runs when a client requests the
StreamStatus.

Ref: SRX-8PS60H
  • Loading branch information
sven-urbanski-freiheit-com authored Nov 5, 2024
1 parent 05283cb commit 73f2cfd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions services/rollout-service/pkg/service/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package service
import (
"context"
"errors"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"sync"
"time"

Expand Down Expand Up @@ -176,15 +177,21 @@ func (b *Broadcast) DisconnectAll() {
b.listener = make(map[chan *BroadcastEvent]struct{})
}

func (b *Broadcast) StreamStatus(req *api.StreamStatusRequest, svc api.RolloutService_StreamStatusServer) error {
func (b *Broadcast) StreamStatus(_ *api.StreamStatusRequest, svc api.RolloutService_StreamStatusServer) error {
ctx := svc.Context()
span, ctx := tracer.StartSpanFromContext(ctx, "StreamStatusConnect")
defer span.Finish()
resp, ch, unsubscribe := b.Start()
defer unsubscribe()
span.SetTag("numberOfEvents", len(resp))
for _, r := range resp {
err := svc.Send(streamStatus(r))
if err != nil {
return err
}
}
span.Finish()

for {
select {
case r := <-ch:
Expand All @@ -196,8 +203,8 @@ func (b *Broadcast) StreamStatus(req *api.StreamStatusRequest, svc api.RolloutSe
if err != nil {
return err
}
case <-svc.Context().Done():
err := svc.Context().Err()
case <-ctx.Done():
err := ctx.Err()
if errors.Is(err, context.Canceled) {
return nil
}
Expand Down

0 comments on commit 73f2cfd

Please sign in to comment.