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

Deprecate plugins directory and sql.go file #215

Merged
merged 17 commits into from
Apr 1, 2020
Merged
Changes from 1 commit
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
Next Next commit
DummySegment and DummySubSegment creation
  • Loading branch information
bhautikpip committed Feb 13, 2020
commit 4edb4b5eff7ade6369742346cf8e7111df4fefb6
48 changes: 48 additions & 0 deletions xray/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ func BeginFacadeSegment(ctx context.Context, name string, h *header.Header) (con
return context.WithValue(ctx, ContextKey, seg), seg
}

// Begin DummySegment creates a segment in the case of no sampling to reduce memory footprint
func BeginDummySegment(ctx context.Context, name string) (context.Context, *Segment) {
dummySeg := &Segment{parent:nil}
dummySeg.ParentSegment = dummySeg
logger.Debugf("Beginning segment named %s", name)

cfg := GetRecorder(ctx)
dummySeg.assignConfiguration(cfg)

dummySeg.Lock()
defer dummySeg.Unlock()

dummySeg.Name = name
dummySeg.TraceID = "dummy segment"
dummySeg.Sampled = false

return context.WithValue(ctx, ContextKey, dummySeg), dummySeg
}

// BeginSegment creates a Segment for a given name and context.
func BeginSegment(ctx context.Context, name string) (context.Context, *Segment) {
seg := basicSegment(name, nil)
Expand Down Expand Up @@ -158,6 +177,35 @@ func (seg *Segment) assignConfiguration(cfg *Config) {
seg.Unlock()
}

// Begin DummySubSegment creates a in the case of no sampling to reduce memory footprint
func BeginDummySubSegment(ctx context.Context, name string) (context.Context, *Segment) {
var parent *Segment

parent = GetSegment(ctx)
if parent == nil {
cfg := GetRecorder(ctx)
failedMessage := fmt.Sprintf("failed to begin subsegment named '%v': segment cannot be found.", name)
if cfg != nil && cfg.ContextMissingStrategy != nil {
cfg.ContextMissingStrategy.ContextMissing(failedMessage)
} else {
globalCfg.ContextMissingStrategy().ContextMissing(failedMessage)
}
return ctx, nil
}

dummySubSeg := &Segment{parent: parent}
logger.Debugf("Beginning subsegment named %s", name)

dummySubSeg.Lock()
defer dummySubSeg.Unlock()

dummySubSeg.ParentSegment = parent.ParentSegment
dummySubSeg.Name = name
dummySubSeg.TraceID = "dummy subsegment"

return context.WithValue(ctx, ContextKey, dummySubSeg), dummySubSeg
}

// BeginSubsegment creates a subsegment for a given name and context.
func BeginSubsegment(ctx context.Context, name string) (context.Context, *Segment) {
if len(name) > 200 {
Expand Down