1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00

remove rSSP and rBSP code, use NewProvider instead. (#271)

This commit is contained in:
Liz Fong-Jones 2019-11-02 00:35:18 +01:00 committed by rghetia
parent 8b061a2102
commit 440b6653c9
6 changed files with 10 additions and 85 deletions

View File

@ -41,7 +41,6 @@ func initTracer() {
if err != nil {
log.Fatal(err)
}
exporter.RegisterSimpleSpanProcessor()
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.

View File

@ -34,7 +34,6 @@ func initTracer() {
if err != nil {
log.Fatal(err)
}
exporter.RegisterSimpleSpanProcessor()
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.

View File

@ -18,7 +18,6 @@ import (
"context"
"encoding/binary"
"log"
"sync"
"google.golang.org/api/support/bundler"
"google.golang.org/grpc/codes"
@ -26,7 +25,6 @@ import (
"go.opentelemetry.io/otel/api/core"
gen "go.opentelemetry.io/otel/exporter/trace/jaeger/internal/gen-go/jaeger"
"go.opentelemetry.io/otel/sdk/export"
"go.opentelemetry.io/otel/sdk/trace"
)
const defaultServiceName = "OpenTelemetry"
@ -137,21 +135,11 @@ type Process struct {
// Exporter is an implementation of trace.Exporter that uploads spans to Jaeger.
type Exporter struct {
once sync.Once
process *gen.Process
bundler *bundler.Bundler
uploader batchUploader
}
// RegisterSimpleSpanProcessor registers e as SimpleSpanProcessor.
//TODO(eran-levy): deprecate - already registered in NewProvider
func (e *Exporter) RegisterSimpleSpanProcessor() {
e.once.Do(func() {
ssp := trace.NewSimpleSpanProcessor(e)
trace.RegisterSpanProcessor(ssp)
})
}
var _ export.SpanSyncer = (*Exporter)(nil)
// ExportSpan exports a SpanData to Jaeger.

View File

@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"log"
"sync"
"time"
traceapi "cloud.google.com/go/trace/apiv2"
@ -28,7 +27,6 @@ import (
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/sdk/export"
"go.opentelemetry.io/otel/sdk/trace"
)
// Option is function type that is passed to the exporter initialization function.
@ -71,22 +69,6 @@ type options struct {
// Optional.
TraceClientOptions []option.ClientOption
// BatchDelayThreshold determines the max amount of time
// the exporter can wait before uploading view data or trace spans to
// the backend.
// Optional.
BatchDelayThreshold time.Duration
// MaxQueueSize is the maximum queue size to buffer spans for delayed processing.
// See the detailed definition in https://godoc.org/go.opentelemetry.io/otel/sdk/trace#BatchSpanProcessorOptions.
// Default is 2048. Optional.
MaxQueueSize int
// MaxExportBatchSize is the maximum number of spans to process in a single batch.
// See the detailed definition in https://godoc.org/go.opentelemetry.io/otel/sdk/trace#BatchSpanProcessorOptions.
// Default is 512. Optional.
MaxExportBatchSize int
// TraceSpansBufferMaxBytes is the maximum size (in bytes) of spans that
// will be buffered in memory before being dropped.
//
@ -178,9 +160,7 @@ const defaultTimeout = 5 * time.Second
// TODO(yoshifumi): add a metrics exporter once the spec definition
// process and the sampler implementation are done.
type Exporter struct {
once sync.Once
traceExporter *traceExporter
spanProcessor trace.SpanProcessor
}
// NewExporter creates a new Exporter thats implements trace.Exporter.
@ -226,36 +206,6 @@ func newContextWithTimeout(ctx context.Context, timeout time.Duration) (context.
return context.WithTimeout(ctx, timeout)
}
// RegisterBatchSpanProcessor registers e as BatchSpanProcessor.
func (e *Exporter) RegisterBatchSpanProcessor() error {
opts := []trace.BatchSpanProcessorOption{}
if e.traceExporter.o.BatchDelayThreshold > 0 {
opts = append(opts, trace.WithScheduleDelayMillis(e.traceExporter.o.BatchDelayThreshold))
}
if e.traceExporter.o.MaxQueueSize > 0 {
opts = append(opts, trace.WithMaxQueueSize(e.traceExporter.o.MaxQueueSize))
}
if e.traceExporter.o.MaxExportBatchSize > 0 {
opts = append(opts, trace.WithMaxExportBatchSize(e.traceExporter.o.MaxExportBatchSize))
}
var err error
e.once.Do(func() {
e.spanProcessor, err = trace.NewBatchSpanProcessor(e, opts...)
trace.RegisterSpanProcessor(e.spanProcessor)
})
return err
}
// RegisterSimpleSpanProcessor registers e as SimpleSpanProcessor.
func (e *Exporter) RegisterSimpleSpanProcessor() {
e.once.Do(func() {
e.spanProcessor = trace.NewSimpleSpanProcessor(e)
trace.RegisterSpanProcessor(e.spanProcessor)
})
}
// ExportSpan exports a SpanData to Stackdriver Trace.
func (e *Exporter) ExportSpan(ctx context.Context, sd *export.SpanData) {
if len(e.traceExporter.o.DefaultTraceAttributes) > 0 {
@ -286,9 +236,3 @@ func (e *Exporter) sdWithDefaultTraceAttributes(sd *export.SpanData) *export.Spa
newSD.Attributes = append(newSD.Attributes, sd.Attributes...)
return &newSD
}
// Shutdown unregisters spanProcessor.
func (e *Exporter) Shutdown() {
trace.UnregisterSpanProcessor(e.spanProcessor)
e.spanProcessor = nil
}

View File

@ -19,7 +19,6 @@ import (
"encoding/json"
"io"
"os"
"sync"
"time"
"google.golang.org/grpc/codes"
@ -27,7 +26,6 @@ import (
"go.opentelemetry.io/otel/api/core"
apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/sdk/export"
"go.opentelemetry.io/otel/sdk/trace"
)
// Options are the options to be used when initializing a stdout export.
@ -39,7 +37,6 @@ type Options struct {
// Exporter is an implementation of trace.Exporter that writes spans to stdout.
type Exporter struct {
once sync.Once
pretty bool
outputWriter io.Writer
}
@ -51,14 +48,6 @@ func NewExporter(o Options) (*Exporter, error) {
}, nil
}
// RegisterSimpleSpanProcessor registers e as SimpleSpanProcessor.
func (e *Exporter) RegisterSimpleSpanProcessor() {
e.once.Do(func() {
ssp := trace.NewSimpleSpanProcessor(e)
trace.RegisterSpanProcessor(ssp)
})
}
type jsonValue struct {
Type string
Value interface{}

View File

@ -27,10 +27,16 @@ const (
defaultTracerName = "go.opentelemetry.io/otel/sdk/tracer"
)
// batcher contains export.SpanBatcher and its options.
type batcher struct {
b export.SpanBatcher
opts []BatchSpanProcessorOption
}
// ProviderOptions
type ProviderOptions struct {
syncers []export.SpanSyncer
batchers []export.SpanBatcher
batchers []batcher
config Config
}
@ -73,7 +79,7 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
}
for _, batcher := range o.batchers {
bsp, err := NewBatchSpanProcessor(batcher)
bsp, err := NewBatchSpanProcessor(batcher.b, batcher.opts...)
if err != nil {
return nil, err
}
@ -172,9 +178,9 @@ func WithSyncer(syncer export.SpanSyncer) ProviderOption {
// This option can be used multiple times.
// The Batchers are wrapped into BatchedSpanProcessors and registered
// with the provider.
func WithBatcher(batcher export.SpanBatcher) ProviderOption {
func WithBatcher(b export.SpanBatcher, bopts ...BatchSpanProcessorOption) ProviderOption {
return func(opts *ProviderOptions) {
opts.batchers = append(opts.batchers, batcher)
opts.batchers = append(opts.batchers, batcher{b, bopts})
}
}