mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
b8558df675
* chore: bump a couple of deps Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * feat: upgrade otel Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
45 lines
986 B
Go
45 lines
986 B
Go
package tracing
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
func SetSpanStatus(span trace.Span, err error) {
|
|
if err != nil {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, err.Error())
|
|
} else {
|
|
span.SetStatus(codes.Ok, "")
|
|
}
|
|
}
|
|
|
|
func SetStatus(ctx context.Context, err error) {
|
|
SetSpanStatus(trace.SpanFromContext(ctx), err)
|
|
}
|
|
|
|
func SetHttpStatus(ctx context.Context, err error, code int) {
|
|
span := trace.SpanFromContext(ctx)
|
|
if err != nil {
|
|
span.RecordError(err)
|
|
}
|
|
span.SetAttributes(semconv.HTTPStatusCodeKey.Int(code))
|
|
if code >= 400 {
|
|
span.SetStatus(codes.Error, http.StatusText(code))
|
|
} else {
|
|
span.SetStatus(codes.Ok, http.StatusText(code))
|
|
}
|
|
}
|
|
|
|
func IsInSpan(ctx context.Context) bool {
|
|
span := trace.SpanFromContext(ctx)
|
|
return span.IsRecording()
|
|
}
|
|
|
|
func CurrentSpan(ctx context.Context) trace.Span {
|
|
return trace.SpanFromContext(ctx)
|
|
}
|