diff --git a/pkg/sidecar/proxy/chat_completions.go b/pkg/sidecar/proxy/chat_completions.go index eb08bf1237..1c367b9d28 100644 --- a/pkg/sidecar/proxy/chat_completions.go +++ b/pkg/sidecar/proxy/chat_completions.go @@ -54,9 +54,14 @@ func (s *Server) chatCompletionsHandler(w http.ResponseWriter, r *http.Request) ctx = context.WithValue(ctx, requestStartTimeKey, requestStart) r = r.WithContext(ctx) + // Set span attributes with safe defaults for nil values + requestPath := "" + if r.URL != nil { + requestPath = r.URL.Path + } span.SetAttributes( attribute.String("llm_d.pd_proxy.connector", s.config.Connector), - attribute.String("llm_d.pd_proxy.request_path", r.URL.Path), + attribute.String("llm_d.pd_proxy.request_path", requestPath), ) var prefillHostPorts []string diff --git a/pkg/sidecar/proxy/proxy_helpers.go b/pkg/sidecar/proxy/proxy_helpers.go index 9a67df213f..8be0623636 100644 --- a/pkg/sidecar/proxy/proxy_helpers.go +++ b/pkg/sidecar/proxy/proxy_helpers.go @@ -32,7 +32,11 @@ func (s *Server) startHTTP(ctx context.Context, cert *tls.Certificate) error { // Wrap handler with OpenTelemetry middleware to extract trace context from incoming requests handler := otelhttp.NewHandler(s.handler, "llm-d-pd-proxy", otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string { - return "llm_d.pd_proxy." + r.Method + " " + r.URL.Path + path := "" + if r.URL != nil { + path = r.URL.Path + } + return "llm_d.pd_proxy." + r.Method + " " + path }), )