Skip to content

Commit

Permalink
feat(otelfiber): add status code attribute to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
onematchfox committed Dec 20, 2022
1 parent ed01458 commit 8dc45bd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions otelfiber/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ func Middleware(service string, opts ...Option) fiber.Handler {

span.SetName(cfg.SpanNameFormatter(c))

routeAttr := semconv.HTTPRouteKey.String(c.Route().Path) // no need to copy c.Route().Path: route strings should be immutable across app lifecycle
responseAttrs := append(
semconv.HTTPAttributesFromHTTPStatusCode(c.Response().StatusCode()),
semconv.HTTPRouteKey.String(c.Route().Path), // no need to copy c.Route().Path: route strings should be immutable across app lifecycle
)

span.SetAttributes(routeAttr)
span.SetAttributes(responseAttrs...)

responseMetricAttrs = append(
requestMetricsAttrs,
routeAttr)
responseMetricAttrs,
responseAttrs...)
requestSize := int64(len(c.Request().Body()))
responseSize := int64(len(c.Response().Body()))

Expand All @@ -160,9 +163,7 @@ func Middleware(service string, opts ...Option) fiber.Handler {
_ = c.App().Config().ErrorHandler(c, err)
}

attrs := semconv.HTTPAttributesFromHTTPStatusCode(c.Response().StatusCode())
spanStatus, spanMessage := semconv.SpanStatusFromHTTPStatusCodeAndSpanKind(c.Response().StatusCode(), oteltrace.SpanKindServer)
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)

return nil
Expand Down

0 comments on commit 8dc45bd

Please sign in to comment.