mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-15 04:33:37 +00:00
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
This commit is contained in:
@@ -1,21 +1,28 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"go.opencensus.io/trace"
|
||||
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
"github.com/caos/zitadel/internal/tracing/otel"
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Fraction float64
|
||||
Fraction float64
|
||||
MetricPrefix string
|
||||
}
|
||||
|
||||
type Tracer struct {
|
||||
otel.Tracer
|
||||
}
|
||||
|
||||
func (c *Config) NewTracer() error {
|
||||
if c.Fraction < 1 {
|
||||
c.Fraction = 1
|
||||
sampler := sdk_trace.ParentBased(sdk_trace.TraceIDRatioBased(c.Fraction))
|
||||
exporter, err := stdout.NewExporter(stdout.WithPrettyPrint())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tracing.T = &Tracer{trace.ProbabilitySampler(c.Fraction)}
|
||||
|
||||
return tracing.T.Start()
|
||||
tracing.T = &Tracer{Tracer: *(otel.NewTracer(c.MetricPrefix, sampler, exporter))}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"go.opencensus.io/examples/exporter"
|
||||
"go.opencensus.io/plugin/ocgrpc"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/trace"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
)
|
||||
|
||||
type Tracer struct {
|
||||
sampler trace.Sampler
|
||||
}
|
||||
|
||||
func (t *Tracer) Start() error {
|
||||
trace.RegisterExporter(&exporter.PrintExporter{})
|
||||
|
||||
views := append(ocgrpc.DefaultServerViews, ocgrpc.DefaultClientViews...)
|
||||
views = append(views, ochttp.DefaultClientViews...)
|
||||
views = append(views, ochttp.DefaultServerViews...)
|
||||
|
||||
if err := view.Register(views...); err != nil {
|
||||
return errors.ThrowInternal(err, "LOG-PoFiB", "unable to register view")
|
||||
}
|
||||
|
||||
trace.ApplyConfig(trace.Config{DefaultSampler: t.sampler})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Tracer) Sampler() trace.Sampler {
|
||||
return t.sampler
|
||||
}
|
||||
|
||||
func (t *Tracer) NewServerInterceptorSpan(ctx context.Context, name string) (context.Context, *tracing.Span) {
|
||||
return t.newSpanFromName(ctx, name, trace.WithSpanKind(trace.SpanKindServer))
|
||||
}
|
||||
|
||||
func (t *Tracer) NewServerSpan(ctx context.Context, caller string) (context.Context, *tracing.Span) {
|
||||
return t.newSpan(ctx, caller, trace.WithSpanKind(trace.SpanKindServer))
|
||||
}
|
||||
|
||||
func (t *Tracer) NewClientInterceptorSpan(ctx context.Context, name string) (context.Context, *tracing.Span) {
|
||||
return t.newSpanFromName(ctx, name, trace.WithSpanKind(trace.SpanKindClient))
|
||||
}
|
||||
|
||||
func (t *Tracer) NewClientSpan(ctx context.Context, caller string) (context.Context, *tracing.Span) {
|
||||
return t.newSpan(ctx, caller, trace.WithSpanKind(trace.SpanKindClient))
|
||||
}
|
||||
|
||||
func (t *Tracer) NewSpan(ctx context.Context, caller string) (context.Context, *tracing.Span) {
|
||||
return t.newSpan(ctx, caller)
|
||||
}
|
||||
|
||||
func (t *Tracer) newSpan(ctx context.Context, caller string, options ...trace.StartOption) (context.Context, *tracing.Span) {
|
||||
return t.newSpanFromName(ctx, caller, options...)
|
||||
}
|
||||
|
||||
func (t *Tracer) newSpanFromName(ctx context.Context, name string, options ...trace.StartOption) (context.Context, *tracing.Span) {
|
||||
ctx, span := trace.StartSpan(ctx, name, options...)
|
||||
return ctx, tracing.CreateSpan(span)
|
||||
}
|
||||
|
||||
func (t *Tracer) NewSpanHTTP(r *http.Request, caller string) (*http.Request, *tracing.Span) {
|
||||
ctx, span := t.NewSpan(r.Context(), caller)
|
||||
r = r.WithContext(ctx)
|
||||
return r, span
|
||||
}
|
||||
Reference in New Issue
Block a user