Skip to content

Commit 0894893

Browse files
chore: propagate otel context in Connection API (#3078)
* chore: propagate otel context in Connection API Use a TaskWrapping executor in the Connection API to propagate the current OpenTelemetry context to the executor thread. This ensures that the context that is used in the end-user application is propagated to the Spanner client library, and tracing shows a full view of the spans from the application to the gRPC layer. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 3804160 commit 0894893

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies:
5050
If you are using Gradle 5.x or later, add this to your dependencies:
5151

5252
```Groovy
53-
implementation platform('com.google.cloud:libraries-bom:26.37.0')
53+
implementation platform('com.google.cloud:libraries-bom:26.38.0')
5454
5555
implementation 'com.google.cloud:google-cloud-spanner'
5656
```

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.common.util.concurrent.ListeningExecutorService;
2929
import com.google.common.util.concurrent.MoreExecutors;
3030
import com.google.protobuf.Duration;
31+
import io.opentelemetry.context.Context;
3132
import java.util.Collections;
3233
import java.util.List;
3334
import java.util.concurrent.Callable;
@@ -147,13 +148,16 @@ org.threeten.bp.Duration asDuration() {
147148
/** Creates an {@link ExecutorService} for a {@link StatementExecutor}. */
148149
private static ListeningExecutorService createExecutorService(boolean useVirtualThreads) {
149150
return MoreExecutors.listeningDecorator(
150-
new ThreadPoolExecutor(
151-
1,
152-
1,
153-
0L,
154-
TimeUnit.MILLISECONDS,
155-
new LinkedBlockingQueue<>(),
156-
useVirtualThreads ? DEFAULT_VIRTUAL_THREAD_FACTORY : DEFAULT_DAEMON_THREAD_FACTORY));
151+
Context.taskWrapping(
152+
new ThreadPoolExecutor(
153+
1,
154+
1,
155+
0L,
156+
TimeUnit.MILLISECONDS,
157+
new LinkedBlockingQueue<>(),
158+
useVirtualThreads
159+
? DEFAULT_VIRTUAL_THREAD_FACTORY
160+
: DEFAULT_DAEMON_THREAD_FACTORY)));
157161
}
158162

159163
private final ListeningExecutorService executor;

0 commit comments

Comments
 (0)