-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transaction, Span, and Error are no longer pooled. Instead, new *Data types are introduced which are pooled, and those are embedded within their related top-level object types. We add a read-write mutex to the Transaction and Span types to guard access to those such that a concurrent StartSpan and Transaction.End will not panic. This change introduces an additional allocation for each of StartTransaction, StartSpan, and NewError. The time overhead (measured in nanoseconds) is not enough to warrant living with the lack of safety. It is now safe to call End() multiple times, and to call StartSpan with an ended transaction or parent span. When StartSpan is called with an ended transaction, a dropped span will be created.
- Loading branch information
Showing
12 changed files
with
425 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package apm_test | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"go.elastic.co/apm" | ||
"go.elastic.co/apm/transport/transporttest" | ||
) | ||
|
||
func TestContextStartSpanTransactionEnded(t *testing.T) { | ||
tracer, err := apm.NewTracer("tracer_testing", "") | ||
assert.NoError(t, err) | ||
defer tracer.Close() | ||
tracer.Transport = transporttest.Discard | ||
|
||
var wg sync.WaitGroup | ||
for i := 0; i < 100; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for i := 0; i < 1000; i++ { | ||
tx := tracer.StartTransaction("name", "type") | ||
ctx := apm.ContextWithTransaction(context.Background(), tx) | ||
tx.End() | ||
apm.CaptureError(ctx, errors.New("boom")).Send() | ||
span, _ := apm.StartSpan(ctx, "name", "type") | ||
assert.True(t, span.Dropped()) | ||
span.End() | ||
} | ||
}() | ||
} | ||
tracer.Flush(nil) | ||
wg.Wait() | ||
} | ||
|
||
func TestContextStartSpanSpanEnded(t *testing.T) { | ||
tracer, err := apm.NewTracer("tracer_testing", "") | ||
assert.NoError(t, err) | ||
defer tracer.Close() | ||
tracer.Transport = transporttest.Discard | ||
|
||
var wg sync.WaitGroup | ||
for i := 0; i < 100; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for i := 0; i < 1000; i++ { | ||
tx := tracer.StartTransaction("name", "type") | ||
ctx := apm.ContextWithTransaction(context.Background(), tx) | ||
span1, ctx := apm.StartSpan(ctx, "name", "type") | ||
span1.End() | ||
apm.CaptureError(ctx, errors.New("boom")).Send() | ||
span2, _ := apm.StartSpan(ctx, "name", "type") | ||
assert.True(t, span2.Dropped()) | ||
span2.End() | ||
tx.End() | ||
} | ||
}() | ||
} | ||
tracer.Flush(nil) | ||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.