Silvan 168242e725
fix(tracing): from opencensus to opentelemetry (#937)
* refactor: switch from opencensus to opentelemetry

* tempo works as designed nooooot

* fix: log traceids

* with grafana agent

* fix: http tracing

* fix: cleanup files

* chore: remove todo

* fix: bad test

* fix: ignore methods in grpc interceptors

* fix: remove test log

* clean up

* typo

* fix(config): configure tracing endpoint

* fix(span): add error id to span
2020-11-20 07:57:39 +01:00

45 lines
916 B
Go

package tracing
import (
"context"
grpc_errs "github.com/caos/zitadel/internal/api/grpc/errors"
api_trace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
)
type Span struct {
span api_trace.Span
opts []api_trace.SpanOption
}
func CreateSpan(span api_trace.Span) *Span {
return &Span{span: span, opts: []api_trace.SpanOption{}}
}
func (s *Span) End() {
if s.span == nil {
return
}
s.span.End(s.opts...)
}
func (s *Span) EndWithError(err error) {
s.SetStatusByError(err)
s.End()
}
func (s *Span) SetStatusByError(err error) {
if s.span == nil {
return
}
if err != nil {
s.span.RecordError(context.TODO(), err, api_trace.WithErrorStatus(codes.Error))
}
code, msg, id, _ := grpc_errs.ExtractCaosError(err)
s.span.SetAttributes(label.Uint32("grpc_code", uint32(code)), label.String("grpc_msg", msg), label.String("error_id", id))
}