Skip to content

Commit ded1186

Browse files
committed
collect j17
1 parent b6acfd1 commit ded1186

4 files changed

Lines changed: 194 additions & 1 deletion

File tree

.github/scripts/instrumentations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ readonly INSTRUMENTATIONS=(
245245
"rocketmq:rocketmq-client-4.8:javaagent:testExperimental"
246246
"rocketmq:rocketmq-client-5.0:javaagent:test"
247247
"rocketmq:rocketmq-client-5.0:javaagent:testExperimental"
248+
"runtime-telemetry:library:check"
248249
"servlet:servlet-2.2:javaagent:test"
249250
"servlet:servlet-3.0:javaagent-testing:test"
250251
"servlet:servlet-5.0:jetty12-testing:test"

docs/instrumentation-list.yaml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12553,6 +12553,152 @@ libraries:
1255312553
type: int
1255412554
default: 10
1255512555
telemetry:
12556+
- when: Java17
12557+
metrics:
12558+
- name: jvm.buffer.count
12559+
description: Number of buffers in the pool.
12560+
instrument: updowncounter
12561+
data_type: LONG_SUM
12562+
unit: '{buffer}'
12563+
attributes:
12564+
- name: jvm.buffer.pool.name
12565+
type: STRING
12566+
- name: jvm.buffer.memory.limit
12567+
description: Measure of total memory capacity of buffers.
12568+
instrument: updowncounter
12569+
data_type: LONG_SUM
12570+
unit: By
12571+
attributes:
12572+
- name: jvm.buffer.pool.name
12573+
type: STRING
12574+
- name: jvm.buffer.memory.used
12575+
description: Measure of memory used by buffers.
12576+
instrument: updowncounter
12577+
data_type: LONG_SUM
12578+
unit: By
12579+
attributes:
12580+
- name: jvm.buffer.pool.name
12581+
type: STRING
12582+
- name: jvm.class.count
12583+
description: Number of classes currently loaded.
12584+
instrument: updowncounter
12585+
data_type: LONG_SUM
12586+
unit: '{class}'
12587+
attributes: []
12588+
- name: jvm.class.loaded
12589+
description: Number of classes loaded since JVM start.
12590+
instrument: counter
12591+
data_type: LONG_SUM
12592+
unit: '{class}'
12593+
attributes: []
12594+
- name: jvm.class.unloaded
12595+
description: Number of classes unloaded since JVM start.
12596+
instrument: counter
12597+
data_type: LONG_SUM
12598+
unit: '{class}'
12599+
attributes: []
12600+
- name: jvm.cpu.count
12601+
description: Number of processors available to the Java virtual machine.
12602+
instrument: updowncounter
12603+
data_type: LONG_SUM
12604+
unit: '{cpu}'
12605+
attributes: []
12606+
- name: jvm.cpu.longlock
12607+
description: Long lock times
12608+
instrument: histogram
12609+
data_type: HISTOGRAM
12610+
unit: s
12611+
attributes: []
12612+
- name: jvm.cpu.recent_utilization
12613+
description: Recent CPU utilization for the process as reported by the JVM.
12614+
instrument: gauge
12615+
data_type: DOUBLE_GAUGE
12616+
unit: '1'
12617+
attributes: []
12618+
- name: jvm.cpu.time
12619+
description: CPU time used by the process as reported by the JVM.
12620+
instrument: counter
12621+
data_type: DOUBLE_SUM
12622+
unit: s
12623+
attributes: []
12624+
- name: jvm.gc.duration
12625+
description: Duration of JVM garbage collection actions.
12626+
instrument: histogram
12627+
data_type: HISTOGRAM
12628+
unit: s
12629+
attributes:
12630+
- name: jvm.gc.action
12631+
type: STRING
12632+
- name: jvm.gc.name
12633+
type: STRING
12634+
- name: jvm.memory.committed
12635+
description: Measure of memory committed.
12636+
instrument: updowncounter
12637+
data_type: LONG_SUM
12638+
unit: By
12639+
attributes:
12640+
- name: jvm.memory.pool.name
12641+
type: STRING
12642+
- name: jvm.memory.type
12643+
type: STRING
12644+
- name: jvm.memory.init
12645+
description: Measure of initial memory requested.
12646+
instrument: updowncounter
12647+
data_type: LONG_SUM
12648+
unit: By
12649+
attributes:
12650+
- name: jvm.memory.pool.name
12651+
type: STRING
12652+
- name: jvm.memory.type
12653+
type: STRING
12654+
- name: jvm.memory.limit
12655+
description: Measure of max obtainable memory.
12656+
instrument: updowncounter
12657+
data_type: LONG_SUM
12658+
unit: By
12659+
attributes:
12660+
- name: jvm.memory.pool.name
12661+
type: STRING
12662+
- name: jvm.memory.type
12663+
type: STRING
12664+
- name: jvm.memory.used
12665+
description: Measure of memory used.
12666+
instrument: updowncounter
12667+
data_type: LONG_SUM
12668+
unit: By
12669+
attributes:
12670+
- name: jvm.memory.pool.name
12671+
type: STRING
12672+
- name: jvm.memory.type
12673+
type: STRING
12674+
- name: jvm.memory.used_after_last_gc
12675+
description: Measure of memory used, as measured after the most recent garbage
12676+
collection event on this pool.
12677+
instrument: updowncounter
12678+
data_type: LONG_SUM
12679+
unit: By
12680+
attributes:
12681+
- name: jvm.memory.pool.name
12682+
type: STRING
12683+
- name: jvm.memory.type
12684+
type: STRING
12685+
- name: jvm.system.cpu.utilization
12686+
description: Recent CPU utilization for the whole system as reported by the
12687+
JVM.
12688+
instrument: gauge
12689+
data_type: DOUBLE_GAUGE
12690+
unit: '1'
12691+
attributes: []
12692+
- name: jvm.thread.count
12693+
description: Number of executing platform threads.
12694+
instrument: updowncounter
12695+
data_type: LONG_SUM
12696+
unit: '{thread}'
12697+
attributes:
12698+
- name: jvm.thread.daemon
12699+
type: BOOLEAN
12700+
- name: jvm.thread.state
12701+
type: STRING
1255612702
- when: default
1255712703
metrics:
1255812704
- name: jvm.buffer.count

instrumentation/runtime-telemetry/library/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ tasks {
110110
}
111111
include("**/*G1GcMemoryMetricTest.*")
112112
jvmArgs("-XX:+UseG1GC")
113+
systemProperty("metadataConfig", "Java17")
113114
}
114115

