Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type (
)

var (
version = "0.4.2-pre.1"
version = "0.4.2"

testingModeFrequency = time.Second
nonTestingModeFrequency = time.Minute
Expand Down
6 changes: 5 additions & 1 deletion agent/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{})
Expand Down
29 changes: 29 additions & 0 deletions init_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}()
}
}
10 changes: 8 additions & 2 deletions tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &currentError)
s.callFinishPanic(&currentError)
}
}

Expand Down Expand Up @@ -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, &currentError)
s.callFinishPanic(&currentError)
}
}

Expand Down