mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-18 03:18:52 -06:00
replace go.opencensus.io with opentelemetry in thumbnails
This commit is contained in:
@@ -47,6 +47,7 @@ func NewService(opts ...Option) grpc.Service {
|
||||
)
|
||||
thumbnail = svc.NewInstrument(thumbnail, options.Metrics)
|
||||
thumbnail = svc.NewLogging(thumbnail, options.Logger)
|
||||
thumbnail = svc.NewTracing(thumbnail)
|
||||
}
|
||||
|
||||
_ = proto.RegisterThumbnailServiceHandler(
|
||||
|
||||
@@ -4,7 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
v0proto "github.com/owncloud/ocis/thumbnails/pkg/proto/v0"
|
||||
"go.opencensus.io/trace"
|
||||
thumbnailsTracing "github.com/owncloud/ocis/thumbnails/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
// NewTracing returns a service that instruments traces.
|
||||
@@ -20,15 +21,16 @@ type tracing struct {
|
||||
|
||||
// GetThumbnail implements the ThumbnailServiceHandler interface.
|
||||
func (t tracing) GetThumbnail(ctx context.Context, req *v0proto.GetThumbnailRequest, rsp *v0proto.GetThumbnailResponse) error {
|
||||
ctx, span := trace.StartSpan(ctx, "Thumbnails.GetThumbnail")
|
||||
tracer := thumbnailsTracing.TraceProvider.Tracer("thumbnails")
|
||||
ctx, span := tracer.Start(ctx, "Thumbnails.GetThumbnail")
|
||||
defer span.End()
|
||||
|
||||
span.Annotate([]trace.Attribute{
|
||||
trace.StringAttribute("filepath", req.Filepath),
|
||||
trace.StringAttribute("thumbnail_type", req.ThumbnailType.String()),
|
||||
trace.Int64Attribute("width", int64(req.Width)),
|
||||
trace.Int64Attribute("height", int64(req.Height)),
|
||||
}, "Execute Thumbnails.GetThumbnail handler")
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{"filepath", attribute.StringValue(req.Filepath)},
|
||||
attribute.KeyValue{"thumbnail_type", attribute.StringValue(req.ThumbnailType.String())},
|
||||
attribute.KeyValue{"width", attribute.IntValue(int(req.Width))},
|
||||
attribute.KeyValue{"height", attribute.IntValue(int(req.Height))},
|
||||
)
|
||||
|
||||
return t.next.GetThumbnail(ctx, req, rsp)
|
||||
}
|
||||
|
||||
@@ -1,87 +1,58 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"contrib.go.opencensus.io/exporter/jaeger"
|
||||
"contrib.go.opencensus.io/exporter/ocagent"
|
||||
"contrib.go.opencensus.io/exporter/zipkin"
|
||||
openzipkin "github.com/openzipkin/zipkin-go"
|
||||
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/trace"
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||
)
|
||||
|
||||
var (
|
||||
// Propagator ensures the entire module uses the same trace propagation strategy.
|
||||
Propagator propagation.TextMapPropagator
|
||||
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config, logger log.Logger) error {
|
||||
if cfg.Tracing.Enabled {
|
||||
switch t := cfg.Tracing.Type; t {
|
||||
case "agent":
|
||||
exporter, err := ocagent.NewExporter(
|
||||
ocagent.WithReconnectionPeriod(5*time.Second),
|
||||
ocagent.WithAddress(cfg.Tracing.Endpoint),
|
||||
ocagent.WithServiceName(cfg.Tracing.Service),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error().
|
||||
Err(err).
|
||||
Str("endpoint", cfg.Tracing.Endpoint).
|
||||
Str("collector", cfg.Tracing.Collector).
|
||||
Msg("Failed to create agent tracing")
|
||||
return err
|
||||
}
|
||||
trace.RegisterExporter(exporter)
|
||||
view.RegisterExporter(exporter)
|
||||
case "jaeger":
|
||||
exporter, err := jaeger.NewExporter(
|
||||
jaeger.Options{
|
||||
AgentEndpoint: cfg.Tracing.Endpoint,
|
||||
CollectorEndpoint: cfg.Tracing.Collector,
|
||||
Process: jaeger.Process{
|
||||
ServiceName: cfg.Tracing.Service,
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error().
|
||||
Err(err).
|
||||
Str("endpoint", cfg.Tracing.Endpoint).
|
||||
Str("collector", cfg.Tracing.Collector).
|
||||
Msg("Failed to create jaeger tracing")
|
||||
return err
|
||||
{
|
||||
exp, err := jaeger.New(
|
||||
jaeger.WithCollectorEndpoint(
|
||||
jaeger.WithEndpoint(cfg.Tracing.Collector),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// set package level trace provider and propagator.
|
||||
TraceProvider = sdktrace.NewTracerProvider(
|
||||
sdktrace.WithBatcher(exp),
|
||||
sdktrace.WithResource(resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String("thumbnails")),
|
||||
),
|
||||
)
|
||||
|
||||
Propagator = propagation.NewCompositeTextMapPropagator(
|
||||
propagation.Baggage{},
|
||||
propagation.TraceContext{},
|
||||
)
|
||||
}
|
||||
trace.RegisterExporter(exporter)
|
||||
case "agent":
|
||||
fallthrough
|
||||
case "zipkin":
|
||||
endpoint, err := openzipkin.NewEndpoint(
|
||||
cfg.Tracing.Service,
|
||||
cfg.Tracing.Endpoint,
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error().
|
||||
Err(err).
|
||||
Str("endpoint", cfg.Tracing.Endpoint).
|
||||
Str("collector", cfg.Tracing.Collector).
|
||||
Msg("Failed to create zipkin tracing")
|
||||
return err
|
||||
}
|
||||
exporter := zipkin.NewExporter(
|
||||
zipkinhttp.NewReporter(
|
||||
cfg.Tracing.Collector,
|
||||
),
|
||||
endpoint,
|
||||
)
|
||||
trace.RegisterExporter(exporter)
|
||||
fallthrough
|
||||
default:
|
||||
logger.Warn().
|
||||
Str("type", t).
|
||||
Msg("Unknown tracing backend")
|
||||
logger.Warn().Str("type", t).Msg("Unknown tracing backend")
|
||||
}
|
||||
trace.ApplyConfig(
|
||||
trace.Config{
|
||||
DefaultSampler: trace.AlwaysSample(),
|
||||
},
|
||||
)
|
||||
} else {
|
||||
logger.Debug().
|
||||
Msg("Tracing is not enabled")
|
||||
|
||||
Reference in New Issue
Block a user