Skip to content

Commit

Permalink
adds switch case to SamplerType
Browse files Browse the repository at this point in the history
Signed-off-by: afzal442 <[email protected]>
  • Loading branch information
afzal442 committed Aug 22, 2023
1 parent 1481731 commit 78f55cd
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions model/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
SamplerTypeLowerBound
SamplerTypeRateLimiting
SamplerTypeConst

// SampledFlag is the bit set in Flags in order to define a span as a sampled span
SampledFlag = Flags(1)
// DebugFlag is the bit set in Flags in order to define a span as a debug span
Expand All @@ -56,16 +57,21 @@ var toSpanKind = map[string]trace.SpanKind{
"internal": trace.SpanKindInternal,
}

var toSamplerType = map[SamplerType]string{
SamplerTypeUnrecognized: "unrecognized",
SamplerTypeProbabilistic: "probabilistic",
SamplerTypeLowerBound: "lowerbound",
SamplerTypeRateLimiting: "ratelimiting",
SamplerTypeConst: "const",
}

func (s SamplerType) String() string {
return toSamplerType[s]
switch s {
case SamplerTypeUnrecognized:
return "unrecognized"

Check warning on line 63 in model/span.go

View check run for this annotation

Codecov / codecov/patch

model/span.go#L62-L63

Added lines #L62 - L63 were not covered by tests
case SamplerTypeProbabilistic:
return "probabilistic"
case SamplerTypeLowerBound:
return "lowerbound"
case SamplerTypeRateLimiting:
return "ratelimiting"
case SamplerTypeConst:
return "const"
default:
return ""

Check warning on line 73 in model/span.go

View check run for this annotation

Codecov / codecov/patch

model/span.go#L72-L73

Added lines #L72 - L73 were not covered by tests
}
}

// Hash implements Hash from Hashable.
Expand Down Expand Up @@ -98,14 +104,17 @@ func (s *Span) GetSpanKind() (spanKind trace.SpanKind, found bool) {
func (s *Span) GetSamplerType() SamplerType {
// There's no corresponding opentelemetry tag label corresponding to sampler.type
if tag, ok := KeyValues(s.Tags).FindByKey(keySamplerType); ok {
if tag.VStr == "" {
return SamplerTypeUnrecognized
} else if tag.VStr == toSamplerType[SamplerTypeProbabilistic] {
switch tag.VStr {
case SamplerTypeProbabilistic.String():
return SamplerTypeProbabilistic
} else if tag.VStr == toSamplerType[SamplerTypeRateLimiting] {
case SamplerTypeRateLimiting.String():
return SamplerTypeRateLimiting
} else {
case SamplerTypeLowerBound.String():
return SamplerTypeLowerBound
case SamplerTypeConst.String():
return SamplerTypeConst

Check warning on line 115 in model/span.go

View check run for this annotation

Codecov / codecov/patch

model/span.go#L114-L115

Added lines #L114 - L115 were not covered by tests
default:
return SamplerTypeUnrecognized
}
}
return SamplerTypeUnrecognized
Expand Down

0 comments on commit 78f55cd

Please sign in to comment.