Skip to content

Commit 061e3c7

Browse files
committed
Documentation updated.
Converter registration is now package private.
1 parent d6b87e2 commit 061e3c7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

instrumentation/jmx-metrics/javaagent/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,39 @@ rules:
307307

308308
For now, only the `lowercase` transformation is supported, other additions might be added in the future if needed.
309309

310+
### Unit conversions
311+
312+
Sometimes JMX attributes values are reported in units not aligned with semantic conventions.
313+
For example duration values are usually reported as milliseconds while semantic conventions recommend using seconds.
314+
315+
This issue can be solved by providing optional `sourceUnit` metric property together with `unit` metric property.
316+
`sourceUnit` defines native unit of value retrieved from JMX attribute, while `unit` defines a semantic convention compatible metric unit that will be reported to the backend.
317+
If conversion between `sourceUnit` and `unit` is available then it is automatically applied before reporting the metric.
318+
If such a conversion is not available then an error is reported during JMX metrics processing.
319+
320+
Currently available unit conversions:
321+
322+
| `sourceUnit` | `unit` |
323+
|-------------|-------|
324+
| ms | s |
325+
| ns | s |
326+
327+
Example of defining unit conversion in yaml file:
328+
```yaml
329+
rules:
330+
- beans:
331+
- Catalina:type=GlobalRequestProcessor,name=*
332+
prefix: http.server.tomcat.
333+
mapping:
334+
maxTime:
335+
metric: maxTime
336+
type: gauge
337+
sourceUnit: ms
338+
unit: s
339+
desc: The longest request processing time
340+
```
341+
`sourceUnit` can also be defined on rule level (see [Making shortcuts](#making-shortcuts))
342+
310343
### General Syntax
311344

312345
Here is the general description of the accepted configuration file syntax. The whole contents of the file is case-sensitive, with exception for `type` as described in the table below.

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/unit/UnitConverterFactory.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static UnitConverter getConverter(@Nullable String sourceUnit, String tar
4242
return converter;
4343
}
4444

45-
public static void registerConverter(
45+
// visible for testing
46+
static void registerConverter(
4647
String sourceUnit,
4748
String targetUnit,
4849
Function<Number, Number> convertingFunction,

0 commit comments

Comments
 (0)