rework list courses page to be flatten

This commit is contained in:
Aleksandr Trushkin
2024-04-19 00:13:03 +03:00
parent 035e9c848f
commit 3a9e01a683
34 changed files with 1803 additions and 474 deletions

View File

@ -107,11 +107,21 @@ func middlewareCustomWriterInjector() mux.MiddlewareFunc {
}
}
type attributeStringKey string
func (k attributeStringKey) Value(value string) attribute.KeyValue {
return attribute.String(string(k), value)
}
func middlewareTrace() mux.MiddlewareFunc {
reqidAttr := attribute.Key("http.request_id")
statusAttr := attribute.Key("http.status_code")
payloadAttr := attribute.Key("http.payload_size")
pathAttr := attribute.Key("http.template_path")
methodAttr := attributeStringKey("http.request.method")
reqidAttr := attributeStringKey("http.request_id")
routeAttr := attributeStringKey("http.route")
queryAttr := attributeStringKey("url.query")
pathAttr := attributeStringKey("http.path")
uaAttr := attributeStringKey("user_agent.original")
statusAttr := attribute.Key("http.response.status_code")
payloadAttr := attribute.Key("http.response_content_length")
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -120,14 +130,18 @@ func middlewareTrace() mux.MiddlewareFunc {
var span trace.Span
route := mux.CurrentRoute(r)
hname := route.GetName()
hpath, _ := route.GetPathTemplate()
ctx, span = webtracer.Start(
ctx, "http."+hname,
ctx, r.Method+" "+hpath,
trace.WithAttributes(
reqidAttr.String(reqid),
pathAttr.String(hpath),
methodAttr.Value(r.Method),
reqidAttr.Value(reqid),
routeAttr.Value(hpath),
pathAttr.Value(r.URL.Path),
queryAttr.Value(r.URL.RawQuery),
uaAttr.Value(r.UserAgent()),
),
trace.WithSpanKind(trace.SpanKindServer),
)
defer span.End()