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

[pdata] Inconsistent output of enum types String() methods #6251

Closed
dmitryax opened this issue Oct 7, 2022 · 6 comments
Closed

[pdata] Inconsistent output of enum types String() methods #6251

dmitryax opened this issue Oct 7, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@dmitryax
Copy link
Member

dmitryax commented Oct 7, 2022

The pdata module has a few enum type definitions. Some of them defined in proto (2), while others are defined in pdata only (based on proto oneof message fields names) (1).

1. For enum types that are not defined in proto, we use a short version of the enum identifier for the output of String() method in:

  • pmetric.MetricType
  • pmetric.NumberDataPointValueType
  • pmetric.ExemplarValueType
  • pmetric.ValueType

e.g.:

MetricTypeNone -> "None"
MetricTypeGauge -> "Gauge"
MetricTypeSum -> "Sum"
MetricTypeHistogram -> "Histogram"
MetricTypeExponentialHistogram -> "ExponentialHistogram"
MetricTypeSummary -> "Summary"

2. For enums that are defined in proto, we have an inconsistent behavior.

One of the proto-defined enums uses the same approach as in (1):

  • pmetric.MetricAggregationTemporality:
MetricAggregationTemporalityUnspecified -> "Unspecified"
MetricAggregationTemporalityDelta -> "Delta"
MetricAggregationTemporalityCumulative -> "Cumulative"

While other enums (2) reuse the string value defined in proto which is always a full uppercased name:

  • plog.SeverityNumber
  • ptrace.SpanKind
  • ptrace.StatusCode, e.g.:
StatusCodeUnset -> "STATUS_CODE_UNSET"
StatusCodeOk -> "STATUS_CODE_OK"
StatusCodeError -> "STATUS_CODE_ERROR"

We should bring all of the values returned by enum String() method to a consistent form.

There are seem to be several options how to achieve that:

A. Ignore string values defined in proto and use the short terms everywhere. Requires changes in plog.SeverityNumber.String(), ptrace.SpanKind.String(), and ptrace.StatusCode.String()

B. Use long version written in uppercase with underscores averywhere. Requires changes in pmetric.MetricType.String(), pmetric.NumberDataPointValueType.Sgtring, pmetric.ExemplarValueType.String(), and pmetric.ValueType.String()

C. Use values defined in proto for enums (2), but keep the short version for enums (1). Requires changes in pmetric.MetricAggregationTemporality.String() only

@dmitryax dmitryax added the bug Something isn't working label Oct 7, 2022
@dmitryax dmitryax changed the title [pdata] Inconsistent output of enum String types [pdata] Inconsistent output of enum types String() methods Oct 7, 2022
@bogdandrutu
Copy link
Member

I do believe that we can have different behavior between proto defined values and the types. Does not mean we should, but it is acceptable if we decide that.

@dmitryax dmitryax self-assigned this Oct 7, 2022
@dmitryax
Copy link
Member Author

dmitryax commented Oct 14, 2022

I do believe that we can have different behavior between proto defined values and the types. Does not mean we should, but it is acceptable if we decide that.

@bogdandrutu I also like this approach, but it'll be different from what json marshaler produces. So user will not be able to compare the json values with pdata unless we provide additional methods like Code returning the proto strings.

I think I'm more inclined towards sticking with what proto provides now for the category 2. Not sure it worth patching json marshaler either.

WDYT?

@bogdandrutu
Copy link
Member

bogdandrutu commented Oct 18, 2022

@bogdandrutu I also like this approach, but it'll be different from what json marshaler produces. So user will not be able to compare the json values with pdata unless we provide additional methods like Code returning the proto strings.

JSON marshaler per the specs MUST produce ints for the enums, see open-telemetry/opentelemetry-specification#2758

@dmitryax
Copy link
Member Author

dmitryax commented Nov 1, 2022

@bogdandrutu I inspected all the components that currently use plog.SeverityNumber.String(), ptrace.SpanKind.String(), or ptrace.StatusCode.String() and got the following list separated by categories where the value is being used as:

Output payload:

  • humio exporter
  • influxdb exporter
  • spanmetrics processor
  • azuredataexplore exporter
  • azuremonitor exporter
  • clickhouse exporter
  • instana exporter
  • splunkhec exporter
  • zipkin v2 exporter (to set "otel.status_code" - should be fixed, use int instead)
  • elasticsearch exporter

Input payload:

  • influxdb receiver
  • azureblob receiver

Config options:

  • span processor
  • loki exporter

Given that we have a pretty big list, we need to be very careful if we go this direction. Some of the components potentially can use the updated string, but they have to go through some graceful transition process. In the meantime we would have to update all of them to keep existing behavior similar to how it's done in open-telemetry/opentelemetry-collector-contrib#16019.

Another option would be to expose another method that returns a string representing proto enum constant name, so clients can keep using it instead of String without introducing any breaking changes. WDYT?

@bogdandrutu
Copy link
Member

Another option would be to expose another method that returns a string representing proto enum constant name, so clients can keep using it instead of String without introducing any breaking changes. WDYT?

The problem is that current protocol may not guarantee stability on these strings, so I don't want give this stability from this repo if proto does not give that.

@dmitryax
Copy link
Member Author

dmitryax commented Nov 2, 2022

Sounds good. I submitted a PR in contrib that uses a replicated version of existing methods for now open-telemetry/opentelemetry-collector-contrib#16021

mx-psi pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this issue Aug 28, 2024
#34799)

**Description:**

Trace `SpanKind` and `StatusCode` are exporting [old enum
values](https:/open-telemetry/opentelemetry-collector-contrib/blob/04b3b9898b242c0b3b707bc043c025eb9f6f73ba/internal/coreinternal/traceutil/traceutil.go#L13-L47).
This change will make these fields consistent with the specification.

I have marked this as a breaking change since it may affect queries that
filter by these strings. There should be no change to exporter
deployments, only to the read queries.

See above/below links for more information as well as a sample of the
old vs new values.

Example: `STATUS_CODE_ERROR` -> `Error`

**Link to tracking Issue:** 

- open-telemetry/opentelemetry-collector#6250
- open-telemetry/opentelemetry-collector#6251

**Testing:**

- Updated integration tests
f7o pushed a commit to f7o/opentelemetry-collector-contrib that referenced this issue Sep 12, 2024
open-telemetry#34799)

**Description:**

Trace `SpanKind` and `StatusCode` are exporting [old enum
values](https:/open-telemetry/opentelemetry-collector-contrib/blob/04b3b9898b242c0b3b707bc043c025eb9f6f73ba/internal/coreinternal/traceutil/traceutil.go#L13-L47).
This change will make these fields consistent with the specification.

I have marked this as a breaking change since it may affect queries that
filter by these strings. There should be no change to exporter
deployments, only to the read queries.

See above/below links for more information as well as a sample of the
old vs new values.

Example: `STATUS_CODE_ERROR` -> `Error`

**Link to tracking Issue:** 

- open-telemetry/opentelemetry-collector#6250
- open-telemetry/opentelemetry-collector#6251

**Testing:**

- Updated integration tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants