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

Auto-instrumentation with JMX #9336

Closed
sarkisjad opened this issue Aug 29, 2023 · 5 comments
Closed

Auto-instrumentation with JMX #9336

sarkisjad opened this issue Aug 29, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@sarkisjad
Copy link

Describe the bug

I am trying to implement auto-instrumentation using the jmx-metrics
My aim is to emit a metric on a simple Java application for the thread count.
When I run the command (shown in 'Steps to reproduce') and create a rules file (as instructed in the documentation), the metric described in said rules file is not emitted even when I leave the application running for a while. Yet, when I open jconsole, it gets emitted successfully. I am assuming it is because I am launching a trigger that will help the process out.

Steps to reproduce

Here is the following command launched on my Windows terminal:
java -javaagent:./opentelemetry-javaagent.jar -Dotel.instrumentation.common.default-enabled=false -Dotel.jmx.discovery.delay=1000 -Dotel.jmx.config=config_file.yml -jar my-application.jar

With the config_file.yml being:

rules:
  - bean: java.lang:type=Threading
    mapping:
      ThreadCount:
        metric: my.own.jvm.thread.count
        type: gauge
        desc: The current number of threads
        unit: "1"

Expected behavior

One of the metrics emitted should be the following:
[{"name":"my.own.jvm.thread.count","description":"The current number of threads","unit":"1","sum":{"dataPoints":[{"startTimeUnixNano":"1692280364935098100","timeUnixNano":"1692280484952967900","asInt":"23"}],"aggregationTemporality":2}}]

It is emitted only when we launch jconsole.

Actual behavior

No such metric is emitted when we leave the application to run alone, without any additional help (jconsole).

Javaagent or library instrumentation version

v1.29.0 (latest as of date)

Environment

JDK: 17.0.2
OS:

Additional context

I have opentelemetry configured. It is listening to the default port (4317) and successfully capturing metrics and logging it in a random text file, as per my configuration.
We have no issues on that side.

@sarkisjad sarkisjad added bug Something isn't working needs triage New issue that requires triage labels Aug 29, 2023
@mateuszrzeszutek
Copy link
Member

Ping @PeterF778 -- is this something you could take a look at?

@PeterF778
Copy link
Contributor

PeterF778 commented Aug 30, 2023 via email

@PeterF778
Copy link
Contributor

The cause for this issue is that the PlatformMBeanServer is lazily instantiated by the Java runtime. If there are no explicit references to it from the application (or the Java runtime itself), JMX Metric Insight will be unable to find the platform MBeans.

@PeterF778
Copy link
Contributor

Providing a fix as PR #9362

@mateuszrzeszutek mateuszrzeszutek removed the needs triage New issue that requires triage label Sep 1, 2023
@breedx-splk
Copy link
Contributor

Looks like the fix landed in #9362 but this wasn't auto closed. Closing now, but please reopen if I have misunderstood.

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

4 participants