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

Method serveQuery

engine/server/session.go:1326–1433  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, client *daggerClient)

Source from the content-addressed store, hash-verified

1324}
1325
1326func (srv *Server) serveQuery(w http.ResponseWriter, r *http.Request, client *daggerClient) (rerr error) {
1327 sess := client.daggerSession
1328 sess.dagqlMu.Lock()
1329 if sess.dagqlClosing {
1330 sess.dagqlMu.Unlock()
1331 return gqlErr(errSessionClosing, http.StatusServiceUnavailable)
1332 }
1333 sess.dagqlInFlight++
1334 sess.dagqlMu.Unlock()
1335 defer func() {
1336 sess.dagqlMu.Lock()
1337 sess.dagqlInFlight--
1338 if sess.dagqlInFlight == 0 {
1339 sess.dagqlCond.Broadcast()
1340 }
1341 sess.dagqlMu.Unlock()
1342 }()
1343
1344 ctx := sess.withClosingCancel(r.Context())
1345
1346 // turn panics into graphql errors — must be set up before any code that
1347 // could panic (including ensureExtraModulesLoaded and schema loading).
1348 defer func() {
1349 if v := recover(); v != nil {
1350 bklog.G(ctx).Errorf("panic serving schema: %v %s", v, string(debug.Stack()))
1351 switch v := v.(type) {
1352 case error:
1353 rerr = gqlErr(v, http.StatusInternalServerError)
1354 case string:
1355 rerr = gqlErr(errors.New(v), http.StatusInternalServerError)
1356 default:
1357 rerr = gqlErr(errors.New("internal server error"), http.StatusInternalServerError)
1358 }
1359 }
1360 }()
1361
1362 // only record telemetry if the request is traced, otherwise
1363 // we end up with orphaned spans in their own separate traces from tests etc.
1364 if trace.SpanContextFromContext(ctx).IsValid() {
1365 // create a span to record telemetry into the client's DB
1366 //
1367 // downstream components must use otel.SpanFromContext(ctx).TracerProvider()
1368 clientTracer := client.tracerProvider.Tracer(InstrumentationLibrary)
1369 var span trace.Span
1370 attrs := []attribute.KeyValue{
1371 attribute.Bool(telemetry.UIPassthroughAttr, true),
1372 }
1373 if engineID := client.clientMetadata.CloudScaleOutEngineID; engineID != "" {
1374 attrs = append(attrs, attribute.String(telemetry.EngineIDAttr, engineID))
1375 }
1376 ctx, span = clientTracer.Start(ctx,
1377 fmt.Sprintf("%s %s", r.Method, r.URL.Path),
1378 trace.WithAttributes(attrs...),
1379 )
1380 defer telemetry.EndWithCause(span, &rerr)
1381 }
1382
1383 // install a logger+meter provider that records to the client's DB

Callers

nothing calls this directly

Calls 15

ensureWorkspaceLoadedMethod · 0.95
ensureModulesLoadedMethod · 0.95
ContextWithQueryFunction · 0.92
NewDefaultHandlerFunction · 0.92
withClosingCancelMethod · 0.80
gqlErrFunction · 0.70
ContextMethod · 0.65
NewMethod · 0.65
BoolMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected