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

Log an error for empty view criteria #4149

Closed
MrAlias opened this issue May 30, 2023 · 6 comments · Fixed by #4307
Closed

Log an error for empty view criteria #4149

MrAlias opened this issue May 30, 2023 · 6 comments · Fixed by #4307
Assignees
Labels
area:metrics Part of OpenTelemetry Metrics pkg:SDK Related to an SDK package

Comments

@MrAlias
Copy link
Contributor

MrAlias commented May 30, 2023

The specification recommends:

  • If no criteria is provided, the SDK SHOULD treat it as an error. It is recommended that the SDK implementations fail fast. Please refer to Error handling in OpenTelemetry for the general guidance.

This is not treated as an error:

if criteria.empty() {
return emptyView
}

An error should be logged to match the other existing error already logged by NewView:

global.Error(
err, "not using aggregation with view",
"criteria", criteria,
"mask", mask,
)

Originally posted by @MrAlias in #3645 (comment)

@MrAlias MrAlias added pkg:SDK Related to an SDK package actions Pull requests that update GitHub action code area:metrics Part of OpenTelemetry Metrics and removed actions Pull requests that update GitHub action code labels May 30, 2023
@pellared
Copy link
Member

An error should be logged

Why not returning an error as suggested per the specification? I would consider changing the declaration to:

func NewView(criteria Instrument, mask Stream) (View, error) {
  1. We still can return a view when a error is reported
  2. I guess usually the operators (users) do not want such errors and would prefer to react. In some cases they may even want to crash the app if they find that they do not accept a misconfigured View.

@MrAlias
Copy link
Contributor Author

MrAlias commented May 31, 2023

Returning an error means NewView will not be able to be passed directly to WithView.

@MrAlias
Copy link
Contributor Author

MrAlias commented May 31, 2023

Returning an error means NewView will not be able to be passed directly to WithView.

That is the reason we already log an error with the global logger. It makes sense to keep the pattern here.

@pellared
Copy link
Member

pellared commented May 31, 2023

On the other hand, the exporter factory functions like otlpmetrichttp.New are returning (metric.Exporter, error) so that one cannot directly pass the result to metric.NewPeriodicReader.

I see Go as a quite verbose language when it comes to error handling. I do not feel that "fluent-like" API is idiomatic. The user can always create a helper that would handle the error (e.g. log, ignore, panic).

@MrAlias
Copy link
Contributor Author

MrAlias commented May 31, 2023

I don't follow. You are suggesting that precedence from a different function from a different package from a different part of the setup should take precedence for NewView? A function with existing precedence for error handling?

@pellared
Copy link
Member

pellared commented May 31, 2023

That is only "one" reason out of three.

  1. I feel that explicit error handling is more idiomatic
  2. It would literally follow the OTel Specification recommendation
  3. Precedence from a different package

(in this order)

MrAlias added a commit to MrAlias/opentelemetry-go that referenced this issue Jul 11, 2023
@MrAlias MrAlias self-assigned this Jul 11, 2023
MrAlias added a commit that referenced this issue Jul 12, 2023
* Log an error for an empty view

Resolves #4149

* Add changelog entry
@MrAlias MrAlias added this to the v1.17.0/v0.40.0 milestone Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics pkg:SDK Related to an SDK package
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants