Skip to content
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

Add Android API-friendliness checks #4505

Merged
merged 6 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation("org.ow2.asm:asm-tree:9.1")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
implementation("org.gradle:test-retry-gradle-plugin:1.2.1")
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3")
// When updating, also update dependencyManagement/build.gradle.kts
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.11.22")
implementation("gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`java-library`

id("ru.vyarus.animalsniffer")
}

dependencies {
add("signature", "com.toasttab.android:gummy-bears-api-21:0.3.0:coreLib@signature")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this conventions something like android or android-compatible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't mind - I used otel.animalsniffer-conventions because the SDK file is named the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android-compatibility? (and we can update in SDK repo too)

}

animalsniffer {
sourceSets = listOf(java.sourceSets.main.get())
}
1 change: 1 addition & 0 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("org.xbib.gradle.plugin.jflex")

id("otel.java-conventions")
id("otel.animalsniffer-conventions")
id("otel.jacoco-conventions")
id("otel.japicmp-conventions")
id("otel.publish-conventions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,40 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nullable;

final class JdkErrorCauseExtractor implements ErrorCauseExtractor {
static final ErrorCauseExtractor INSTANCE = new JdkErrorCauseExtractor();

@Nullable
private static final Class<?> COMPLETION_EXCEPTION_CLASS = getCompletionExceptionClass();

@Override
public Throwable extractCause(Throwable error) {
if (error.getCause() != null
&& (error instanceof ExecutionException
|| error instanceof CompletionException
|| isInstanceOfCompletionException(error)
|| error instanceof InvocationTargetException
|| error instanceof UndeclaredThrowableException)) {
return extractCause(error.getCause());
}
return error;
}

private static boolean isInstanceOfCompletionException(Throwable error) {
return COMPLETION_EXCEPTION_CLASS != null && COMPLETION_EXCEPTION_CLASS.isInstance(error);
}

@Nullable
private static Class<?> getCompletionExceptionClass() {
try {
return Class.forName("java.util.concurrent.CompletionException");
} catch (ClassNotFoundException e) {
// Android level 21 does not support java.util.concurrent.CompletionException
return null;
}
}

private JdkErrorCauseExtractor() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/**
* Base class for all instrumentation specific tracer implementations.
Expand All @@ -48,6 +48,9 @@
public abstract class BaseTracer {
private static final SupportabilityMetrics supportability = SupportabilityMetrics.instance();

@Nullable
private static final Class<?> COMPLETION_EXCEPTION_CLASS = getCompletionExceptionClass();

private final Tracer tracer;
private final ContextPropagators propagators;

Expand Down Expand Up @@ -242,7 +245,7 @@ public void onException(Context context, Throwable throwable) {
protected Throwable unwrapThrowable(Throwable throwable) {
if (throwable.getCause() != null
&& (throwable instanceof ExecutionException
|| throwable instanceof CompletionException
|| isInstanceOfCompletionException(throwable)
|| throwable instanceof InvocationTargetException
|| throwable instanceof UndeclaredThrowableException)) {
return unwrapThrowable(throwable.getCause());
Expand Down Expand Up @@ -283,4 +286,18 @@ public <C> Context extract(C carrier, TextMapGetter<C> getter) {
public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) {
propagators.getTextMapPropagator().inject(context, carrier, setter);
}

private static boolean isInstanceOfCompletionException(Throwable error) {
return COMPLETION_EXCEPTION_CLASS != null && COMPLETION_EXCEPTION_CLASS.isInstance(error);
}

@Nullable
private static Class<?> getCompletionExceptionClass() {
try {
return Class.forName("java.util.concurrent.CompletionException");
} catch (ClassNotFoundException e) {
// Android level 21 does not support java.util.concurrent.CompletionException
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
id("otel.animalsniffer-conventions")
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions instrumentation/grpc-1.6/library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.library-instrumentation")
id("otel.animalsniffer-conventions")
}

val grpcVersion = "1.6.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
id("otel.animalsniffer-conventions")
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pluginManagement {
id("org.xbib.gradle.plugin.jflex") version "1.5.0"
id("nebula.release") version "15.3.1"
id("com.github.johnrengelman.shadow") version "7.0.0"
id("ru.vyarus.animalsniffer") version "1.5.3"
}
}

Expand Down