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

MetricPoint public API changes #2633

Closed
cijothomas opened this issue Nov 17, 2021 · 7 comments · Fixed by #2657
Closed

MetricPoint public API changes #2633

cijothomas opened this issue Nov 17, 2021 · 7 comments · Fixed by #2657
Assignees
Labels
enhancement New feature or request metrics Metrics signal related
Milestone

Comments

@cijothomas
Copy link
Member

The numerical values are now retrived using LongValue, DoubleValue etc. These fields have meaning based on the type (eg: For histogram DoubleValue means the SUM, for Long Counter , DoubleValue means nothing and is an error if trrying to access)

Proposal is to make these internal, and instead provide methods like GetHistogramSum etc., so that exporters doesn't have to know any internal details. This will also allow us from changing the MetricPoint structure internally, w/o breaking exporters.

@cijothomas cijothomas added the enhancement New feature or request label Nov 17, 2021
@cijothomas cijothomas added this to the 1.2.0 milestone Nov 17, 2021
@cijothomas cijothomas added metrics Metrics signal related priority:p1 labels Nov 17, 2021
@joaopgrassi
Copy link
Member

This would make things much clearer. I just now wrote an exporter and had to dig in the code to see what they meant.

@cijothomas
Copy link
Member Author

This would make things much clearer. I just now wrote an exporter and had to dig in the code to see what they meant.

yes surely.! A bigger motivation is to hide the implementation from users, so we can optimize MetricPoint in the future, without breaking.

@joaopgrassi
Copy link
Member

Just to maybe capture some feedback around this. I'm building an exporter and some things I stumbled across that might be considered:

For example:

var lines = new List<string>(metric.PointsCount); // new API
foreach (var metricPoint in metric.GetMetricPoints())
{
	lines.add(SerializePoint(metricPoint))
}
  • A nicer API around collecting the attributes. Right now we have to loop through metricPoint.Keys and metricPoint.Values. I thought I saw something around improving it, but couldn't find anymore. The issue is that exporters will probably have to duplicate code similar to this.
for (int i = 0; i < metricPoint.Keys.Length; i++)
{
	tagsBuilder.Append(metricPoint.Keys[i]);
	tagsBuilder.Append(':');
	tagsBuilder.Append(metricPoint.Values[i]);
	tagsBuilder.Append(' ');
}
  • Validation when adding attributes. Now we accept <string, object?>, which allows me to pass something like an instance of a class. Is this already in our backlog to improve? I ask because you can do things like this (which was a surprise)
public class MyClass
{
	public override string ToString() => "OOPS";
}

// either this or by using `TagList`
var attributes = new KeyValuePair<string, object?>[]
{
	new ("key1", new MyClass()),
};

var attributes2 = new TagList
{
	{ "my_label", new MyClass() }
};

var counter = meter.CreateCounter<int>("counter");
counter.Add(10, attributes);

image

@cijothomas
Copy link
Member Author

For attributes/tags - this pr #2642 is merged.

Regarding the tag value being object - Could you clarify what is the ask?

@cijothomas
Copy link
Member Author

It would be nice if it was possible to know how many points a metric holds. --> we should be able to support this.

@joaopgrassi
Copy link
Member

Regarding the tag value being object - Could you clarify what is the ask?

It's just that the spec says only primitive values (or lists of primitive values) are allowed, but here I can add whatever value I want. And in this case, I added an instance of a class and it took the ToString() out of it. We probably should allow only primitive types, for example like Java does https://github.com/open-telemetry/opentelemetry-java/blob/main/api/all/src/main/java/io/opentelemetry/api/common/AttributeKey.java

@cijothomas
Copy link
Member Author

Closing the overall issue as its covered by several prs, and is part of 1.2.0-rc1 release.

Have few additional feedback from @joaopgrassi . Will operate specific issues for tracking them, to add post 1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request metrics Metrics signal related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants