EndHTTPSpan captures request and response data after the handler is done.
(r *http.Request, status int, span trace.Span)
| 77 | |
| 78 | // EndHTTPSpan captures request and response data after the handler is done. |
| 79 | func EndHTTPSpan(r *http.Request, status int, span trace.Span) { |
| 80 | // set the resource name as we get it only once the handler is executed |
| 81 | route := chi.RouteContext(r.Context()).RoutePattern() |
| 82 | span.SetName(fmt.Sprintf("%s %s", r.Method, route)) |
| 83 | span.SetAttributes(netconv.Transport("tcp")) |
| 84 | span.SetAttributes(httpconv.ServerRequest("coderd", r)...) |
| 85 | span.SetAttributes(semconv.HTTPRouteKey.String(route)) |
| 86 | |
| 87 | // 0 status means one has not yet been sent in which case net/http library will write StatusOK |
| 88 | if status == 0 { |
| 89 | status = http.StatusOK |
| 90 | } |
| 91 | span.SetAttributes(semconv.HTTPStatusCodeKey.Int(status)) |
| 92 | span.SetStatus(httpconv.ServerStatus(status)) |
| 93 | |
| 94 | // finally end span |
| 95 | span.End() |
| 96 | } |
| 97 | |
| 98 | type tracerNameKey struct{} |
| 99 |
no test coverage detected