bunrouterotel/now can get HTTP path from req.Request.URL.Path;

develop bunrouterotel/v0.2.0
Ge Song 11 months ago
parent a278d10e4c
commit 2963386f32

@ -13,7 +13,7 @@ import (
const (
tracerName = "git.blauwelle.com/go/crate/bunrouterotel"
version = "0.1.0"
version = "0.2.0"
)
type config struct {
@ -53,18 +53,21 @@ func Middleware(serverName string, opts ...Option) bunrouter.MiddlewareFunc {
var spanName string
params := req.Params()
route := params.Route()
if route != "" {
spanName = req.Method + " " + route
} else {
spanName = "HTTP " + req.Method + " route not found"
if route == "" {
if req.Request != nil && req.Request.URL != nil && req.Request.URL.Path != "" {
route = req.Request.URL.Path
} else {
route = "route not found"
}
}
tarcerStartOpts := []trace.SpanStartOption{
spanName = req.Method + " " + route
tracerStartOpts := []trace.SpanStartOption{
trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", req.Request)...),
trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(req.Request)...),
trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(serverName, route, req.Request)...),
trace.WithSpanKind(trace.SpanKindServer),
}
ctx, span := tracer.Start(ctx, spanName, tarcerStartOpts...)
ctx, span := tracer.Start(ctx, spanName, tracerStartOpts...)
req.Request = req.Request.WithContext(ctx)
paramSlice := params.Slice()
attrs := make([]attribute.KeyValue, 0, len(paramSlice))

Loading…
Cancel
Save