-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from w-h-a/traces
feat: memory-based traces
- Loading branch information
Showing
21 changed files
with
440 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
package http | ||
|
||
import "net/http" | ||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/w-h-a/pkg/telemetry/tracev2" | ||
"github.com/w-h-a/pkg/utils/errorutils" | ||
"github.com/w-h-a/pkg/utils/httputils" | ||
) | ||
|
||
type HealthHandler interface { | ||
Check(w http.ResponseWriter, r *http.Request) | ||
Trace(w http.ResponseWriter, r *http.Request) | ||
} | ||
|
||
type healthHandler struct { | ||
tracer tracev2.Trace | ||
} | ||
|
||
func (h *healthHandler) Check(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(200) | ||
w.Write([]byte("ok")) | ||
} | ||
|
||
func NewHealthHandler() HealthHandler { | ||
return &healthHandler{} | ||
func (h *healthHandler) Trace(w http.ResponseWriter, r *http.Request) { | ||
c := r.URL.Query().Get("count") | ||
|
||
var count int | ||
var err error | ||
|
||
if len(c) > 0 { | ||
count, err = strconv.Atoi(c) | ||
if err != nil { | ||
httputils.ErrResponse(w, errorutils.BadRequest("trace", "received bad count query param: %v", err)) | ||
return | ||
} | ||
} | ||
|
||
spans, err := h.tracer.Read( | ||
tracev2.ReadWithCount(count), | ||
) | ||
if err != nil { | ||
httputils.ErrResponse(w, errorutils.InternalServerError("trace", "failed to retrieve traces: %v", err)) | ||
return | ||
} | ||
|
||
httputils.OkResponse(w, spans) | ||
} | ||
|
||
func NewHealthHandler(tracer tracev2.Trace) HealthHandler { | ||
return &healthHandler{tracer} | ||
} |
Oops, something went wrong.