-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make clickhouse instrumentation indy compatible (#12181)
- Loading branch information
Showing
2 changed files
with
49 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.clickhouse; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.clickhouse.ClickHouseSingletons.instrumenter; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
|
||
/** Container used to carry state between enter and exit advices */ | ||
public final class ClickHouseScope { | ||
private final ClickHouseDbRequest clickHouseDbRequest; | ||
private final Context context; | ||
private final Scope scope; | ||
|
||
private ClickHouseScope(ClickHouseDbRequest clickHouseDbRequest, Context context, Scope scope) { | ||
this.clickHouseDbRequest = clickHouseDbRequest; | ||
this.context = context; | ||
this.scope = scope; | ||
} | ||
|
||
public static ClickHouseScope start( | ||
Context parentContext, ClickHouseDbRequest clickHouseDbRequest) { | ||
if (!instrumenter().shouldStart(parentContext, clickHouseDbRequest)) { | ||
return null; | ||
} | ||
|
||
Context context = instrumenter().start(parentContext, clickHouseDbRequest); | ||
return new ClickHouseScope(clickHouseDbRequest, context, context.makeCurrent()); | ||
} | ||
|
||
public void end(Throwable throwable) { | ||
scope.close(); | ||
instrumenter().end(context, clickHouseDbRequest, null, throwable); | ||
} | ||
} |