Skip to content

Conversation

@mcmho
Copy link
Contributor

@mcmho mcmho commented Oct 17, 2025

Description:
Feature / Improvement: use weaver model to describe metrics so that they can be standardized.

  • created metrics.yaml weaver model for jvm metrics
  • created attriutes.yaml
  • tested with weaver registry generate

Testing:

  • tested with weaver registry generate; metadata.yaml is successfully generated and content is valided

Documentation:

  • customer facing docs not yet needed

Outstanding items:

  • once this looks good, there will be other models to work on for other target systems.

…try#2072

 - created metrics.yaml weaver model
 - created attriutes.yaml
 - tested with weaver registry generate
@mcmho mcmho requested a review from a team as a code owner October 17, 2025 00:15
mcmho added 2 commits October 22, 2025 17:07
…try#2072

 - tested weaver model locally as well as on docker
 - completed Makefile
…try#2072

 - tested weaver model locally as well as on docker
 - completed Makefile
Copy link
Contributor

@atoulme atoulme left a comment

Choose a reason for hiding this comment

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

LGTM - please look at the CI?

@SylvainJuge
Copy link
Contributor

I am not familiar with weaver, does it means that the jmx scraper yaml configuration would be now generated from registry+template ? Maybe we could modify the yaml format to make this easier or even avoid having to use a template.

Do you have an high level overview of what this change helps to achieve?

Also, the metrics descriptions are part of what is being tested in unit tests, so when changing them you'll have to update the test code as well.

@mcmho
Copy link
Contributor Author

mcmho commented Oct 31, 2025

Thanks all. sorry for the delay! The tests are fixed now.

Re: @SylvainJuge
yes, the rule configuration will be generated from jinja2 template and registry.

Perhaps @atoulme can chime in since he created the original request. As far as I understand, one of the main benefits coming out of this is standardization of metrics. Ultimately, we can have a centralized registry of metrics. That would become the single source of truth / semconv. I think that's what @atoulme has in mind "The idea is that eventually we can move some of the weaver models to semconv, as metric references."

@SylvainJuge
Copy link
Contributor

If I understand this correctly, this PR does the following:

  • makes the weaver yaml descriptor the source of truth to define JMX metrics (limited to the JVM target system for now)
  • adds a jinja template to translate from the weaver yaml to the JMX metrics yaml

With that, modifying the JMX metrics yaml would require expertise in jinja and in running weaver with a makefile, which is not how things are usually done in this java-only project.

What I think would be simpler here is to keep the JMX metrics yaml as source of truth and then generate the weaver yaml files from it as part of the build process.

The benefits I see for this approach would be the following:

  • it's easier to add extra attributes in JMX yaml for the weaver yaml generation than using jinja template to do the opposite
  • keep the implementation 100% in Java
  • easy to integrate into current gradle build
  • could be included directly into the jmx-scraper CLI so that end-users could also do the same with their custom JMX metrics definitions.
  • adding support for other target systems would only require to update their jmx yaml (with the few new extra fields), without having to deal with a dedicated template for each and thus handle them all at once.
  • we could still use the weaver yaml and templates to generate and update the documentation markdown, for example as part of the CI.

I will need to prototype this to validate this is a viable approach, I will try to do this in the following weeks. This will need to happen in the instrumentation repository as the jmx-metrics implementation is part of it.

In addition to that, we also need to deal with the following extra challenges:

  • jmx-scraper can use two sets of metrics: the "legacy" ones in jmx-scraper and the ones from "instrumentation" that are inherited from instrumentation (depends on the value of otel.jmx.target.source configuration), do we have a way to describe things that depend on configuration in the weaver description ?
  • the jmx metrics definitions that are in instrumentation should have their definitions in the java instrumentation repository, but we can still generate the effective weaver yaml (including what is inherited).

Regarding the ability to push JMX metrics into semconv, this would be awesome but also challenging as product implementation might change across versions and would also require to create semconv SIG(s). I'd be happy to participate to that initiative when it starts.

@SylvainJuge
Copy link
Contributor

I've opened open-telemetry/opentelemetry-java-instrumentation#15196 to attempt to implement this directly into java instrumentation.

@atoulme
Copy link
Contributor

atoulme commented Oct 31, 2025

With that, modifying the JMX metrics yaml would require expertise in jinja and in running weaver with a makefile, which is not how things are usually done in this java-only project.

Please upvote and consider participating in open-telemetry/weaver#792

I'm sure we can work out a gradle task to run a docker container, might take a bit to get the kinks out.

The choice of jinja2 as a templating language seems like the least of all choices at this point, but please feel free to offer alternatives in the weaver repository?

What I think would be simpler here is to keep the JMX metrics yaml as source of truth and then generate the weaver yaml files from it as part of the build process.

It can work, but the weaver model is richer than the JMX metrics yaml though.

mapping:
{%- for m in ctx.groups if m.id.startswith(jvm_memory_prefix + "heap") %}
{%- if m.id == jvm_memory_prefix + "heap.committed" %}
HeapMemoryUsage.committed:
Copy link
Contributor

Choose a reason for hiding this comment

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

You could put an annotation on the metric and use it here if you wanted.

So your metrics.yaml would be something like:

groups:
  - id: jvm.memory.head.committed
    type: metric
    ...
    annotations:
    - jmx_name: HeapMemoryUsage.committed

Then here you could have the mapping generically pull the annotation:

{{ m.annotatiions.jmx_name }}:
  metric: {{ m.id | ... }
  ...

Copy link
Contributor

Choose a reason for hiding this comment

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

You could even go further and record the Bean / property and group-by bean, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants