MCPcopy Create free account
hub / github.com/dagger/dagger / LogsSubscribeHandler

Method LogsSubscribeHandler

engine/server/telemetry.go:237–270  ·  view source on GitHub ↗

nolint:dupl

(w http.ResponseWriter, r *http.Request, client *daggerClient)

Source from the content-addressed store, hash-verified

235
236//nolint:dupl
237func (ps *PubSub) LogsSubscribeHandler(w http.ResponseWriter, r *http.Request, client *daggerClient) error {
238 return ps.sseHandler(w, r, client, func(ctx context.Context, db *clientdb.DB, lastID string) (*sse.Event, bool, error) {
239 var since int64
240 if lastID != "" {
241 _, err := fmt.Sscanf(lastID, "%d", &since)
242 if err != nil {
243 return nil, false, fmt.Errorf("invalid last ID: %w", err)
244 }
245 }
246 logs, err := db.SelectLogsSince(ctx, clientdb.SelectLogsSinceParams{
247 ID: since,
248 Limit: otlpBatchSize,
249 })
250 if err != nil {
251 return nil, false, fmt.Errorf("select logs: %w", err)
252 }
253 if len(logs) == 0 {
254 return nil, false, nil
255 }
256 since = logs[len(logs)-1].ID
257 // Marshal the logs to OTLP.
258 payload, err := protojson.Marshal(&collogspb.ExportLogsServiceRequest{
259 ResourceLogs: clientdb.LogsToPB(logs),
260 })
261 if err != nil {
262 return nil, false, fmt.Errorf("marshal logs: %w", err)
263 }
264 return &sse.Event{
265 Name: "logs",
266 ID: fmt.Sprintf("%d", since),
267 Data: payload,
268 }, true, nil
269 })
270}
271
272//nolint:dupl
273func (ps *PubSub) MetricsSubscribeHandler(w http.ResponseWriter, r *http.Request, client *daggerClient) error {

Callers

nothing calls this directly

Calls 4

sseHandlerMethod · 0.95
LogsToPBFunction · 0.92
SelectLogsSinceMethod · 0.80
MarshalMethod · 0.65

Tested by

no test coverage detected