Skip to content

Commit 8de9ca4

Browse files
xiangtianyuotelbot[bot]laurit
authored
Fix context propagation for guava AsyncEventBus (open-telemetry#14791)
Co-authored-by: otelbot <[email protected]> Co-authored-by: Lauri Tulmin <[email protected]>
1 parent a548f7e commit 8de9ca4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.guava.v10_0;
7+
8+
import com.google.common.eventbus.AsyncEventBus;
9+
import com.google.common.eventbus.Subscribe;
10+
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
11+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
12+
import java.util.concurrent.ExecutorService;
13+
import java.util.concurrent.Executors;
14+
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.extension.RegisterExtension;
16+
17+
class AsyncEventBusTest {
18+
19+
@RegisterExtension
20+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
21+
22+
static final ExecutorService executor = Executors.newSingleThreadExecutor();
23+
static final AsyncEventBus asyncEventBus = new AsyncEventBus(executor);
24+
25+
@Test
26+
void contextPropagation() {
27+
class Listener {
28+
29+
@Subscribe
30+
public void onEvent(String event) {
31+
testing.runWithSpan("listener", () -> {});
32+
}
33+
}
34+
35+
asyncEventBus.register(new Listener());
36+
37+
testing.runWithSpan("parent", () -> asyncEventBus.post("test"));
38+
39+
testing.waitAndAssertTraces(
40+
trace ->
41+
trace.hasSpansSatisfyingExactly(
42+
span -> span.hasName("parent"), span -> span.hasName("listener")));
43+
}
44+
}

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/ignore/AdditionalLibraryIgnoredTypesConfigurer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ public void configure(IgnoredTypesBuilder builder) {
250250
.ignoreClass("com.google.common.")
251251
.allowClass("com.google.common.util.concurrent.")
252252
.allowClass("com.google.common.base.internal.Finalizer")
253-
.allowClass("com.google.common.base.Java8Usage$$Lambda");
253+
.allowClass("com.google.common.base.Java8Usage$$Lambda")
254+
.allowClass("com.google.common.eventbus.Subscriber$");
254255

255256
builder
256257
.ignoreClass("com.google.inject.")

0 commit comments

Comments
 (0)