Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Wait for on export #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
20 changes: 12 additions & 8 deletions xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ func buildConfig(opts ...Option) (config, error) {
if c.output == nil {
c.output = os.Stderr
}
if c.onExport == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't removing this mean that the later call to onExport will panic?

c.onExport = func(export OnExport) {}
}
if c.interval <= 0 {
c.interval = defaultInterval
}
Expand Down Expand Up @@ -316,17 +313,21 @@ func (e *Exporter) makeInput(spans []*trace.SpanData) (xray.PutTraceSegmentsInpu
}

func (e *Exporter) publish(spans []*trace.SpanData) {
defer e.wg.Done()

var (
input, traceIDs = e.makeInput(spans)
)

for attempt := 0; attempt < 3; attempt++ {
_, err := e.api.PutTraceSegments(&input)
if err == nil {
for _, traceID := range traceIDs {
go e.onExport(OnExport{TraceID: traceID})
if e.onExport != nil {
e.wg.Add(len(traceIDs))
for _, traceID := range traceIDs {
go func() {
defer e.wg.Done()
e.onExport(OnExport{TraceID: traceID})
}()
}
}
return
}
Expand All @@ -350,7 +351,10 @@ func (e *Exporter) flush() {
e.offset = 0

e.wg.Add(1)
go e.publish(spans)
go func() {
defer e.wg.Done()
e.publish(spans)
}()
}

func (e *Exporter) publishAtInterval(interval time.Duration) {
Expand Down