Skip to content

Commit 729b5e0

Browse files
committed
Merge branch 'main' of github.com:jaydeluca/opentelemetry-java-instrumentation into breaking-change-message-2
2 parents 0688144 + 4d54532 commit 729b5e0

File tree

81 files changed

+1579
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1579
-233
lines changed

.github/graal-native-docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ services:
55
- "27017:27017"
66

77
zookeeper:
8-
image: confluentinc/cp-zookeeper:6.2.10
8+
image: confluentinc/cp-zookeeper:7.7.7
99
environment:
1010
ZOOKEEPER_CLIENT_PORT: 2181
1111
ZOOKEEPER_TICK_TIME: 2000
1212
ports:
1313
- "22181:2181"
1414

1515
kafka:
16-
image: confluentinc/cp-kafka:6.2.10
16+
image: confluentinc/cp-kafka:7.7.7
1717
ports:
1818
- 9094:9094
1919
depends_on:

.github/workflows/codeql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
./gradlew assemble -x javadoc
8181
-x :smoke-tests-otel-starter:spring-boot-3:collectReachabilityMetadata
8282
-x :smoke-tests-otel-starter:spring-boot-3.2:collectReachabilityMetadata
83+
-x :smoke-tests-otel-starter:spring-boot-4:collectReachabilityMetadata
8384
-x :smoke-tests-otel-starter:spring-boot-reactive-3:collectReachabilityMetadata
8485
--no-build-cache --no-daemon
8586

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
data class DependencySet(val group: String, val version: String, val modules: List<String>)
66

77
// this line is managed by .github/scripts/update-sdk-version.sh
8-
val otelSdkVersion = "1.56.0"
8+
val otelSdkVersion = "1.57.0"
99
val otelContribVersion = "1.52.0-alpha"
1010
val otelSdkAlphaVersion = otelSdkVersion.replaceFirst("(-SNAPSHOT)?$".toRegex(), "-alpha$1")
1111

