| 104 | } |
| 105 | |
| 106 | func (s *Server) Serve(ctx context.Context, ln net.Listener) error { |
| 107 | // Wrap the Echo handler with otelhttp so the configured W3C |
| 108 | // propagator extracts `traceparent` / `tracestate` / `baggage` |
| 109 | // from incoming API requests. Without this the API server's |
| 110 | // runtime spans (already wired via `WithTracer` in the session |
| 111 | // manager) start fresh trace ids per request rather than |
| 112 | // chaining onto the calling client's trace. |
| 113 | srv := http.Server{ |
| 114 | Handler: otelhttp.NewHandler(s.e, "agent-api"), |
| 115 | ReadHeaderTimeout: 10 * time.Second, |
| 116 | } |
| 117 | |
| 118 | if err := srv.Serve(ln); err != nil && ctx.Err() == nil { |
| 119 | slog.ErrorContext(ctx, "Failed to start server", "error", err) |
| 120 | return err |
| 121 | } |
| 122 | |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | const maxAPITimeout = 5 * time.Minute |
| 127 | |