You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
add RegisterSimpleSpanProcessor() modeled on stackdriver code (#213)
* add RegisterSimpleSpanProcessor() modeled on stackdriver code * update examples
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,6 +17,7 @@ package jaeger
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/api/support/bundler"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"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"
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user