examples/distro/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ subprojects {
2727
ext {
2828
versions = [
2929
// this line is managed by .github/scripts/update-sdk-version.sh
30-
opentelemetrySdk : "1.56.0",
30+
opentelemetrySdk : "1.57.0",
3131

3232
// these lines are managed by .github/scripts/update-version.sh
3333
opentelemetryJavaagent : "2.23.0-SNAPSHOT",

examples/extension/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ version '1.0'
2323
ext {
2424
versions = [
2525
// this line is managed by .github/scripts/update-sdk-version.sh
26-
opentelemetrySdk : "1.56.0",
26+
opentelemetrySdk : "1.57.0",
2727

2828
// these lines are managed by .github/scripts/update-version.sh
2929
opentelemetryJavaagent : "2.23.0-SNAPSHOT",

instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java renamed to instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jmx/JmxMetricInsightInstaller.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.javaagent.jmx;
6+
package io.opentelemetry.javaagent.instrumentation.jmx;
77

88
import com.google.auto.service.AutoService;
99
import io.opentelemetry.api.GlobalOpenTelemetry;
@@ -13,6 +13,8 @@
1313
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
1414
import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil;
1515
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
16+
import java.io.InputStream;
17+
import java.nio.file.Path;
1618
import java.nio.file.Paths;
1719
import java.time.Duration;
1820
import java.util.logging.Level;
@@ -33,18 +35,37 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
3335
JmxTelemetry.builder(GlobalOpenTelemetry.get())
3436
.beanDiscoveryDelay(beanDiscoveryDelay(config));
3537

36-
try {
37-
config.getList("otel.jmx.config").stream().map(Paths::get).forEach(jmx::addCustomRules);
38-
config.getList("otel.jmx.target.system").forEach(jmx::addClassPathRules);
39-
} catch (RuntimeException e) {
40-
// for now only log JMX errors as they do not prevent agent startup
41-
logger.log(Level.SEVERE, "Error while loading JMX configuration", e);
42-
}
38+
config.getList("otel.jmx.config").stream()
39+
.map(Paths::get)
40+
.forEach(path -> addFileRules(path, jmx));
41+
config.getList("otel.jmx.target.system").forEach(target -> addClasspathRules(target, jmx));
4342

4443
jmx.build().start();
4544
}
4645
}
4746

47+
private static void addFileRules(Path path, JmxTelemetryBuilder builder) {
48+
try {
49+
builder.addRules(path);
50+
} catch (RuntimeException e) {
51+
// for now only log JMX metric configuration errors as they do not prevent agent startup
52+
logger.log(Level.SEVERE, "Error while loading JMX configuration from " + path, e);
53+
}
54+
}
55+
56+
private static void addClasspathRules(String target, JmxTelemetryBuilder builder) {
57+
ClassLoader classLoader = JmxTelemetryBuilder.class.getClassLoader();
58+
String resource = String.format("jmx/rules/%s.yaml", target);
59+
InputStream input = classLoader.getResourceAsStream(resource);
60+
try {
61+
builder.addRules(input);
62+
} catch (RuntimeException e) {
63+
// for now only log JMX metric configuration errors as they do not prevent agent startup
64+
logger.log(
65+
Level.SEVERE, "Error while loading JMX configuration from classpath " + resource, e);
66+
}
67+
}
68+
4869
private static Duration beanDiscoveryDelay(ConfigProperties configProperties) {
4970
Duration discoveryDelay = configProperties.getDuration("otel.jmx.discovery.delay");
5071
if (discoveryDelay != null) {

instrumentation/jmx-metrics/javaagent/src/test/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstallerTest.java renamed to instrumentation/jmx-metrics/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jmx/JmxMetricInsightInstallerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.javaagent.jmx;
6+
package io.opentelemetry.javaagent.instrumentation.jmx;
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

@@ -41,7 +41,7 @@ void testToVerifyExistingRulesAreValid() throws Exception {
4141
assertThat(filePath).isRegularFile();
4242

4343
// loading rules from direct file access
44-
JmxTelemetry.builder(OpenTelemetry.noop()).addCustomRules(filePath);
44+
JmxTelemetry.builder(OpenTelemetry.noop()).addRules(filePath);
4545
}
4646
}
4747
}

instrumentation/jmx-metrics/library/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ import io.opentelemetry.api.OpenTelemetry;
3535
import io.opentelemetry.instrumentation.jmx.JmxTelemetry;
3636
import io.opentelemetry.instrumentation.jmx.JmxTelemetryBuilder;
3737

38+
import java.time.Duration;
39+
3840
// Get an OpenTelemetry instance
39-
OpenTelemetry openTelemetry = ...
41+
OpenTelemetry openTelemetry = ...;
4042

4143
JmxTelemetry jmxTelemetry = JmxTelemetry.builder(openTelemetry)
4244
// Configure included metrics (optional)
43-
.addClasspathRules("tomcat")
44-
.addClasspathRules("jetty")
45+
.addRules(JmxTelemetry.class.getClassLoader().getResourceAsStream("jmx/rules/jetty.yaml"), "jetty")
46+
.addRules(JmxTelemetry.class.getClassLoader().getResourceAsStream("jmx/rules/tomcat.yaml"), "tomcat")
4547
// Configure custom metrics (optional)
46-
.addCustomRules("/path/to/custom-jmx.yaml")
48+
.addRules(Paths.get("/path/to/custom-jmx.yaml"))
4749
// delay bean discovery by 5 seconds
48-
.beanDiscoveryDelay(5000)
50+
.beanDiscoveryDelay(Duration.ofSeconds(5))
4951
.build();
5052

51-
jmxTelemetry.startLocal();
53+
jmxTelemetry.start();
5254
```

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/JmxTelemetryBuilder.java

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,47 +49,73 @@ public JmxTelemetryBuilder beanDiscoveryDelay(Duration delay) {
4949
}
5050

5151
/**
52-
* Adds built-in JMX rules from classpath resource
52+
* Adds built-in JMX rules from classpath resource.
5353
*
5454
* @param target name of target in /jmx/rules/{target}.yaml classpath resource
5555
* @return builder instance
5656
* @throws IllegalArgumentException when classpath resource does not exist or can't be parsed
5757
*/
58+
// TODO: deprecate this method after 2.23.0 release in favor of addRules
5859
@CanIgnoreReturnValue
5960
public JmxTelemetryBuilder addClassPathRules(String target) {
60-
String yamlResource = String.format("jmx/rules/%s.yaml", target);
61-
try (InputStream inputStream =
62-
JmxTelemetryBuilder.class.getClassLoader().getResourceAsStream(yamlResource)) {
63-
if (inputStream == null) {
64-
throw new IllegalArgumentException("JMX rules not found in classpath: " + yamlResource);
65-
}
66-
logger.log(FINE, "Adding JMX config from classpath for {0}", yamlResource);
67-
RuleParser parserInstance = RuleParser.get();
68-
parserInstance.addMetricDefsTo(metricConfiguration, inputStream, target);
69-
} catch (Exception e) {
61+
String resourcePath = String.format("jmx/rules/%s.yaml", target);
62+
ClassLoader classLoader = JmxTelemetryBuilder.class.getClassLoader();
63+
logger.log(FINE, "Adding JMX config from classpath {0}", resourcePath);
64+
try (InputStream inputStream = classLoader.getResourceAsStream(resourcePath)) {
65+
return addRules(inputStream);
66+
} catch (IOException e) {
7067
throw new IllegalArgumentException(
71-
"Unable to load JMX rules from classpath: " + yamlResource, e);
68+
"Unable to load JMX rules from resource " + resourcePath, e);
7269
}
70+
}
71+
72+
/**
73+
* Adds JMX rules from input stream
74+
*
75+
* @param input input to read rules from
76+
* @throws IllegalArgumentException when input is {@literal null} or can't be parsed
77+
*/
78+
@CanIgnoreReturnValue
79+
public JmxTelemetryBuilder addRules(InputStream input) {
80+
if (input == null) {
81+
throw new IllegalArgumentException("missing JMX rules");
82+
}
83+
RuleParser parserInstance = RuleParser.get();
84+
parserInstance.addMetricDefsTo(metricConfiguration, input);
7385
return this;
7486
}
7587

7688
/**
77-
* Adds custom JMX rules from file system path
89+
* Adds JMX rules from file system path
7890
*
7991
* @param path path to yaml file
8092
* @return builder instance
81-
* @throws IllegalArgumentException when classpath resource does not exist or can't be parsed
93+
* @throws IllegalArgumentException in case of parsing errors or when file does not exist
8294
*/
8395
@CanIgnoreReturnValue
84-
public JmxTelemetryBuilder addCustomRules(Path path) {
85-
logger.log(FINE, "Adding JMX config from file: {0}", path);
86-
RuleParser parserInstance = RuleParser.get();
96+
public JmxTelemetryBuilder addRules(Path path) {
97+
if (path == null) {
98+
throw new IllegalArgumentException("missing JMX rules");
99+
}
87100
try (InputStream inputStream = Files.newInputStream(path)) {
88-
parserInstance.addMetricDefsTo(metricConfiguration, inputStream, path.toString());
101+
logger.log(FINE, "Adding JMX config from file {0}", path);
102+
return addRules(inputStream);
89103
} catch (IOException e) {
90-
throw new IllegalArgumentException("Unable to load JMX rules in path: " + path, e);
104+
throw new IllegalArgumentException("Unable to load JMX rules from: " + path, e);
91105
}
92-
return this;
106+
}
107+
108+
/**
109+
* Adds custom JMX rules from file system path
110+
*
111+
* @param path path to yaml file
112+
* @return builder instance
113+
* @throws IllegalArgumentException when classpath resource does not exist or can't be parsed
114+
*/
115+
// TODO: deprecate this method after 2.23.0 release in favor of addRules
116+
@CanIgnoreReturnValue
117+
public JmxTelemetryBuilder addCustomRules(Path path) {
118+
return addRules(path);
93119
}
94120

95121
public JmxTelemetry build() {

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/RuleParser.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.opentelemetry.instrumentation.jmx.yaml;
77

88
import static java.util.Collections.emptyList;
9-
import static java.util.logging.Level.INFO;
9+
import static java.util.logging.Level.FINE;
1010

1111
import io.opentelemetry.instrumentation.jmx.engine.MetricConfiguration;
1212
import java.io.InputStream;
@@ -162,21 +162,19 @@ private static void failOnExtraKeys(Map<String, Object> yaml) {
162162
*
163163
* @param conf the metric configuration
164164
* @param is the InputStream with the YAML rules
165-
* @param id identifier of the YAML ruleset, such as a filename
166165
* @throws IllegalArgumentException when unable to parse YAML
167166
*/
168-
public void addMetricDefsTo(MetricConfiguration conf, InputStream is, String id) {
167+
public void addMetricDefsTo(MetricConfiguration conf, InputStream is) {
169168
try {
170169
JmxConfig config = loadConfig(is);
171-
logger.log(INFO, "{0}: found {1} metric rules", new Object[] {id, config.getRules().size()});
170+
logger.log(FINE, "found {1} metric rules", config.getRules().size());
172171
config.addMetricDefsTo(conf);
173172
} catch (Exception exception) {
174173
// It is essential that the parser exception is made visible to the user.
175174
// It contains contextual information about any syntax issues found by the parser.
176175
String msg =
177176
String.format(
178-
"Failed to parse YAML rules from %s: %s %s",
179-
id, rootCause(exception), exception.getMessage());
177+
"Failed to parse YAML rules : %s %s", rootCause(exception), exception.getMessage());
180178
throw new IllegalArgumentException(msg, exception);
181179
}
182180
}

0 commit comments

Comments
 (0)