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
()
| 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 |
| 1043 | func (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. |
no test coverage detected