-
Notifications
You must be signed in to change notification settings - Fork 989
ClickHouse client v0.8 instrumentation #14501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9cf7c6f
support ClickHouse Client v2
mznet c16c75c
update clickhouse-client to 0.8
mznet 6fa8042
delete useless ClickHouseClientV2ExampleData.java
mznet 5b44e25
get error response from ServerException
mznet a243942
update fossa and supported-libraries.md
mznet 1b1d794
rename clickhouse-client-0.8 to clickhouse-clientv2-0.8
mznet f466ba7
Merge branch 'main' into clickhouse-client-v0.8
mznet 3f4d8c7
move the advices into instrumentation
mznet ff22d97
add comment says only one endpoint is supported
mznet 1dc624c
Update instrumentation/clickhouse/clickhouse-clientv2-0.8/javaagent/b…
mznet 5bdd827
review
laurit ba7169a
review
laurit 08c457e
Merge branch 'main' into clickhouse-client-v0.8
laurit f6f4ab8
update fossaa config
laurit 7194f3b
fix instrumentation name
laurit 294446c
rename metaDataConfig to metadataConfig
mznet 53a2b43
Merge branch 'main' into clickhouse-client-v0.8
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
80 changes: 0 additions & 80 deletions
80
...o/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseClientInstrumentation.java
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseSingletons.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
.../javaagent/instrumentation/clickhouse/client/v0_5/ClickHouseClientV1AttributesGetter.java
This file contains hidden or 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,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.clickhouse.client.v0_5; | ||
|
||
import com.clickhouse.client.ClickHouseException; | ||
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseAttributesGetter; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseDbRequest; | ||
import javax.annotation.Nullable; | ||
|
||
public final class ClickHouseClientV1AttributesGetter extends ClickHouseAttributesGetter | ||
implements DbClientAttributesGetter<ClickHouseDbRequest, Void> { | ||
|
||
public static ClickHouseClientV1AttributesGetter create() { | ||
return new ClickHouseClientV1AttributesGetter(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) { | ||
if (error instanceof ClickHouseException) { | ||
return Integer.toString(((ClickHouseException) error).getErrorCode()); | ||
} | ||
return null; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...aagent/instrumentation/clickhouse/client/v0_5/ClickHouseClientV1ExecuteAndWaitAdvice.java
This file contains hidden or 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,63 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.clickhouse.client.v0_5; | ||
|
||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; | ||
|
||
import com.clickhouse.client.ClickHouseClient; | ||
import com.clickhouse.client.ClickHouseRequest; | ||
import com.clickhouse.client.ClickHouseRequestAccess; | ||
import com.clickhouse.client.config.ClickHouseDefaults; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.javaagent.bootstrap.CallDepth; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseDbRequest; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseScope; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@SuppressWarnings("unused") | ||
public class ClickHouseClientV1ExecuteAndWaitAdvice { | ||
laurit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static ClickHouseScope onEnter( | ||
@Advice.Argument(0) ClickHouseRequest<?> clickHouseRequest) { | ||
Instrumenter<ClickHouseDbRequest, Void> instrumenter = | ||
ClickHouseClientV1Singletons.instrumenter(); | ||
|
||
CallDepth callDepth = CallDepth.forClass(ClickHouseClient.class); | ||
if (callDepth.getAndIncrement() > 0 || clickHouseRequest == null) { | ||
return null; | ||
} | ||
|
||
Context parentContext = currentContext(); | ||
|
||
ClickHouseDbRequest request = | ||
ClickHouseDbRequest.create( | ||
clickHouseRequest.getServer().getHost(), | ||
clickHouseRequest.getServer().getPort(), | ||
clickHouseRequest | ||
.getServer() | ||
.getDatabase() | ||
.orElse(ClickHouseDefaults.DATABASE.getDefaultValue().toString()), | ||
ClickHouseRequestAccess.getQuery(clickHouseRequest)); | ||
|
||
return ClickHouseScope.start(instrumenter, parentContext, request); | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void onExit( | ||
@Advice.Thrown Throwable throwable, @Advice.Enter ClickHouseScope scope) { | ||
|
||
Instrumenter<ClickHouseDbRequest, Void> instrumenter = | ||
ClickHouseClientV1Singletons.instrumenter(); | ||
|
||
CallDepth callDepth = CallDepth.forClass(ClickHouseClient.class); | ||
if (callDepth.decrementAndGet() > 0 || scope == null) { | ||
return; | ||
} | ||
|
||
scope.end(instrumenter, throwable); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...y/javaagent/instrumentation/clickhouse/client/v0_5/ClickHouseClientV1Instrumentation.java
This file contains hidden or 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,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.clickhouse.client.v0_5; | ||
|
||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class ClickHouseClientV1Instrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return implementsInterface(named("com.clickhouse.client.ClickHouseClient")); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod() | ||
.and(namedOneOf("executeAndWait", "execute")) | ||
.and(takesArgument(0, named("com.clickhouse.client.ClickHouseRequest"))), | ||
"io.opentelemetry.javaagent.instrumentation.clickhouse.client.v0_5.ClickHouseClientV1ExecuteAndWaitAdvice"); | ||
} | ||
} |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
...emetry/javaagent/instrumentation/clickhouse/client/v0_5/ClickHouseClientV1Singletons.java
This file contains hidden or 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,28 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.clickhouse.client.v0_5; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseDbRequest; | ||
import io.opentelemetry.javaagent.instrumentation.clickhouse.common.ClickHouseInstrumenterFactory; | ||
|
||
public final class ClickHouseClientV1Singletons { | ||
|
||
private static final String INSTRUMENTER_NAME = "io.opentelemetry.clickhouse-client-0.5"; | ||
private static final Instrumenter<ClickHouseDbRequest, Void> INSTRUMENTER; | ||
|
||
static { | ||
INSTRUMENTER = | ||
ClickHouseInstrumenterFactory.createInstrumenter( | ||
INSTRUMENTER_NAME, ClickHouseClientV1AttributesGetter.create()); | ||
} | ||
|
||
public static Instrumenter<ClickHouseDbRequest, Void> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private ClickHouseClientV1Singletons() {} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.