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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
exporter.RegisterSimpleSpanProcessor()
|
||||||
// Wrap stdout exporter with SimpleSpanProcessor and register the processor.
|
|
||||||
ssp := sdktrace.NewSimpleSpanProcessor(exporter)
|
|
||||||
sdktrace.RegisterSpanProcessor(ssp)
|
|
||||||
|
|
||||||
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
|
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
|
||||||
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
|
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ func initTracer() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
exporter.RegisterSimpleSpanProcessor()
|
||||||
// Wrap stdout exporter with SimpleSpanProcessor and register the processor.
|
|
||||||
ssp := sdktrace.NewSimpleSpanProcessor(exporter)
|
|
||||||
sdktrace.RegisterSpanProcessor(ssp)
|
|
||||||
|
|
||||||
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
|
// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
|
||||||
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
|
// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
exporter.RegisterSimpleSpanProcessor()
|
||||||
// Wrap exporter with SimpleSpanProcessor and register the processor.
|
|
||||||
ssp := trace.NewSimpleSpanProcessor(exporter)
|
|
||||||
trace.RegisterSpanProcessor(ssp)
|
|
||||||
|
|
||||||
// For demoing purposes, always sample. In a production application, you should
|
// For demoing purposes, always sample. In a production application, you should
|
||||||
// configure this to a trace.ProbabilitySampler set at the desired
|
// configure this to a trace.ProbabilitySampler set at the desired
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package jaeger
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"google.golang.org/api/support/bundler"
|
"google.golang.org/api/support/bundler"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
@@ -24,6 +25,7 @@ import (
|
|||||||
"go.opentelemetry.io/api/core"
|
"go.opentelemetry.io/api/core"
|
||||||
gen "go.opentelemetry.io/exporter/trace/jaeger/internal/gen-go/jaeger"
|
gen "go.opentelemetry.io/exporter/trace/jaeger/internal/gen-go/jaeger"
|
||||||
"go.opentelemetry.io/sdk/export"
|
"go.opentelemetry.io/sdk/export"
|
||||||
|
"go.opentelemetry.io/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultServiceName = "OpenTelemetry"
|
const defaultServiceName = "OpenTelemetry"
|
||||||
@@ -138,11 +140,20 @@ type Tag struct {
|
|||||||
|
|
||||||
// Exporter is an implementation of trace.Exporter that uploads spans to Jaeger.
|
// Exporter is an implementation of trace.Exporter that uploads spans to Jaeger.
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
|
once sync.Once
|
||||||
process *gen.Process
|
process *gen.Process
|
||||||
bundler *bundler.Bundler
|
bundler *bundler.Bundler
|
||||||
uploader batchUploader
|
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)
|
var _ export.SpanSyncer = (*Exporter)(nil)
|
||||||
|
|
||||||
// ExportSpan exports a SpanData to Jaeger.
|
// ExportSpan exports a SpanData to Jaeger.
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/sdk/export"
|
"go.opentelemetry.io/sdk/export"
|
||||||
|
"go.opentelemetry.io/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options are the options to be used when initializing a stdout export.
|
// 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.
|
// Exporter is an implementation of trace.Exporter that writes spans to stdout.
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
|
once sync.Once
|
||||||
pretty bool
|
pretty bool
|
||||||
outputWriter io.Writer
|
outputWriter io.Writer
|
||||||
}
|
}
|
||||||
@@ -43,6 +46,14 @@ func NewExporter(o Options) (*Exporter, error) {
|
|||||||
}, nil
|
}, 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.
|
// ExportSpan writes a SpanData in json format to stdout.
|
||||||
func (e *Exporter) ExportSpan(ctx context.Context, data *export.SpanData) {
|
func (e *Exporter) ExportSpan(ctx context.Context, data *export.SpanData) {
|
||||||
var jsonSpan []byte
|
var jsonSpan []byte
|
||||||
|
|||||||
Reference in New Issue
Block a user