diff --git a/.chloggen/rename-severy-numer-and-state-string-output.yaml b/.chloggen/rename-severy-numer-and-state-string-output.yaml new file mode 100644 index 00000000000..aa1a1dccbe5 --- /dev/null +++ b/.chloggen/rename-severy-numer-and-state-string-output.yaml @@ -0,0 +1,8 @@ +change_type: breaking +component: pdata +note: "Change output of String() method of the following enum types to more a concise form:" +subtext: | + - plog.SeverityNumber + - ptrace.SpanKind + - ptrace.StatusCode +issues: [6251] diff --git a/exporter/loggingexporter/internal/otlptext/testdata/logs/embedded_maps.out b/exporter/loggingexporter/internal/otlptext/testdata/logs/embedded_maps.out index 2dd79b12735..0da7f284706 100644 --- a/exporter/loggingexporter/internal/otlptext/testdata/logs/embedded_maps.out +++ b/exporter/loggingexporter/internal/otlptext/testdata/logs/embedded_maps.out @@ -7,7 +7,7 @@ LogRecord #0 ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: INFO -SeverityNumber: SEVERITY_NUMBER_INFO(9) +SeverityNumber: Info(9) Body: Map({"key1":"val1","key2":{"key21":"val21","key22":"val22"}}) Attributes: -> key1: Map({"key11":"val11","key12":"val12","key13":{"key131":"val131"}}) diff --git a/exporter/loggingexporter/internal/otlptext/testdata/logs/one_record.out b/exporter/loggingexporter/internal/otlptext/testdata/logs/one_record.out index 36d724e5265..f5548208a15 100644 --- a/exporter/loggingexporter/internal/otlptext/testdata/logs/one_record.out +++ b/exporter/loggingexporter/internal/otlptext/testdata/logs/one_record.out @@ -9,7 +9,7 @@ LogRecord #0 ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info -SeverityNumber: SEVERITY_NUMBER_INFO(9) +SeverityNumber: Info(9) Body: Str(This is a log message) Attributes: -> app: Str(server) diff --git a/exporter/loggingexporter/internal/otlptext/testdata/logs/two_records.out b/exporter/loggingexporter/internal/otlptext/testdata/logs/two_records.out index 516726fd0fd..6d1eaf7b575 100644 --- a/exporter/loggingexporter/internal/otlptext/testdata/logs/two_records.out +++ b/exporter/loggingexporter/internal/otlptext/testdata/logs/two_records.out @@ -9,7 +9,7 @@ LogRecord #0 ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info -SeverityNumber: SEVERITY_NUMBER_INFO(9) +SeverityNumber: Info(9) Body: Str(This is a log message) Attributes: -> app: Str(server) @@ -21,7 +21,7 @@ LogRecord #1 ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info -SeverityNumber: SEVERITY_NUMBER_INFO(9) +SeverityNumber: Info(9) Body: Str(something happened) Attributes: -> customer: Str(acme) diff --git a/pdata/plog/logs.go b/pdata/plog/logs.go index dce60d56ee6..7557ddd729c 100644 --- a/pdata/plog/logs.go +++ b/pdata/plog/logs.go @@ -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 SeverityNumberUnspecified: + return "Unspecified" + 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 "" +} diff --git a/pdata/plog/logs_test.go b/pdata/plog/logs_test.go index 40d1fb69375..aa1db8ae210 100644 --- a/pdata/plog/logs_test.go +++ b/pdata/plog/logs_test.go @@ -133,3 +133,32 @@ func TestLogsCopyTo(t *testing.T) { logs.CopyTo(logsCopy) assert.EqualValues(t, logs, logsCopy) } + +func TestSeverityNumberString(t *testing.T) { + assert.EqualValues(t, "Unspecified", SeverityNumberUnspecified.String()) + assert.EqualValues(t, "Trace", SeverityNumberTrace.String()) + assert.EqualValues(t, "Trace2", SeverityNumberTrace2.String()) + assert.EqualValues(t, "Trace3", SeverityNumberTrace3.String()) + assert.EqualValues(t, "Trace4", SeverityNumberTrace4.String()) + assert.EqualValues(t, "Debug", SeverityNumberDebug.String()) + assert.EqualValues(t, "Debug2", SeverityNumberDebug2.String()) + assert.EqualValues(t, "Debug3", SeverityNumberDebug3.String()) + assert.EqualValues(t, "Debug4", SeverityNumberDebug4.String()) + assert.EqualValues(t, "Info", SeverityNumberInfo.String()) + assert.EqualValues(t, "Info2", SeverityNumberInfo2.String()) + assert.EqualValues(t, "Info3", SeverityNumberInfo3.String()) + assert.EqualValues(t, "Info4", SeverityNumberInfo4.String()) + assert.EqualValues(t, "Warn", SeverityNumberWarn.String()) + assert.EqualValues(t, "Warn2", SeverityNumberWarn2.String()) + assert.EqualValues(t, "Warn3", SeverityNumberWarn3.String()) + assert.EqualValues(t, "Warn4", SeverityNumberWarn4.String()) + assert.EqualValues(t, "Error", SeverityNumberError.String()) + assert.EqualValues(t, "Error2", SeverityNumberError2.String()) + assert.EqualValues(t, "Error3", SeverityNumberError3.String()) + assert.EqualValues(t, "Error4", SeverityNumberError4.String()) + assert.EqualValues(t, "Fatal", SeverityNumberFatal.String()) + assert.EqualValues(t, "Fatal2", SeverityNumberFatal2.String()) + assert.EqualValues(t, "Fatal3", SeverityNumberFatal3.String()) + assert.EqualValues(t, "Fatal4", SeverityNumberFatal4.String()) + assert.EqualValues(t, "", SeverityNumber(100).String()) +} diff --git a/pdata/ptrace/traces.go b/pdata/ptrace/traces.go index 29782d60eee..0af4b9e478c 100644 --- a/pdata/ptrace/traces.go +++ b/pdata/ptrace/traces.go @@ -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) @@ -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 @@ -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 "" +} diff --git a/pdata/ptrace/traces_test.go b/pdata/ptrace/traces_test.go index 9cfbcec4e2f..7bd460407b6 100644 --- a/pdata/ptrace/traces_test.go +++ b/pdata/ptrace/traces_test.go @@ -134,3 +134,20 @@ func TestTracesCopyTo(t *testing.T) { traces.CopyTo(tracesCopy) assert.EqualValues(t, traces, tracesCopy) } + +func TestSpanKindString(t *testing.T) { + assert.EqualValues(t, "Unspecified", SpanKindUnspecified.String()) + assert.EqualValues(t, "Internal", SpanKindInternal.String()) + assert.EqualValues(t, "Server", SpanKindServer.String()) + assert.EqualValues(t, "Client", SpanKindClient.String()) + assert.EqualValues(t, "Producer", SpanKindProducer.String()) + assert.EqualValues(t, "Consumer", SpanKindConsumer.String()) + assert.EqualValues(t, "", SpanKind(100).String()) +} + +func TestStatusCodeString(t *testing.T) { + assert.EqualValues(t, "Unset", StatusCodeUnset.String()) + assert.EqualValues(t, "Ok", StatusCodeOk.String()) + assert.EqualValues(t, "Error", StatusCodeError.String()) + assert.EqualValues(t, "", StatusCode(100).String()) +}