Skip to content

Commit

Permalink
[pdata] Update values returned by all String methods of enum types
Browse files Browse the repository at this point in the history
Update values returned by all String methods of enum types to a consistent short form representing the enum identifier
  • Loading branch information
dmitryax committed Oct 14, 2022
1 parent f4556f5 commit 2d9ad3c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
56 changes: 55 additions & 1 deletion pdata/plog/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,58 @@ const (
)

// String returns the string representation of the SeverityNumber.
func (sn SeverityNumber) String() string { return otlplogs.SeverityNumber(sn).String() }
func (sn SeverityNumber) String() string {
switch sn {
case SeverityNumberUndefined:
return "Undefined"
case SeverityNumberTrace:
return "Trace"
case SeverityNumberTrace2:
return "Trace2"
case SeverityNumberTrace3:
return "Trace3"
case SeverityNumberTrace4:
return "Trace4"
case SeverityNumberDebug:
return "Debug"
case SeverityNumberDebug2:
return "Debug2"
case SeverityNumberDebug3:
return "Debug3"
case SeverityNumberDebug4:
return "Debug4"
case SeverityNumberInfo:
return "Info"
case SeverityNumberInfo2:
return "Info2"
case SeverityNumberInfo3:
return "Info3"
case SeverityNumberInfo4:
return "Info4"
case SeverityNumberWarn:
return "Warn"
case SeverityNumberWarn2:
return "Warn2"
case SeverityNumberWarn3:
return "Warn3"
case SeverityNumberWarn4:
return "Warn4"
case SeverityNumberError:
return "Error"
case SeverityNumberError2:
return "Error2"
case SeverityNumberError3:
return "Error3"
case SeverityNumberError4:
return "Error4"
case SeverityNumberFatal:
return "Fatal"
case SeverityNumberFatal2:
return "Fatal2"
case SeverityNumberFatal3:
return "Fatal3"
case SeverityNumberFatal4:
return "Fatal4"
}
return ""
}
34 changes: 30 additions & 4 deletions pdata/ptrace/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (ms Traces) ResourceSpans() ResourceSpansSlice {
// in addition to a parent/child relationship.
type SpanKind int32

// String returns the string representation of the SpanKind.
func (sk SpanKind) String() string { return otlptrace.Span_SpanKind(sk).String() }

const (
// SpanKindUnspecified represents that the SpanKind is unspecified, it MUST NOT be used.
SpanKindUnspecified = SpanKind(otlptrace.Span_SPAN_KIND_UNSPECIFIED)
Expand All @@ -98,6 +95,25 @@ const (
SpanKindConsumer = SpanKind(otlptrace.Span_SPAN_KIND_CONSUMER)
)

// String returns the string representation of the SpanKind.
func (sk SpanKind) String() string {
switch sk {
case SpanKindUnspecified:
return "Unspecified"
case SpanKindInternal:
return "Internal"
case SpanKindServer:
return "Server"
case SpanKindClient:
return "Client"
case SpanKindProducer:
return "Producer"
case SpanKindConsumer:
return "Consumer"
}
return ""
}

// StatusCode mirrors the codes defined at
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status
type StatusCode int32
Expand All @@ -109,4 +125,14 @@ const (
)

// String returns the string representation of the StatusCode.
func (sc StatusCode) String() string { return otlptrace.Status_StatusCode(sc).String() }
func (sc StatusCode) String() string {
switch sc {
case StatusCodeUnset:
return "Unset"
case StatusCodeOk:
return "Ok"
case StatusCodeError:
return "Error"
}
return ""
}

0 comments on commit 2d9ad3c

Please sign in to comment.