Skip to content

Commit c21e279

Browse files
committed
Merge branch 'main' of github.com:jaydeluca/opentelemetry-java-instrumentation into declarative-config-flakyness
2 parents 00414f6 + 7088573 commit c21e279

File tree

109 files changed

+2690
-3088
lines changed

Some content is hidden

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

109 files changed

+2690
-3088
lines changed

.github/scripts/update-version.sh

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ sed -Ei "s/(opentelemetryJavaagentAlpha *: )\"[^\"]*\"/\1\"$alpha_version\"/" ex
2121

2222
sed -Ei "s/(io.opentelemetry.instrumentation.muzzle-generation\" version )\"[^\"]*\"/\1\"$alpha_version\"/" examples/extension/build.gradle
2323
sed -Ei "s/(io.opentelemetry.instrumentation.muzzle-check\" version )\"[^\"]*\"/\1\"$alpha_version\"/" examples/extension/build.gradle
24+
25+
sed -Ei "1 s/(Comparing source compatibility of [a-z-]+)-[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?.jar/\1-$version.jar/" docs/apidiffs/current_vs_latest/*.txt

CHANGELOG.md

+49
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22

33
## Unreleased
44

5+
## Version 2.8.0 (2024-09-13)
6+
7+
### Migration notes
8+
9+
- The unit on the opt-in Java 17 JFR-based metrics was updated from milliseconds to seconds
10+
to conform with the semantic conventions.
11+
If you are using the Java agent, this only affects you if you are opting in via
12+
`otel.instrumentation.runtime-telemetry-java17.enable-all=true`.
13+
([#12084](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12084),
14+
[#12244](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12244))
15+
16+
### 📈 Enhancements
17+
18+
- Update Pulsar instrumentation to work with next Pulsar release
19+
([#11648](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/11648))
20+
- Capture `network.peer.address` in OkHttp 3.0 instrumentation
21+
([#12012](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12012))
22+
- Add support for CXF 4.0 JAX-WS
23+
([#12077](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12077))
24+
- Add rules for capturing Apache Camel metrics exposed by JMX MBeans
25+
([#11901](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/11901))
26+
- Make RocketMQ span status extractor delegate to the default extractor
27+
([#12183](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12183))
28+
- Bridge log body any value
29+
([#12204](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12204))
30+
- Add declarative config support for resource providers
31+
([#12144](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12144))
32+
33+
### 🛠️ Bug fixes
34+
35+
- Fix Javaagent doesn't work with `java.net.spi.InetAddressResolverProvider`
36+
([#11987](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/11987))
37+
- Fix Oracle UCP 11 metrics not emitted
38+
([#12052](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12052))
39+
- Fix wrong database info captured while using Apache ShardingSphere
40+
([#12066](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12066))
41+
- Fix RabbitMQ NullPointerException
42+
([#12109](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12109))
43+
- Fix possible `NullPointerException` in Play instrumentation
44+
([#12121](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12121))
45+
- Fix error span status for successful requests in Ktor
46+
([#12161](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12161))
47+
- Make OpenTelemetryHandlerMappingFilter handle exceptions from `ServletRequestPathUtils.parseAndCache()`
48+
([#12221](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12221))
49+
- Fix tracing CoroutineCrudRepository.findById
50+
([#12131](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12131))
51+
- Fix capturing context in log4j library instrumentation with async logger
52+
([#12176](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12176))
53+
554
## Version 1.33.6 (2024-08-26)
655

756
### 📈 Enhancements

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
<img alt="Build Status" src="https://img.shields.io/github/actions/workflow/status/open-telemetry/opentelemetry-java-instrumentation/build.yml?branch=main&style=for-the-badge">
1616
</a>
1717
<a href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases">
18-
<img alt="GitHub release (latest by date including pre-releases)" src="https://img.shields.io/github/v/release/open-telemetry/opentelemetry-java-instrumentation?include_prereleases&style=for-the-badge">
18+
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/open-telemetry/opentelemetry-java-instrumentation?style=for-the-badge">
1919
</a>
20-
<img alt="Beta" src="https://img.shields.io/badge/status-beta-informational?style=for-the-badge&logo=data:image/png;base64,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">
2120
</p>
2221

2322
<p align="center">
@@ -67,6 +66,13 @@ This package includes the instrumentation agent as well as
6766
instrumentations for all supported libraries and all available data exporters.
6867
The package provides a completely automatic, out-of-the-box experience.
6968

69+
*Note: There are 2.x releases and 1.x releases. The 2.0 release included significant breaking
70+
changes, the details of which can be found in the [release notes](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/tag/v2.0.0).
71+
It is recommended to use the latest 2.x release which will have the latest features and improvements.
72+
1.x will receive security patches for a limited time and will not include other bug fixes and
73+
enhancements.*
74+
75+
7076
Enable the instrumentation agent using the `-javaagent` flag to the JVM.
7177

7278
```
@@ -154,7 +160,6 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
154160

155161
Triagers ([@open-telemetry/java-instrumentation-triagers](https://github.com/orgs/open-telemetry/teams/java-instrumentation-triagers)):
156162

157-
- [Jay DeLuca](https://github.com/jaydeluca)
158163
- [Jonas Kunz](https://github.com/JonasKunz), Elastic
159164
- [Steve Rao](https://github.com/steverao), Alibaba
160165
- [Sylvain Juge](https://github.com/SylvainJuge), Elastic
@@ -164,6 +169,7 @@ Approvers ([@open-telemetry/java-instrumentation-approvers](https://github.com/o
164169
- [Gregor Zietlinger](https://github.com/zeitlinger), Grafana
165170
- [Jack Berg](https://github.com/jack-berg), New Relic
166171
- [Jason Plumb](https://github.com/breedx-splk), Splunk
172+
- [Jay DeLuca](https://github.com/jaydeluca)
167173
- [Jean Bisutti](https://github.com/jeanbisutti), Microsoft
168174
- [John Watson](https://github.com/jkwatson), Verta.ai
169175

dependencyManagement/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ val groovyVersion = "4.0.23"
2828

2929
val DEPENDENCY_BOMS = listOf(
3030
"com.fasterxml.jackson:jackson-bom:2.17.2",
31-
"com.squareup.okio:okio-bom:3.9.0", // see https://github.com/open-telemetry/opentelemetry-java/issues/5637
31+
"com.squareup.okio:okio-bom:3.9.1", // see https://github.com/open-telemetry/opentelemetry-java/issues/5637
3232
"com.google.guava:guava-bom:33.3.0-jre",
3333
"org.apache.groovy:groovy-bom:${groovyVersion}",
3434
"io.opentelemetry:opentelemetry-bom:${otelSdkVersion}",
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-instrumentation-annotations-2.8.0-SNAPSHOT.jar against opentelemetry-instrumentation-annotations-2.7.0.jar
1+
Comparing source compatibility of opentelemetry-instrumentation-annotations-2.9.0-SNAPSHOT.jar against opentelemetry-instrumentation-annotations-2.8.0.jar
22
No changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-instrumentation-api-2.8.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.7.0.jar
1+
Comparing source compatibility of opentelemetry-instrumentation-api-2.9.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.8.0.jar
22
No changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.8.0-SNAPSHOT.jar against opentelemetry-spring-boot-autoconfigure-2.7.0.jar
1+
Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.9.0-SNAPSHOT.jar against opentelemetry-spring-boot-autoconfigure-2.8.0.jar
22
No changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-spring-boot-starter-2.8.0-SNAPSHOT.jar against opentelemetry-spring-boot-starter-2.7.0.jar
1+
Comparing source compatibility of opentelemetry-spring-boot-starter-2.9.0-SNAPSHOT.jar against opentelemetry-spring-boot-starter-2.8.0.jar
22
No changes.

examples/distro/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
dependencies {
1515
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
1616
classpath "com.gradleup.shadow:shadow-gradle-plugin:8.3.1"
17-
classpath "io.opentelemetry.instrumentation:gradle-plugins:2.8.0-alpha-SNAPSHOT"
17+
classpath "io.opentelemetry.instrumentation:gradle-plugins:2.9.0-alpha-SNAPSHOT"
1818
}
1919
}
2020

@@ -30,8 +30,8 @@ subprojects {
3030
opentelemetrySdk : "1.42.1",
3131

3232
// these lines are managed by .github/scripts/update-version.sh
33-
opentelemetryJavaagent : "2.8.0-SNAPSHOT",
34-
opentelemetryJavaagentAlpha: "2.8.0-alpha-SNAPSHOT",
33+
opentelemetryJavaagent : "2.9.0-SNAPSHOT",
34+
opentelemetryJavaagentAlpha: "2.9.0-alpha-SNAPSHOT",
3535

3636
autoservice : "1.1.1",
3737
junit : "5.11.0"

examples/extension/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ plugins {
1313
id "com.gradleup.shadow" version "8.3.1"
1414
id "com.diffplug.spotless" version "6.25.0"
1515

16-
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.8.0-alpha-SNAPSHOT"
17-
id "io.opentelemetry.instrumentation.muzzle-check" version "2.8.0-alpha-SNAPSHOT"
16+
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.9.0-alpha-SNAPSHOT"
17+
id "io.opentelemetry.instrumentation.muzzle-check" version "2.9.0-alpha-SNAPSHOT"
1818
}
1919

2020
group 'io.opentelemetry.example'
@@ -26,8 +26,8 @@ ext {
2626
opentelemetrySdk : "1.42.1",
2727

2828
// these lines are managed by .github/scripts/update-version.sh
29-
opentelemetryJavaagent : "2.8.0-SNAPSHOT",
30-
opentelemetryJavaagentAlpha: "2.8.0-alpha-SNAPSHOT",
29+
opentelemetryJavaagent : "2.9.0-SNAPSHOT",
30+
opentelemetryJavaagentAlpha: "2.9.0-alpha-SNAPSHOT",
3131

3232
junit : "5.11.0"
3333
]

instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerInstrumentationModule.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import java.util.List;
1516
import net.bytebuddy.matcher.ElementMatcher;
1617

1718
@AutoService(InstrumentationModule.class)
18-
public class AkkaHttpServerInstrumentationModule extends InstrumentationModule {
19+
public class AkkaHttpServerInstrumentationModule extends InstrumentationModule
20+
implements ExperimentalInstrumentationModule {
1921
public AkkaHttpServerInstrumentationModule() {
2022
super("akka-http", "akka-http-10.0", "akka-http-server");
2123
}
2224

25+
@Override
26+
public String getModuleGroup() {
27+
return "akka-http";
28+
}
29+
2330
@Override
2431
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
2532
// in GraphInterpreterInstrumentation we instrument a class that belongs to akka-streams, make
2633
// sure this runs only when akka-http is present to avoid muzzle failures
2734
return hasClassesNamed("akka.http.scaladsl.HttpExt");
2835
}
2936

30-
@Override
31-
public boolean isIndyModule() {
32-
// AkkaHttpServerInstrumentationModule and AkkaHttpServerRouteInstrumentationModule share
33-
// AkkaRouteHolder class
34-
return false;
35-
}
36-
3737
@Override
3838
public List<TypeInstrumentation> typeInstrumentations() {
3939
return asList(

instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/route/AkkaHttpServerRouteInstrumentationModule.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
import com.google.auto.service.AutoService;
1111
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1212
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
13+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1314
import java.util.List;
1415

1516
/**
1617
* This instrumentation applies to classes in akka-http.jar while
1718
* AkkaHttpServerInstrumentationModule applies to classes in akka-http-core.jar
1819
*/
1920
@AutoService(InstrumentationModule.class)
20-
public class AkkaHttpServerRouteInstrumentationModule extends InstrumentationModule {
21+
public class AkkaHttpServerRouteInstrumentationModule extends InstrumentationModule
22+
implements ExperimentalInstrumentationModule {
2123
public AkkaHttpServerRouteInstrumentationModule() {
2224
super("akka-http", "akka-http-10.0", "akka-http-server", "akka-http-server-route");
2325
}
2426

2527
@Override
26-
public boolean isIndyModule() {
27-
// AkkaHttpServerInstrumentationModule and AkkaHttpServerRouteInstrumentationModule share
28-
// AkkaRouteHolder class
29-
return false;
28+
public String getModuleGroup() {
29+
return "akka-http";
3030
}
3131

3232
@Override

instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseClientInstrumentation.java

+10-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
99
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
10-
import static io.opentelemetry.javaagent.instrumentation.clickhouse.ClickHouseSingletons.instrumenter;
1110
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1211
import static net.bytebuddy.matcher.ElementMatchers.named;
1312
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
@@ -17,7 +16,6 @@
1716
import com.clickhouse.client.ClickHouseRequest;
1817
import com.clickhouse.client.config.ClickHouseDefaults;
1918
import io.opentelemetry.context.Context;
20-
import io.opentelemetry.context.Scope;
2119
import io.opentelemetry.javaagent.bootstrap.CallDepth;
2220
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2321
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
@@ -43,19 +41,12 @@ public void transform(TypeTransformer transformer) {
4341
@SuppressWarnings("unused")
4442
public static class ClickHouseExecuteAndWaitAdvice {
4543
@Advice.OnMethodEnter(suppress = Throwable.class)
46-
public static void onEnter(
47-
@Advice.Argument(0) ClickHouseRequest<?> clickHouseRequest,
48-
@Advice.Local("otelContext") Context context,
49-
@Advice.Local("otelScope") Scope scope,
50-
@Advice.Local("otelCallDepth") CallDepth callDepth) {
44+
public static ClickHouseScope onEnter(
45+
@Advice.Argument(0) ClickHouseRequest<?> clickHouseRequest) {
5146

52-
callDepth = CallDepth.forClass(ClickHouseClient.class);
53-
if (callDepth.getAndIncrement() > 0) {
54-
return;
55-
}
56-
57-
if (clickHouseRequest == null) {
58-
return;
47+
CallDepth callDepth = CallDepth.forClass(ClickHouseClient.class);
48+
if (callDepth.getAndIncrement() > 0 || clickHouseRequest == null) {
49+
return null;
5950
}
6051

6152
Context parentContext = currentContext();
@@ -70,32 +61,19 @@ public static void onEnter(
7061
.orElse(ClickHouseDefaults.DATABASE.getDefaultValue().toString()),
7162
clickHouseRequest.getPreparedQuery().getOriginalQuery());
7263

73-
if (!instrumenter().shouldStart(parentContext, request)) {
74-
return;
75-
}
76-
77-
context = instrumenter().start(parentContext, request);
78-
scope = context.makeCurrent();
64+
return ClickHouseScope.start(parentContext, request);
7965
}
8066

8167
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
8268
public static void onExit(
83-
@Advice.Thrown Throwable throwable,
84-
@Advice.Local("otelRequest") ClickHouseDbRequest clickHouseRequest,
85-
@Advice.Local("otelContext") Context context,
86-
@Advice.Local("otelScope") Scope scope,
87-
@Advice.Local("otelCallDepth") CallDepth callDepth) {
88-
89-
if (callDepth.decrementAndGet() > 0) {
90-
return;
91-
}
69+
@Advice.Thrown Throwable throwable, @Advice.Enter ClickHouseScope scope) {
9270

93-
if (scope == null) {
71+
CallDepth callDepth = CallDepth.forClass(ClickHouseClient.class);
72+
if (callDepth.decrementAndGet() > 0 || scope == null) {
9473
return;
9574
}
9675

97-
scope.close();
98-
instrumenter().end(context, clickHouseRequest, null, throwable);
76+
scope.end(throwable);
9977
}
10078
}
10179
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.clickhouse;
7+
8+
import static io.opentelemetry.javaagent.instrumentation.clickhouse.ClickHouseSingletons.instrumenter;
9+
10+
import io.opentelemetry.context.Context;
11+
import io.opentelemetry.context.Scope;
12+
13+
/** Container used to carry state between enter and exit advices */
14+
public final class ClickHouseScope {
15+
private final ClickHouseDbRequest clickHouseDbRequest;
16+
private final Context context;
17+
private final Scope scope;
18+
19+
private ClickHouseScope(ClickHouseDbRequest clickHouseDbRequest, Context context, Scope scope) {
20+
this.clickHouseDbRequest = clickHouseDbRequest;
21+
this.context = context;
22+
this.scope = scope;
23+
}
24+
25+
public static ClickHouseScope start(
26+
Context parentContext, ClickHouseDbRequest clickHouseDbRequest) {
27+
if (!instrumenter().shouldStart(parentContext, clickHouseDbRequest)) {
28+
return null;
29+
}
30+
31+
Context context = instrumenter().start(parentContext, clickHouseDbRequest);
32+
return new ClickHouseScope(clickHouseDbRequest, context, context.makeCurrent());
33+
}
34+
35+
public void end(Throwable throwable) {
36+
scope.close();
37+
instrumenter().end(context, clickHouseDbRequest, null, throwable);
38+
}
39+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
3636
JmxMetricInsight.createService(
3737
GlobalOpenTelemetry.get(), beanDiscoveryDelay(config).toMillis());
3838
MetricConfiguration conf = buildMetricConfiguration(config);
39-
service.start(conf);
39+
service.startLocal(conf);
4040
}
4141
}
4242

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JmxMetricInsightInstallerTest {
3838
@Test
3939
void testToVerifyExistingRulesAreValid() throws Exception {
4040
RuleParser parser = RuleParser.get();
41-
assertThat(parser == null).isFalse();
41+
assertThat(parser).isNotNull();
4242

4343
Path path = Paths.get(PATH_TO_ALL_EXISTING_RULES);
4444
assertThat(Files.exists(path)).isTrue();

0 commit comments

Comments
 (0)