Skip to content

Commit

Permalink
dash: propagate app id for new trace events
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Dec 7, 2023
1 parent c15735c commit 6c38020
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions cli/daemon/dash/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,18 @@ func (s *Server) listenTraces() {
continue
}

data, err := protoEncoder.Marshal(sp)
data, err := protoEncoder.Marshal(sp.Span)
if err != nil {
log.Error().Err(err).Msg("dash: could not marshal trace")
continue
}

s.notify(&notification{
Method: "trace/new",
Params: json.RawMessage(data),
Params: map[string]any{
"app_id": sp.AppID,
"span": json.RawMessage(data),
},
})
}
}
Expand Down
5 changes: 2 additions & 3 deletions cli/daemon/dash/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encr.dev/cli/internal/jsonrpc2"
"encr.dev/internal/conf"
"encr.dev/pkg/fns"
tracepb2 "encr.dev/proto/encore/engine/trace2"
)

var upgrader = websocket.Upgrader{
Expand All @@ -45,7 +44,7 @@ func NewServer(appsMgr *apps.Manager, runMgr *run.Manager, tr trace2.Store, dash
run: runMgr,
tr: tr,
dashPort: dashPort,
traceCh: make(chan *tracepb2.SpanSummary, 10),
traceCh: make(chan trace2.NewSpanEvent, 10),
clients: make(map[chan<- *notification]struct{}),
}

Expand All @@ -63,7 +62,7 @@ type Server struct {
run *run.Manager
tr trace2.Store
dashPort int
traceCh chan *tracepb2.SpanSummary
traceCh chan trace2.NewSpanEvent

mu sync.Mutex
clients map[chan<- *notification]struct{}
Expand Down
5 changes: 4 additions & 1 deletion cli/daemon/engine/trace2/sqlite/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ func (s *Store) emitCompleteSpanToListeners(ctx context.Context, appID, traceID,
ts := time.Unix(0, startedAt)
t.StartedAt = timestamppb.New(ts)
for _, ln := range s.listeners {
ln <- &t
ln <- trace2.NewSpanEvent{
AppID: appID,
Span: &t,
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions cli/daemon/engine/trace2/sqlite/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func New(db *sql.DB) *Store {

type Store struct {
db *sql.DB
listeners []chan<- *tracepbcli.SpanSummary
listeners []chan<- trace2.NewSpanEvent
}

var _ trace2.Store = (*Store)(nil)

func (s *Store) Listen(ch chan<- *tracepbcli.SpanSummary) {
func (s *Store) Listen(ch chan<- trace2.NewSpanEvent) {
s.listeners = append(s.listeners, ch)
}

Expand Down
7 changes: 6 additions & 1 deletion cli/daemon/engine/trace2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@ type Store interface {
Get(ctx context.Context, appID, traceID string, iter EventIterator) error

// Listen listens for new spans.
Listen(ch chan<- *tracepb2.SpanSummary)
Listen(ch chan<- NewSpanEvent)
}

type NewSpanEvent struct {
AppID string
Span *tracepb2.SpanSummary
}

0 comments on commit 6c38020

Please sign in to comment.