Skip to content

Commit

Permalink
POC for changing the way hub is stored; otel-bootstrap module
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Mar 15, 2024
1 parent 12600f5 commit 05d1cf2
Show file tree
Hide file tree
Showing 20 changed files with 870 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ val upstreamAgent = configurations.create("upstreamAgent") {

dependencies {
bootstrapLibs(projects.sentry)
bootstrapLibs(projects.sentryOpentelemetry.sentryOpentelemetryBootstrap)
javaagentLibs(projects.sentryOpentelemetry.sentryOpentelemetryAgentcustomization)
upstreamAgent(Config.Libs.OpenTelemetry.otelJavaAgent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
exclude(group = "io.opentelemetry")
exclude(group = "io.opentelemetry.javaagent")
}
implementation(projects.sentryOpentelemetry.sentryOpentelemetryBootstrap)

compileOnly(Config.Libs.OpenTelemetry.otelSdk)
compileOnly(Config.Libs.OpenTelemetry.otelExtensionAutoconfigureSpi)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public final class io/sentry/opentelemetry/OtelContextScopeStorage : io/sentry/ScopeStorage {
public fun <init> ()V
public fun close ()V
public fun get ()Lio/sentry/IHub;
public fun set (Lio/sentry/IHub;)Lio/sentry/SentryStorageToken;
}

public final class io/sentry/opentelemetry/SentryContextStorage : io/opentelemetry/context/ContextStorage {
public static final field HUB_KEY Lio/opentelemetry/context/ContextKey;
public fun <init> (Lio/opentelemetry/context/ContextStorage;)V
public fun attach (Lio/opentelemetry/context/Context;)Lio/opentelemetry/context/Scope;
public fun current ()Lio/opentelemetry/context/Context;
}

public final class io/sentry/opentelemetry/SentryContextWrapper : io/opentelemetry/context/Context {
public fun get (Lio/opentelemetry/context/ContextKey;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
public fun with (Lio/opentelemetry/context/ContextKey;Ljava/lang/Object;)Lio/opentelemetry/context/Context;
public static fun wrap (Lio/opentelemetry/context/Context;)Lio/sentry/opentelemetry/SentryContextWrapper;
}

public final class io/sentry/opentelemetry/SentryOtelKeys {
public static final field SENTRY_BAGGAGE_KEY Lio/opentelemetry/context/ContextKey;
public static final field SENTRY_HUB_KEY Lio/opentelemetry/context/ContextKey;
public static final field SENTRY_SCOPES_KEY Lio/opentelemetry/context/ContextKey;
public static final field SENTRY_TRACE_KEY Lio/opentelemetry/context/ContextKey;
public fun <init> ()V
}

public final class io/sentry/opentelemetry/SentryWeakSpanStorage {
public fun getHub (Lio/opentelemetry/api/trace/SpanContext;)Lio/sentry/IHub;
public static fun getInstance ()Lio/sentry/opentelemetry/SentryWeakSpanStorage;
public fun getScopes (Lio/opentelemetry/api/trace/SpanContext;)Lio/sentry/Scopes;
public fun storeHub (Lio/opentelemetry/api/trace/SpanContext;Lio/sentry/IHub;)V
public fun storeScopes (Lio/opentelemetry/api/trace/SpanContext;Lio/sentry/Scopes;)V
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-library`
kotlin("jvm")
jacoco
id(Config.QualityPlugins.errorProne)
id(Config.QualityPlugins.gradleVersions)
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}

dependencies {
compileOnly(projects.sentry)

compileOnly(Config.Libs.OpenTelemetry.otelSdk)

compileOnly(Config.CompileOnly.nopen)
errorprone(Config.CompileOnly.nopenChecker)
errorprone(Config.CompileOnly.errorprone)
compileOnly(Config.CompileOnly.jetbrainsAnnotations)
errorprone(Config.CompileOnly.errorProneNullAway)

// tests
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
testImplementation(Config.TestLibs.awaitility)

testImplementation(Config.Libs.OpenTelemetry.otelSdk)
testImplementation(Config.Libs.OpenTelemetry.otelSemconv)
}

configure<SourceSetContainer> {
test {
java.srcDir("src/test/java")
}
}

jacoco {
toolVersion = Config.QualityPlugins.Jacoco.version
}

tasks.jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(false)
}
}

tasks {
jacocoTestCoverageVerification {
violationRules {
rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } }
}
}
check {
dependsOn(jacocoTestCoverageVerification)
dependsOn(jacocoTestReport)
}
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.sentry")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.sentry.opentelemetry;

import static io.sentry.opentelemetry.SentryOtelKeys.SENTRY_HUB_KEY;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.sentry.IHub;
import io.sentry.ScopeStorage;
import io.sentry.SentryStorageToken;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("MustBeClosedChecker")
public final class OtelContextScopeStorage implements ScopeStorage {

@Override
public SentryStorageToken set(@Nullable IHub hub) {
// TODO use scopes key
Scope otelScope = Context.current().with(SENTRY_HUB_KEY, hub).makeCurrent();
return new OtelContextScopeStorageToken(otelScope);
}

@Override
public @Nullable IHub get() {
return Context.current().get(SENTRY_HUB_KEY);
}

@Override
public void close() {
// TODO can we do something here?
}

static final class OtelContextScopeStorageToken implements SentryStorageToken {

private final @NotNull Scope otelScope;

OtelContextScopeStorageToken(final @NotNull Scope otelScope) {
this.otelScope = otelScope;
}

@Override
public void close() {
otelScope.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.opentelemetry.context.ContextKey;
import io.sentry.Baggage;
import io.sentry.IHub;
import io.sentry.Scopes;
import io.sentry.SentryTraceHeader;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -16,4 +17,5 @@ public final class SentryOtelKeys {
ContextKey.named("sentry.baggage");
public static final @NotNull ContextKey<Scopes> SENTRY_SCOPES_KEY =
ContextKey.named("sentry.scopes");
public static final @NotNull ContextKey<IHub> SENTRY_HUB_KEY = ContextKey.named("sentry.hub");
}

0 comments on commit 05d1cf2

Please sign in to comment.