From fd82e23224f4b7e8fa72bcd0723151dcee04d987 Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Tue, 16 Jun 2020 16:23:34 +0200 Subject: [PATCH 1/3] adds locking over the tag map on error reporting and map copy in the reporter --- agent/recorder.go | 6 +++++- tracer/span.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/agent/recorder.go b/agent/recorder.go index 600e0e3a..e54107ca 100644 --- a/agent/recorder.go +++ b/agent/recorder.go @@ -329,6 +329,10 @@ func (r *SpanRecorder) getPayloadComponents(span tracer.RawSpan) (PayloadSpan, [ } traceId := tracer.UUIDToString(span.Context.TraceID) spanId := fmt.Sprintf("%x", span.Context.SpanID) + tags := opentracing.Tags{} + for key, value := range span.Tags { + tags[key] = value + } payloadSpan := PayloadSpan{ "context": map[string]interface{}{ "trace_id": traceId, @@ -339,7 +343,7 @@ func (r *SpanRecorder) getPayloadComponents(span tracer.RawSpan) (PayloadSpan, [ "operation": span.Operation, "start": r.applyNTPOffset(span.Start).Format(time.RFC3339Nano), "duration": span.Duration.Nanoseconds(), - "tags": span.Tags, + "tags": tags, } for _, event := range span.Logs { var fields = make(map[string]interface{}) diff --git a/tracer/span.go b/tracer/span.go index 63c1379b..1b231af6 100644 --- a/tracer/span.go +++ b/tracer/span.go @@ -210,7 +210,7 @@ func (s *spanImpl) Finish() { if s.tracer != nil && s.tracer.options.OnSpanFinishPanic != nil && s.raw.ParentSpanID != 0 { if r := recover(); r != nil { currentError = errors.Wrap(r, 1) - s.tracer.options.OnSpanFinishPanic(&s.raw, ¤tError) + s.callFinishPanic(¤tError) } } @@ -238,12 +238,18 @@ func rotateLogBuffer(buf []opentracing.LogRecord, pos int) { } } +func (s *spanImpl) callFinishPanic(err **errors.Error) { + s.Lock() + defer s.Unlock() + s.tracer.options.OnSpanFinishPanic(&s.raw, err) +} + func (s *spanImpl) FinishWithOptions(opts opentracing.FinishOptions) { var currentError *errors.Error if s.tracer != nil && s.tracer.options.OnSpanFinishPanic != nil && s.raw.ParentSpanID != 0 { if r := recover(); r != nil { currentError = errors.Wrap(r, 1) - s.tracer.options.OnSpanFinishPanic(&s.raw, ¤tError) + s.callFinishPanic(¤tError) } } From cc98e0b9fdc01f7883a887fbbc28045634731eba Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Wed, 17 Jun 2020 12:35:23 +0200 Subject: [PATCH 2/3] goroutine race test --- init_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 init_test.go diff --git a/init_test.go b/init_test.go new file mode 100644 index 00000000..f9c97063 --- /dev/null +++ b/init_test.go @@ -0,0 +1,29 @@ +package scopeagent_test + +import ( + "fmt" + "os" + "testing" + + "github.com/opentracing/opentracing-go" + + "go.undefinedlabs.com/scopeagent" + _ "go.undefinedlabs.com/scopeagent/autoinstrument" +) + +func TestMain(m *testing.M) { + os.Exit(m.Run()) +} + +func TestFromGoroutineRace(t *testing.T) { + ctx := scopeagent.GetContextFromTest(t) + span := opentracing.SpanFromContext(ctx) + + for x := 0; x<10;x++ { + go func() { + for i := 0; i < 100; i++ { + span.SetTag(fmt.Sprintf("Key%v", i), i) + } + }() + } +} From 3f45b67cf0fcc8a69aca2aae42ed3ef8dfb97be2 Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Wed, 17 Jun 2020 13:11:43 +0200 Subject: [PATCH 3/3] bump to 0.4.2 --- agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index 922c8b05..b33c3a03 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -64,7 +64,7 @@ type ( ) var ( - version = "0.4.2-pre.1" + version = "0.4.2" testingModeFrequency = time.Second nonTestingModeFrequency = time.Minute