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

add metric annotation instrumentation #11354

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

Duncan-tree-zhou
Copy link

@Duncan-tree-zhou Duncan-tree-zhou commented May 14, 2024

refer to #7030
add metric annotation instrumentation

@Duncan-tree-zhou Duncan-tree-zhou requested a review from a team May 14, 2024 15:45
@steverao
Copy link
Contributor

There are some CI failures, firstly you can solve them by referring to https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/running-tests.md#troubleshooting-ci-test-failures

@Duncan-tree-zhou Duncan-tree-zhou marked this pull request as draft May 15, 2024 15:00
@Duncan-tree-zhou Duncan-tree-zhou force-pushed the add_metric_annotation_instrument branch 2 times, most recently from f1797c8 to f7dd6b9 Compare May 20, 2024 13:27
@Duncan-tree-zhou
Copy link
Author

Hi @steverao, I found that there are lots of fails "to connect to localhost/127.0.0.1:4318". So I want to rerun the task, but I can't see the rerun button. Is it disabled for contributors?

@steverao
Copy link
Contributor

Is it disabled for contributors?

Yes, you can fix the problems firstly and push relevant commits. It will trigger to rerun the CI tasks.

@Duncan-tree-zhou
Copy link
Author

Duncan-tree-zhou commented May 22, 2024

I mean I guest the failure is caused by the CI run time environment crush..... if it's able to rerun a task, It might save some time....

@Duncan-tree-zhou Duncan-tree-zhou force-pushed the add_metric_annotation_instrument branch 2 times, most recently from 815bbfd to 95f0f0d Compare May 24, 2024 14:29
@github-actions github-actions bot requested a review from theletterf May 29, 2024 16:36
@Duncan-tree-zhou Duncan-tree-zhou force-pushed the add_metric_annotation_instrument branch from f9657ec to 5ab650b Compare May 30, 2024 14:13
@Duncan-tree-zhou Duncan-tree-zhou marked this pull request as ready for review May 30, 2024 14:58
@Duncan-tree-zhou
Copy link
Author

Duncan-tree-zhou commented May 30, 2024

I turn it ready for reviewing, and get some questions for discuss:

  1. the module naming of the @Counted and @Timed instrumentation.
    • I avoid using the opentelemetry-instrumentation-annotations prefix because it's already been used for @Withspan. I am not sure if using opentelemetry-instrumentation-annotations-coutned would cause some problem somewhere.
    • I have no idea if there is a better module naming rule for metrics annotations instrumentations.
  2. I am not sure if we should put the instance of meter, LongCounter and DoubleHistogram in another module where can be loaded without javaagent?
  3. I am doubted about allowing the return value to be an attributes because most of time the return value is unpredictable. would it be possible to design some static api to allow user to post the attributes to the metrics via threadlocal?

@Duncan-tree-zhou Duncan-tree-zhou force-pushed the add_metric_annotation_instrument branch 5 times, most recently from 5024350 to 54866bf Compare June 9, 2024 04:27
@Duncan-tree-zhou Duncan-tree-zhou force-pushed the add_metric_annotation_instrument branch from 54866bf to 21cbf96 Compare June 9, 2024 04:30
@laurit
Copy link
Contributor

laurit commented Jun 26, 2024

@open-telemetry/java-instrumentation-approvers could you please review

@laurit laurit added this to the v2.6.0 milestone Jul 8, 2024
* <p>Warning: be careful to fill it because it might cause an explosion of the cardinality on
* your metric
*/
String value() default "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth renaming this to name (even though it would then require providing name = ), so that it's not confusing that this is the "metric value", and consistent with @StaticMetricAttribute which uses name/value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like forcing users to use name = "foo" Micrometer https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/aop/MeterTag.java defines key and value and says that both represent the name of the tag and value is an alias for key.

*
* <p>If you are a library developer, then probably you should NOT use this annotation, because it
* is non-functional without the OpenTelemetry auto-instrumentation agent, or some other annotation
* processor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we doc the attribute type that will be used for the metric attribute?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute type is chosen based on the same logic as with SpanAttribute. The logic for choosing the type in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-annotations-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/AttributeBindingFactory.java is quite complicated but in my opinion still not complete. For example it does not handle byte and short and their arrays as numeric types. In the span attribute code there are differences between attribute types used in the default and kotlin coroutine implementation.

*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface MetricAttribute {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this @Attribute and would use it both for metrics and tracing...
We have the @SpanAttribute witch can record high cardinality data. However, @Attribute could have a field stating if we want it or not in the trace...
This would avoid having a ton of annotations in method params.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree that the current names are not ideal, but I think they are good enough for the first prototype and give a good base to build upon. To be honest I wasn't really interested in driving this effort I only wanted to help getting this PR into mergeable shape.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth to discuss this a bit because if we have to change it in the future, it will be yet another breaking change.

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(StaticMetricAttributes.class)
public @interface StaticMetricAttribute {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ StaticMetricAttribute is a very long name.

@trask trask modified the milestones: v2.6.0, v2.7.0 Jul 16, 2024
@trask trask modified the milestones: v2.7.0, v2.8.0 Aug 16, 2024
@trask trask modified the milestones: v2.8.0, v2.9.0 Sep 13, 2024
@trask trask modified the milestones: v2.9.0, v2.10.0 Oct 17, 2024
@trask trask modified the milestones: v2.10.0, v2.11.0 Nov 13, 2024
@trask trask modified the milestones: v2.11.0, v2.12.0 Dec 23, 2024
@Duncan-tree-zhou Duncan-tree-zhou requested a review from a team as a code owner January 7, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants