Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trace] add option.Writer for stdout output #404

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion exporter/trace/stdout/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (

// Options are the options to be used when initializing a stdout export.
type Options struct {
// File is the destination. If not set, os.Stdout is used.
File io.Writer
clsung marked this conversation as resolved.
Show resolved Hide resolved

// PrettyPrint will pretty the json representation of the span,
// making it print "pretty". Default is false.
PrettyPrint bool
Expand All @@ -37,9 +40,12 @@ type Exporter struct {
}

func NewExporter(o Options) (*Exporter, error) {
if o.File == nil {
o.File = os.Stdout
}
return &Exporter{
pretty: o.PrettyPrint,
outputWriter: os.Stdout,
outputWriter: o.File,
}, nil
}

Expand Down
8 changes: 3 additions & 5 deletions exporter/trace/stdout/stdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ import (
)

func TestExporter_ExportSpan(t *testing.T) {
ex, err := NewExporter(Options{})
// write to buffer for testing
var b bytes.Buffer
ex, err := NewExporter(Options{File: &b})
if err != nil {
t.Errorf("Error constructing stdout exporter %s", err)
}

// override output writer for testing
var b bytes.Buffer
ex.outputWriter = &b

// setup test span
now := time.Now()
traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10")
Expand Down