mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
8609ced24b
* chore(deps): bump k8s.io/apiextensions-apiserver from 0.19.2 to 0.21.3 Bumps [k8s.io/apiextensions-apiserver](https://github.com/kubernetes/apiextensions-apiserver) from 0.19.2 to 0.21.3. - [Release notes](https://github.com/kubernetes/apiextensions-apiserver/releases) - [Commits](https://github.com/kubernetes/apiextensions-apiserver/compare/v0.19.2...v0.21.3) --- updated-dependencies: - dependency-name: k8s.io/apiextensions-apiserver dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump google.golang.org/api from 0.34.0 to 0.52.0 Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.34.0 to 0.52.0. - [Release notes](https://github.com/googleapis/google-api-go-client/releases) - [Changelog](https://github.com/googleapis/google-api-go-client/blob/master/CHANGES.md) - [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.34.0...v0.52.0) --- updated-dependencies: - dependency-name: google.golang.org/api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * start update dependencies * update mods and otlp * fix(build): update to go 1.16 * old version for k8s mods * update k8s versions * update orbos * with batcher * add batch span processor * try with older otel version 0.20 * remove syncer * otel rc2 * fix config Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefan Benz <stefan@caos.ch>
73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package otel
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/propagation"
|
|
sdk_trace "go.opentelemetry.io/otel/sdk/trace"
|
|
api_trace "go.opentelemetry.io/otel/trace"
|
|
|
|
"github.com/caos/zitadel/internal/telemetry/tracing"
|
|
)
|
|
|
|
type Tracer struct {
|
|
Exporter api_trace.Tracer
|
|
sampler sdk_trace.Sampler
|
|
}
|
|
|
|
func NewTracer(name string, sampler sdk_trace.Sampler, exporter sdk_trace.SpanExporter) *Tracer {
|
|
spanProcessor := sdk_trace.NewBatchSpanProcessor(exporter)
|
|
tp := sdk_trace.NewTracerProvider(
|
|
sdk_trace.WithSampler(sampler),
|
|
sdk_trace.WithBatcher(exporter),
|
|
sdk_trace.WithSpanProcessor(spanProcessor),
|
|
)
|
|
|
|
otel.SetTracerProvider(tp)
|
|
tc := propagation.TraceContext{}
|
|
otel.SetTextMapPropagator(tc)
|
|
|
|
return &Tracer{Exporter: tp.Tracer(name), sampler: sampler}
|
|
}
|
|
|
|
func (t *Tracer) Sampler() sdk_trace.Sampler {
|
|
return t.sampler
|
|
}
|
|
|
|
func (t *Tracer) NewServerInterceptorSpan(ctx context.Context, name string) (context.Context, *tracing.Span) {
|
|
return t.newSpanFromName(ctx, name, api_trace.WithSpanKind(api_trace.SpanKindServer))
|
|
}
|
|
|
|
func (t *Tracer) NewServerSpan(ctx context.Context, caller string) (context.Context, *tracing.Span) {
|
|
return t.newSpan(ctx, caller, api_trace.WithSpanKind(api_trace.SpanKindServer))
|
|
}
|
|
|
|
func (t *Tracer) NewClientInterceptorSpan(ctx context.Context, name string) (context.Context, *tracing.Span) {
|
|
return t.newSpanFromName(ctx, name, api_trace.WithSpanKind(api_trace.SpanKindClient))
|
|
}
|
|
|
|
func (t *Tracer) NewClientSpan(ctx context.Context, caller string) (context.Context, *tracing.Span) {
|
|
return t.newSpan(ctx, caller, api_trace.WithSpanKind(api_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 ...api_trace.SpanStartOption) (context.Context, *tracing.Span) {
|
|
return t.newSpanFromName(ctx, caller, options...)
|
|
}
|
|
|
|
func (t *Tracer) newSpanFromName(ctx context.Context, name string, options ...api_trace.SpanStartOption) (context.Context, *tracing.Span) {
|
|
ctx, span := t.Exporter.Start(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
|
|
}
|