-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcontext.go
35 lines (29 loc) · 920 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package httpserver
import (
"github.com/ankorstore/yokai/log"
"github.com/ankorstore/yokai/trace"
"github.com/labstack/echo/v4"
oteltrace "go.opentelemetry.io/otel/trace"
)
// TracerName is the httpserver tracer name.
const TracerName = "httpserver"
// CtxRequestIdKey is a contextual struct key.
type CtxRequestIdKey struct{}
// CtxRequestId returns the contextual request id.
func CtxRequestId(c echo.Context) string {
if rid, ok := c.Request().Context().Value(CtxRequestIdKey{}).(string); ok {
return rid
} else {
return ""
}
}
// CtxRequestId returns the contextual [log.Logger].
func CtxLogger(c echo.Context) *log.Logger {
return log.CtxLogger(c.Request().Context())
}
// CtxTracer returns the contextual [Tracer].
//
// [Tracer]: https://go.opentelemetry.io/otel/trace
func CtxTracer(c echo.Context) oteltrace.Tracer {
return trace.CtxTracerProvider(c.Request().Context()).Tracer(TracerName)
}