115116
val testPS by registering(Test::class) {
@@ -121,6 +122,7 @@ tasks {
121122
}
122123
include("**/*PsGcMemoryMetricTest.*")
123124
jvmArgs("-XX:+UseParallelGC")
125+
systemProperty("metadataConfig", "Java17")
124126
}
125127

126128
val testSerial by registering(Test::class) {
@@ -132,6 +134,7 @@ tasks {
132134
}
133135
include("**/*SerialGcMemoryMetricTest.*")
134136
jvmArgs("-XX:+UseSerialGC")
137+
systemProperty("metadataConfig", "Java17")
135138
}
136139

137140
// Run other Java 17 tests (not GC-specific)
@@ -144,6 +147,7 @@ tasks {
144147
excludeTestsMatching("*SerialGcMemoryMetricTest")
145148
excludeTestsMatching("*PsGcMemoryMetricTest")
146149
}
150+
systemProperty("metadataConfig", "Java17")
147151
}
148152

149153
test {

instrumentation/runtime-telemetry/library/src/testJava17/java/io/opentelemetry/instrumentation/runtimetelemetry/JfrExtension.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66
package io.opentelemetry.instrumentation.runtimetelemetry;
77

88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
9+
import static java.util.Collections.emptyMap;
910
import static java.util.concurrent.TimeUnit.SECONDS;
1011
import static org.awaitility.Awaitility.await;
1112

1213
import io.opentelemetry.instrumentation.runtimetelemetry.internal.JfrConfig;
14+
import io.opentelemetry.instrumentation.testing.internal.MetaDataCollector;
1315
import io.opentelemetry.sdk.OpenTelemetrySdk;
16+
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1417
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
1518
import io.opentelemetry.sdk.metrics.data.MetricData;
1619
import io.opentelemetry.sdk.testing.assertj.MetricAssert;
1720
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
21+
import java.io.File;
22+
import java.io.IOException;
1823
import java.util.Collection;
24+
import java.util.HashMap;
25+
import java.util.HashSet;
26+
import java.util.List;
27+
import java.util.Map;
28+
import java.util.Set;
1929
import java.util.function.Consumer;
2030
import jdk.jfr.FlightRecorder;
2131
import org.junit.jupiter.api.Assumptions;
@@ -30,6 +40,9 @@ public class JfrExtension implements BeforeEachCallback, AfterEachCallback {
3040
private SdkMeterProvider meterProvider;
3141
private InMemoryMetricReader metricReader;
3242
private RuntimeTelemetry runtimeMetrics;
43+
private final Map<InstrumentationScopeInfo, Map<String, MetricData>> metricsByScope =
44+
new HashMap<>();
45+
private final Set<InstrumentationScopeInfo> instrumentationScopes = new HashSet<>();
3346

3447
public JfrExtension(Consumer<JfrConfig> jfrConfigConsumer) {
3548
this.jfrConfigConsumer = jfrConfigConsumer;
@@ -58,13 +71,22 @@ public void beforeEach(ExtensionContext context) throws InterruptedException {
5871
}
5972

6073
@Override
61-
public void afterEach(ExtensionContext context) {
74+
public void afterEach(ExtensionContext context) throws IOException {
6275
if (meterProvider != null) {
6376
meterProvider.close();
6477
}
6578
if (runtimeMetrics != null) {
6679
runtimeMetrics.close();
6780
}
81+
82+
// Generates files in a `.telemetry` directory within the instrumentation module with all
83+
// captured emitted metadata to be used by the instrumentation-docs Doc generator.
84+
if (Boolean.getBoolean("collectMetadata")) {
85+
String path = new File("").getAbsolutePath();
86+
87+
MetaDataCollector.writeTelemetryToFiles(
88+
path, metricsByScope, emptyMap(), instrumentationScopes);
89+
}
6890
}
6991

7092
@SafeVarargs
@@ -79,6 +101,26 @@ protected final void waitAndAssertMetrics(Consumer<MetricAssert>... assertions)
79101
for (Consumer<MetricAssert> assertion : assertions) {
80102
assertThat(metrics).anySatisfy(metric -> assertion.accept(assertThat(metric)));
81103
}
104+
if (Boolean.getBoolean("collectMetadata")) {
105+
collectEmittedMetrics(metrics.stream().toList());
106+
}
82107
});
83108
}
109+
110+
private void collectEmittedMetrics(List<MetricData> metrics) {
111+
for (MetricData metric : metrics) {
112+
Map<String, MetricData> scopeMap =
113+
this.metricsByScope.computeIfAbsent(
114+
metric.getInstrumentationScopeInfo(), m -> new HashMap<>());
115+
116+
if (!scopeMap.containsKey(metric.getName())) {
117+
scopeMap.put(metric.getName(), metric);
118+
}
119+
120+
InstrumentationScopeInfo scopeInfo = metric.getInstrumentationScopeInfo();
121+
if (!scopeInfo.getName().equals("test")) {
122+
instrumentationScopes.add(scopeInfo);
123+
}
124+
}
125+
}
84126
}

0 commit comments

Comments
 (0)