Skip to content

Commit

Permalink
Accept review by aluzzardi
Browse files Browse the repository at this point in the history
Signed-off-by: Alvise <vitalvise@gmail.com>
  • Loading branch information
Alvise88 committed Jul 9, 2021
1 parent ac3efa9 commit d2d441e
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions cmd/dagger/logger/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type tracer struct {
TraceProvider *tracesdk.TracerProvider
provider *tracesdk.TracerProvider
}

func InitTracing() io.Closer {
Expand All @@ -33,7 +33,7 @@ func InitTracing() io.Closer {
otel.SetTracerProvider(tp)

tracer := tracer{
TraceProvider: tp,
provider: tp,
}

return tracer
Expand All @@ -51,34 +51,20 @@ func tracerProvider(url string) (*tracesdk.TracerProvider, error) {
}
tp := tracesdk.NewTracerProvider(
// Always be sure to batch in production.
tracesdk.WithBatcher(exp),
tracesdk.WithBatcher(exp, tracesdk.WithMaxExportBatchSize(1)),
// Record information about this application in an Resource.
tracesdk.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("dagger"),
// attribute.String("environment", "dagger"),
// attribute.Int64("ID", 1),
)),
)
return tp, nil
}

func (t tracer) Close() error {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

var closeError error
// Cleanly shutdown and flush telemetry when the application exits.
defer func(ctx context.Context) {
// Do not make the application hang when it is shutdown.
ctx, cancel = context.WithTimeout(ctx, time.Second*5)
defer cancel()
if err := t.TraceProvider.Shutdown(ctx); err != nil {
closeError = err
}
}(ctx)

return closeError
return t.provider.Shutdown(ctx)
}

type nopCloser struct {
Expand Down

0 comments on commit d2d441e

Please sign in to comment.