prevent having a nil traceprovider

This commit is contained in:
A.Unger
2021-08-09 17:14:36 +02:00
parent 2a60b6b933
commit fe530e9a27
8 changed files with 22 additions and 16 deletions

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {

View File

@@ -74,7 +74,7 @@ func Server(opts ...Option) (http.Service, error) {
)
{
handle = svc.NewTracing(handle)
//handle = svc.NewTracing(handle)
handle = svc.NewInstrument(handle, options.Metrics)
handle = svc.NewLogging(handle, options.Logger)
}

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {

View File

@@ -3,6 +3,8 @@ package svc
import (
"context"
"go.opentelemetry.io/otel/trace"
v0proto "github.com/owncloud/ocis/thumbnails/pkg/proto/v0"
thumbnailsTracing "github.com/owncloud/ocis/thumbnails/pkg/tracing"
"go.opentelemetry.io/otel/attribute"
@@ -21,16 +23,20 @@ type tracing struct {
// GetThumbnail implements the ThumbnailServiceHandler interface.
func (t tracing) GetThumbnail(ctx context.Context, req *v0proto.GetThumbnailRequest, rsp *v0proto.GetThumbnailResponse) error {
tracer := thumbnailsTracing.TraceProvider.Tracer("thumbnails")
ctx, span := tracer.Start(ctx, "Thumbnails.GetThumbnail")
defer span.End()
var span trace.Span
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))},
)
if thumbnailsTracing.TraceProvider != nil {
tracer := thumbnailsTracing.TraceProvider.Tracer("thumbnails")
ctx, span = tracer.Start(ctx, "Thumbnails.GetThumbnail")
defer span.End()
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)
}

View File

@@ -15,7 +15,7 @@ var (
Propagator propagation.TextMapPropagator
// TraceProvider is the global trace provider for the proxy service.
TraceProvider *sdktrace.TracerProvider
TraceProvider = sdktrace.NewTracerProvider()
)
func Configure(cfg *config.Config, logger log.Logger) error {