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

Setting Default ErrorStrategy to Log #382

Merged
merged 2 commits into from
Oct 25, 2022
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
21 changes: 5 additions & 16 deletions xray/capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,9 @@ func TestPanicCapture(t *testing.T) {
}

func TestNoSegmentCapture(t *testing.T) {
var err error
func() {
defer func() {
if p := recover(); p != nil {
err = errors.New(p.(string))
}
}()
_ = Capture(context.Background(), "PanicService", func(context.Context) error {
panic("MyPanic")
})
}()

assert.NotNil(t, err)
assert.Equal(t, "failed to begin subsegment named 'PanicService': segment cannot be found.", err.Error())
ctx, _ := NewTestDaemon()
_, seg := BeginSubsegment(ctx, "Name")
seg.Close(nil)
}

func TestCaptureAsync(t *testing.T) {
Expand Down Expand Up @@ -162,8 +151,8 @@ func TestCaptureAsync(t *testing.T) {

// Benchmarks
func BenchmarkCapture(b *testing.B) {
ctx, seg:= BeginSegment(context.Background(), "TestCaptureSeg")
for i:=0; i<b.N; i++ {
ctx, seg := BeginSegment(context.Background(), "TestCaptureSeg")
for i := 0; i < b.N; i++ {
Capture(ctx, "TestCaptureSubSeg", func(ctx context.Context) error {
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion xray/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newGlobalConfig() *globalConfig {
ret.contextMissingStrategy = cm
}
} else {
cm := ctxmissing.NewDefaultRuntimeErrorStrategy()
cm := ctxmissing.NewDefaultLogErrorStrategy()
ret.contextMissingStrategy = cm
}

Expand Down
14 changes: 7 additions & 7 deletions xray/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestDefaultConfigureParameters(t *testing.T) {
daemonAddr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 2000}
efs, _ := exception.NewDefaultFormattingStrategy()
sms, _ := NewDefaultStreamingStrategy()
cms := ctxmissing.NewDefaultRuntimeErrorStrategy()
cms := ctxmissing.NewDefaultLogErrorStrategy()

assert.Equal(t, daemonAddr, globalCfg.daemonAddr)
assert.Equal(t, efs, globalCfg.exceptionFormattingStrategy)
Expand Down Expand Up @@ -271,13 +271,13 @@ func BenchmarkConfigure(b *testing.B) {
cms := &TestContextMissingStrategy{}

configure := Config{
ServiceVersion: serviceVersion,
SamplingStrategy: ss,
ServiceVersion: serviceVersion,
SamplingStrategy: ss,
ExceptionFormattingStrategy: efs,
StreamingStrategy: sms,
ContextMissingStrategy: cms,
LogLevel: logLevel,
LogFormat: logFormat,
StreamingStrategy: sms,
ContextMissingStrategy: cms,
LogLevel: logLevel,
LogFormat: logFormat,
}
for i := 0; i < b.N; i++ {
Configure(configure)
Expand Down
5 changes: 5 additions & 0 deletions xray/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ func (seg *Segment) Close(err error) {
return
}

if seg == nil {
logger.Debugf("No input subsegment to end. No-op")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we can delegate this situation to be handled by the ContextMissingStrategy?
This way it can be just a log or a runtime exception if a user choses to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked with Will in regards to its implementation in Java.

"I think that’s the expected behavior for this method. If a customer explicitly passes in the subsegment to be closed, then we shouldn’t throw context missing errors because we’re not interacting with the context, we just use the subsegment provided by the customer as noted in javadocs."

return
}

seg.Lock()
if seg.parent != nil {
logger.Debugf("Closing subsegment named %s", seg.Name)
Expand Down