Skip to content

Commit

Permalink
Merge pull request quarkusio#40068 from geoand/markers
Browse files Browse the repository at this point in the history
Introduce markers for static and runtime init recorder methods
  • Loading branch information
geoand authored Apr 15, 2024
2 parents 8bd1c82 + 43e92f3 commit 6139e8a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.runtime.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marker annotation used to indicate that a recorder method is called during the runtime init phase
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface RuntimeInit {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.runtime.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marker annotation used to indicate that a recorder method is called during the static init phase
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface StaticInit {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.annotations.RuntimeInit;
import io.quarkus.runtime.annotations.StaticInit;
import io.quarkus.runtime.configuration.DurationConverter;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.SmallRyeConfig;
Expand All @@ -30,23 +32,23 @@ public class OpenTelemetryRecorder {

public static final String OPEN_TELEMETRY_DRIVER = "io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver";

/* STATIC INIT */
@StaticInit
public void resetGlobalOpenTelemetryForDevMode() {
GlobalOpenTelemetry.resetForTest();
GlobalEventEmitterProvider.resetForTest();
}

/* RUNTIME INIT */
@RuntimeInit
public void eagerlyCreateContextStorage() {
ContextStorage.get();
}

/* RUNTIME INIT */
@RuntimeInit
public void storeVertxOnContextStorage(Supplier<Vertx> vertx) {
QuarkusContextStorage.vertx = vertx.get();
}

/* RUNTIME INIT */
@RuntimeInit
public Function<SyntheticCreationalContext<OpenTelemetry>, OpenTelemetry> opentelemetryBean(
OTelRuntimeConfig oTelRuntimeConfig) {
return new Function<>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import io.opentelemetry.semconv.ResourceAttributes;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.annotations.StaticInit;

@Recorder
public class TracerRecorder {

public static final Set<String> dropNonApplicationUriTargets = new HashSet<>();
public static final Set<String> dropStaticResourceTargets = new HashSet<>();

/* STATIC INIT */
@StaticInit
public void setAttributes(
BeanContainer beanContainer,
String quarkusVersion,
Expand All @@ -35,7 +36,7 @@ public void setAttributes(
.getAttributes());
}

/* STATIC INIT */
@StaticInit
public void setupSampler(
List<String> dropNonApplicationUris,
List<String> dropStaticResources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.vertx.SqlClientInstrumenterVertxTracer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.annotations.RuntimeInit;
import io.vertx.core.VertxOptions;
import io.vertx.core.metrics.MetricsOptions;
import io.vertx.core.tracing.TracingOptions;
Expand All @@ -34,14 +35,15 @@ public InstrumentationRecorder(RuntimeValue<OTelRuntimeConfig> config) {
this.config = config;
}

/* RUNTIME INIT */
@RuntimeInit
public Consumer<VertxOptions> getVertxTracingOptions() {
TracingOptions tracingOptions = new TracingOptions()
.setFactory(FACTORY);
return vertxOptions -> vertxOptions.setTracingOptions(tracingOptions);
}

/* RUNTIME INIT */
@RuntimeInit
public void setupVertxTracer(BeanContainer beanContainer, boolean sqlClientAvailable,
boolean redisClientAvailable, final String semconvStability) {
OpenTelemetry openTelemetry = beanContainer.beanInstance(OpenTelemetry.class);
Expand Down

0 comments on commit 6139e8a

Please sign in to comment.