MCPcopy Index your code
hub / github.com/rilldata/rill / traceHandler

Method traceHandler

cli/pkg/local/server.go:1043–1075  ·  view source on GitHub ↗

traceHandler returns trace information. Traces are stored in a file in `~/.rill/otel_traces.log` in JSON format when `--debug` flag is set. It uses duckdb to search the JSON file for traces and returns the trace output as JSON. The handler accepts two kind of query parameters: - trace_id: search for

()

Source from the content-addressed store, hash-verified

1041// - trace_id: search for traces for a given trace_id
1042// - resource_name: search for trace for the last reconcile of the given resource name
1043func (s *Server) traceHandler() http.Handler {
1044 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1045 traceID := r.URL.Query().Get("trace_id")
1046 resourceName := r.URL.Query().Get("resource_name")
1047 if resourceName == "" && traceID == "" {
1048 w.WriteHeader(http.StatusBadRequest)
1049 return
1050 }
1051 if resourceName != "" && traceID != "" {
1052 w.WriteHeader(http.StatusBadRequest)
1053 return
1054 }
1055
1056 bytes, err := observability.SearchTracesFile(r.Context(), traceID, resourceName)
1057 if err != nil {
1058 if errors.Is(err, sql.ErrNoRows) {
1059 w.WriteHeader(http.StatusNotFound)
1060 return
1061 }
1062 s.logger.Error("failed to search trace", zap.Error(err))
1063 w.WriteHeader(http.StatusInternalServerError)
1064 return
1065 }
1066
1067 w.Header().Set("Content-Type", "application/json")
1068 _, err = w.Write(bytes)
1069 if err != nil {
1070 s.logger.Error("failed to write trace", zap.Error(err))
1071 w.WriteHeader(http.StatusInternalServerError)
1072 return
1073 }
1074 })
1075}
1076
1077// currentGitBranch returns the current git branch of the repository at the given path.
1078// It does not return error if the repo does not exist.

Callers 1

RegisterHandlersMethod · 0.95

Calls 8

SearchTracesFileFunction · 0.92
WriteHeaderMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
ContextMethod · 0.65
ErrorMethod · 0.45
SetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected