Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
f071b4b145 | |||
44a2f58a69 |
38
handler.go
38
handler.go
@@ -436,11 +436,12 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var sp tracer.Span
|
var sp tracer.Span
|
||||||
if !match && h.hd != nil {
|
if !match && h.hd != nil {
|
||||||
if hdlr, ok := h.hd.Handler().(http.Handler); ok {
|
if hdlr, ok := h.hd.Handler().(http.Handler); ok {
|
||||||
if !slices.Contains(tracer.DefaultSkipEndpoints, h.hd.Name()) {
|
endpointName := fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name)
|
||||||
ctx, sp = h.opts.Tracer.Start(ctx, h.hd.Name()+" rpc-server",
|
if !slices.Contains(tracer.DefaultSkipEndpoints, endpointName) {
|
||||||
|
ctx, sp = h.opts.Tracer.Start(ctx, "rpc-server",
|
||||||
tracer.WithSpanKind(tracer.SpanKindServer),
|
tracer.WithSpanKind(tracer.SpanKindServer),
|
||||||
tracer.WithSpanLabels(
|
tracer.WithSpanLabels(
|
||||||
"endpoint", h.hd.Name(),
|
"endpoint", endpointName,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -452,20 +453,20 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !slices.Contains(meter.DefaultSkipEndpoints, h.hd.Name()) {
|
if !slices.Contains(meter.DefaultSkipEndpoints, endpointName) {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", h.hd.Name()).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "http").Inc()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
n := GetRspCode(ctx)
|
n := GetRspCode(ctx)
|
||||||
if n > 399 {
|
if n > 399 {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", h.hd.Name(), "status", "success", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "http", "status", "success", "code", strconv.Itoa(n)).Inc()
|
||||||
} else {
|
} else {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", h.hd.Name(), "status", "failure", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "http", "status", "failure", "code", strconv.Itoa(n)).Inc()
|
||||||
}
|
}
|
||||||
te := time.Since(ts)
|
te := time.Since(ts)
|
||||||
h.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", h.hd.Name()).Update(te.Seconds())
|
h.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", endpointName, "server", "http").Update(te.Seconds())
|
||||||
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", h.hd.Name()).Update(te.Seconds())
|
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", endpointName, "server", "http").Update(te.Seconds())
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", h.hd.Name()).Dec()
|
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "http").Dec()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,10 +476,11 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else if !match {
|
} else if !match {
|
||||||
// check for http.HandlerFunc handlers
|
// check for http.HandlerFunc handlers
|
||||||
if !slices.Contains(tracer.DefaultSkipEndpoints, r.URL.Path) {
|
if !slices.Contains(tracer.DefaultSkipEndpoints, r.URL.Path) {
|
||||||
ctx, sp = h.opts.Tracer.Start(ctx, r.URL.Path+" rpc-server",
|
ctx, sp = h.opts.Tracer.Start(ctx, "rpc-server",
|
||||||
tracer.WithSpanKind(tracer.SpanKindServer),
|
tracer.WithSpanKind(tracer.SpanKindServer),
|
||||||
tracer.WithSpanLabels(
|
tracer.WithSpanLabels(
|
||||||
"endpoint", r.URL.Path,
|
"endpoint", r.URL.Path,
|
||||||
|
"server", "http",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -500,10 +502,12 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
endpointName := fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name)
|
endpointName := fmt.Sprintf("%s.%s", hldr.name, hldr.mtype.method.Name)
|
||||||
|
|
||||||
topts := []tracer.SpanOption{
|
topts := []tracer.SpanOption{
|
||||||
tracer.WithSpanKind(tracer.SpanKindServer),
|
tracer.WithSpanKind(tracer.SpanKindServer),
|
||||||
tracer.WithSpanLabels(
|
tracer.WithSpanLabels(
|
||||||
"endpoint", endpointName,
|
"endpoint", endpointName,
|
||||||
|
"server", "http",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,20 +515,20 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
topts = append(topts, tracer.WithSpanRecord(false))
|
topts = append(topts, tracer.WithSpanRecord(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, sp = h.opts.Tracer.Start(ctx, endpointName+" rpc-server", topts...)
|
ctx, sp = h.opts.Tracer.Start(ctx, "rpc-server", topts...)
|
||||||
|
|
||||||
if !slices.Contains(meter.DefaultSkipEndpoints, handler.name) {
|
if !slices.Contains(meter.DefaultSkipEndpoints, handler.name) {
|
||||||
defer func() {
|
defer func() {
|
||||||
te := time.Since(ts)
|
te := time.Since(ts)
|
||||||
h.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", handler.name).Update(te.Seconds())
|
h.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", handler.name, "server", "http").Update(te.Seconds())
|
||||||
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", handler.name).Update(te.Seconds())
|
h.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", handler.name, "server", "http").Update(te.Seconds())
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", handler.name).Dec()
|
h.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", handler.name, "server", "http").Dec()
|
||||||
|
|
||||||
n := GetRspCode(ctx)
|
n := GetRspCode(ctx)
|
||||||
if n > 399 {
|
if n > 399 {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "status", "failure", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "server", "http", "status", "failure", "code", strconv.Itoa(n)).Inc()
|
||||||
} else {
|
} else {
|
||||||
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "status", "success", "code", strconv.Itoa(n)).Inc()
|
h.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", handler.name, "server", "http", "status", "success", "code", strconv.Itoa(n)).Inc()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user