Skip to content

Commit

Permalink
Unify trace and metric stdout exporters (#956)
Browse files Browse the repository at this point in the history
* Consolidate stdout exporter

* Move config to own file and match project standard

* Abstract Exporter into unified struct

* Rename trace part of the exporter

* Update import paths and configuration

* Update tests

* Update InstallNewPipeline to not return traceProvider

It is a registered global, access it that way.

* Update example_test

* Update docs

* Update example to be for whole package

* Update metric output

Closer match the span output.

* Clean up span output

Print as a batch and cleanup marshaling.

* Correct spelling error in doc

* Add Exporters README

* Update Changelog

* Propagate changes to rest of project

* Lint fixes

* Fix example test in metric SDK

* Add disable config options for trace and metric

Co-authored-by: Liz Fong-Jones <lizf@honeycomb.io>
  • Loading branch information
MrAlias and lizthegrey authored Jul 22, 2020
1 parent f31d8ec commit 452256c
Show file tree
Hide file tree
Showing 22 changed files with 746 additions and 593 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Jaeger exporter helpers: added InstallNewPipeline and removed RegisterGlobal option instead. (#944)
- Zipkin exporter helpers: pipeline methods introduced, new exporter method adjusted. (#944)
- The trace (`go.opentelemetry.io/otel/exporters/trace/stdout`) and metric (`go.opentelemetry.io/otel/exporters/metric/stdout`) `stdout` exporters are now merged into a single exporter at `go.opentelemetry.io/otel/exporters/stdout`. (#956)

## [0.9.0] - 2020-07-20

Expand Down
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,17 @@ import (
"log"

"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func initTracer() {
exporter, err := stdout.NewExporter(stdout.Options{PrettyPrint: true})
if err != nil {
log.Fatal(err)
}
tp, err := sdktrace.NewProvider(sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithSyncer(exporter))
func main() {
pusher, err := stdout.InstallNewPipeline(nil, nil)
if err != nil {
log.Fatal(err)
}
global.SetTraceProvider(tp)
}
defer pusher.Stop()

func main() {
initTracer()
tracer := global.Tracer("ex.com/basic")

tracer.WithSpan(context.Background(), "foo",
Expand Down
22 changes: 11 additions & 11 deletions api/global/internal/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"go.opentelemetry.io/otel/api/global/internal"
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporters/metric/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
metrictest "go.opentelemetry.io/otel/internal/metric"
)

Expand Down Expand Up @@ -243,10 +243,10 @@ func TestDefaultSDK(t *testing.T) {
counter.Add(ctx, 1, labels1...)

in, out := io.Pipe()
pusher, err := stdout.InstallNewPipeline(stdout.Config{
Writer: out,
DoNotPrintTime: true,
})
pusher, err := stdout.InstallNewPipeline([]stdout.Option{
stdout.WithWriter(out),
stdout.WithoutTimestamps(),
}, nil)
if err != nil {
panic(err)
}
Expand All @@ -262,7 +262,7 @@ func TestDefaultSDK(t *testing.T) {
pusher.Stop()
out.Close()

require.Equal(t, `{"updates":[{"name":"test.builtin{instrumentation.name=builtin,A=B}","sum":1}]}
require.Equal(t, `[{"Name":"test.builtin{instrumentation.name=builtin,A=B}","Sum":1}]
`, <-ch)
}

Expand Down Expand Up @@ -408,10 +408,10 @@ func TestRecordBatchRealSDK(t *testing.T) {

var buf bytes.Buffer

pusher, err := stdout.InstallNewPipeline(stdout.Config{
Writer: &buf,
DoNotPrintTime: true,
})
pusher, err := stdout.InstallNewPipeline([]stdout.Option{
stdout.WithWriter(&buf),
stdout.WithoutTimestamps(),
}, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -420,6 +420,6 @@ func TestRecordBatchRealSDK(t *testing.T) {
meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
pusher.Stop()

require.Equal(t, `{"updates":[{"name":"test.counter{instrumentation.name=builtin}","sum":1}]}
require.Equal(t, `[{"Name":"test.counter{instrumentation.name=builtin}","Sum":1}]
`, buf.String())
}
44 changes: 9 additions & 35 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import (
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/api/trace"
metricstdout "go.opentelemetry.io/otel/exporters/metric/stdout"
tracestdout "go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/exporters/stdout"
)

var (
Expand All @@ -37,37 +33,15 @@ var (
anotherKey = kv.Key("ex.com/another")
)

// initTracer creates and registers trace provider instance.
func initTracer() {
var err error
exp, err := tracestdout.NewExporter(tracestdout.Options{PrettyPrint: false})
if err != nil {
log.Panicf("failed to initialize trace stdout exporter %v", err)
return
}
tp, err := sdktrace.NewProvider(sdktrace.WithSyncer(exp),
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithResource(resource.New(kv.String("rk1", "rv11"), kv.Int64("rk2", 5))))
if err != nil {
log.Panicf("failed to initialize trace provider %v", err)
}
global.SetTraceProvider(tp)
}

func initMeter() *push.Controller {
pusher, err := metricstdout.InstallNewPipeline(metricstdout.Config{
Quantiles: []float64{0.5, 0.9, 0.99},
PrettyPrint: false,
})
func main() {
pusher, err := stdout.InstallNewPipeline([]stdout.Option{
stdout.WithQuantiles([]float64{0.5, 0.9, 0.99}),
stdout.WithPrettyPrint(),
}, nil)
if err != nil {
log.Panicf("failed to initialize metric stdout exporter %v", err)
log.Fatalf("failed to initialize stdout export pipeline: %v", err)
}
return pusher
}

func main() {
defer initMeter().Stop()
initTracer()
defer pusher.Stop()

tracer := global.Tracer("ex.com/basic")
meter := global.Meter("ex.com/basic")
Expand All @@ -93,7 +67,7 @@ func main() {
valuerecorder := valuerecorderTwo.Bind(commonLabels...)
defer valuerecorder.Unbind()

err := tracer.WithSpan(ctx, "operation", func(ctx context.Context) error {
err = tracer.WithSpan(ctx, "operation", func(ctx context.Context) error {

trace.SpanFromContext(ctx).AddEvent(ctx, "Nice operation!", kv.Key("bogons").Int(100))

Expand Down
4 changes: 2 additions & 2 deletions example/grpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"log"

"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

// Init configures an OpenTelemetry exporter and trace provider
func Init() {
exporter, err := stdout.NewExporter(stdout.Options{PrettyPrint: true})
exporter, err := stdout.NewExporter(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions example/http/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import (

"go.opentelemetry.io/otel/api/correlation"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/instrumentation/httptrace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func initTracer() {
// Create stdout exporter to be able to retrieve
// the collected spans.
exporter, err := stdout.NewExporter(stdout.Options{PrettyPrint: true})
exporter, err := stdout.NewExporter(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions example/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/standard"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/instrumentation/httptrace"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
Expand All @@ -32,7 +32,7 @@ import (
func initTracer() {
// Create stdout exporter to be able to retrieve
// the collected spans.
exporter, err := stdout.NewExporter(stdout.Options{PrettyPrint: true})
exporter, err := stdout.NewExporter(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions example/namedtracer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/example/namedtracer/foo"
"go.opentelemetry.io/otel/exporters/trace/stdout"
"go.opentelemetry.io/otel/exporters/stdout"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

Expand All @@ -39,7 +39,7 @@ var tp *sdktrace.Provider
// initTracer creates and registers trace provider instance.
func initTracer() {
var err error
exp, err := stdout.NewExporter(stdout.Options{})
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
if err != nil {
log.Panicf("failed to initialize stdout exporter %v\n", err)
return
Expand Down
18 changes: 18 additions & 0 deletions exporters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Exporters

Included in this directory are exporters that export both metric and trace telemetry.

- [stdout](./stdout): Writes telemetry to a specified local output as structured JSON.
- [otlp](./otlp): Sends telemetry to an OpenTelemetry collector as OTLP.

Additionally, there are [metric](./metric) and [trace](./trace) only exporters.

## Metric Telemetry Only

- [prometheus](./metric/prometheus): Exposes metric telemetry as Prometheus metrics.
- [test](./metric/test): A development tool when testing the telemetry pipeline.

## Trace Telemetry Only

- [jaeger](./trace/jaeger): Sends properly transformed trace telemetry to a Jaeger endpoint.
- [zipkin](./trace/zipkin): Sends properly transformed trace telemetry to a Zipkin endpoint.
60 changes: 0 additions & 60 deletions exporters/metric/stdout/example_test.go

This file was deleted.

Loading

0 comments on commit 452256c

Please sign in to comment.