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

Introduce markers for static and runtime init recorder methods #40068

Merged
merged 2 commits into from
Apr 15, 2024
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
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
Copy link
Member

Choose a reason for hiding this comment

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

I'm all for these marker annotations as I agree things have been confusing. But shouldn't have a check then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But shouldn't have a check then?

I am not sure I follow this one. Care to elaborate please?

Copy link
Member

Choose a reason for hiding this comment

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

If we add a marker, I would expect us to check that this recorder method is called at the proper phase and not at runtime init (for this particular example).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I agree, it's on my TODO list for when I have more time (definitely not this week). I wanted however to do this now as otherwise I would completelt forget

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
Loading