Skip to content

Commit

Permalink
add RegisterSimpleSpanProcessor() modeled on stackdriver code (open-t…
Browse files Browse the repository at this point in the history
…elemetry#213)

* add RegisterSimpleSpanProcessor() modeled on stackdriver code

* update examples
  • Loading branch information
lizthegrey authored and rghetia committed Oct 16, 2019
1 parent 9f03360 commit 75562dd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
5 changes: 1 addition & 4 deletions example/http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func initTracer() {
if err != nil {
log.Fatal(err)
}

// Wrap stdout exporter with SimpleSpanProcessor and register the processor.
ssp := sdktrace.NewSimpleSpanProcessor(exporter)
sdktrace.RegisterSpanProcessor(ssp)
exporter.RegisterSimpleSpanProcessor()

// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
Expand Down
5 changes: 1 addition & 4 deletions example/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ func initTracer() {
if err != nil {
log.Fatal(err)
}

// Wrap stdout exporter with SimpleSpanProcessor and register the processor.
ssp := sdktrace.NewSimpleSpanProcessor(exporter)
sdktrace.RegisterSpanProcessor(ssp)
exporter.RegisterSimpleSpanProcessor()

// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
Expand Down
5 changes: 1 addition & 4 deletions exporter/trace/jaeger/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ func main() {
if err != nil {
log.Fatal(err)
}

// Wrap exporter with SimpleSpanProcessor and register the processor.
ssp := trace.NewSimpleSpanProcessor(exporter)
trace.RegisterSpanProcessor(ssp)
exporter.RegisterSimpleSpanProcessor()

// For demoing purposes, always sample. In a production application, you should
// configure this to a trace.ProbabilitySampler set at the desired
Expand Down
11 changes: 11 additions & 0 deletions exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package jaeger
import (
"context"
"log"
"sync"

"google.golang.org/api/support/bundler"
"google.golang.org/grpc/codes"

"go.opentelemetry.io/api/core"
gen "go.opentelemetry.io/exporter/trace/jaeger/internal/gen-go/jaeger"
"go.opentelemetry.io/sdk/export"
"go.opentelemetry.io/sdk/trace"
)

const defaultServiceName = "OpenTelemetry"
Expand Down Expand Up @@ -138,11 +140,20 @@ type Tag 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.
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.
Expand Down
11 changes: 11 additions & 0 deletions exporter/trace/stdout/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
"encoding/json"
"io"
"os"
"sync"

"go.opentelemetry.io/sdk/export"
"go.opentelemetry.io/sdk/trace"
)

// Options are the options to be used when initializing a stdout export.
Expand All @@ -32,6 +34,7 @@ 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
}
Expand All @@ -43,6 +46,14 @@ 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)
})
}

// ExportSpan writes a SpanData in json format to stdout.
func (e *Exporter) ExportSpan(ctx context.Context, data *export.SpanData) {
var jsonSpan []byte
Expand Down

0 comments on commit 75562dd

Please sign in to comment.