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

Fix generic parameters for SampleTestRunner #24

Merged
merged 1 commit into from
May 16, 2022
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
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def VERSIONS = [
]

def PLATFORM_VERSIONS = [
'io.micrometer:micrometer-bom:1.10.0-M2',
'io.micrometer:micrometer-bom:1.10.0-SNAPSHOT',
'io.zipkin.brave:brave-bom:5.13.+',
// opentelemetry-instrumentation-api dependency above with this
'io.opentelemetry:opentelemetry-bom:1.+',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
* @author Marcin Grzejszczak
* @since 1.0.0
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class DefaultTracingObservationHandler implements TracingObservationHandler {
public class DefaultTracingObservationHandler implements TracingObservationHandler<Observation.Context> {

private final Tracer tracer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
* @param <T> type of handler context
* @since 1.0.0
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public interface TracingObservationHandler<T extends Observation.Context>
extends ObservationHandler<T> {
public interface TracingObservationHandler<T extends Observation.Context> extends ObservationHandler<T> {

/**
* Tags the span.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public abstract class SampleTestRunner {

private MeterRegistry meterRegistry;

private final List<ObservationHandler<?>> observationHandlersCopy;
private final List<ObservationHandler<? extends Observation.Context>> observationHandlersCopy;

/**
* Creates a new instance of the {@link SampleTestRunner} with a pre-created configuration and {@link MeterRegistry}.
Expand Down Expand Up @@ -219,7 +219,7 @@ public interface SampleTestRunnerConsumer {
* @return timer recording handler customizing function
*/
@SuppressWarnings("rawtypes")
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizeObservationHandlers() {
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizeObservationHandlers() {
return (tracer, ObservationHandlers) -> {

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public interface BuildingBlocks {
*
* @return customizers
*/
BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> getCustomizers();
BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> getCustomizers();

/**
* Returns a list of finished spans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.micrometer.tracing.test.reporter.inmemory;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -110,9 +109,9 @@ public static class Builder {

private Function<HttpTracing, HttpClientHandler> httpClientHandler;

private Function<BraveBuildingBlocks, ObservationHandler> handlers;
private Function<BraveBuildingBlocks, ObservationHandler<? extends Observation.Context>> handlers;

private BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers;
private BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers;

private Consumer<BraveBuildingBlocks> closingFunction;

Expand All @@ -133,11 +132,11 @@ public static class BraveBuildingBlocks implements BuildingBlocks {

public final HttpClientHandler httpClientHandler;

public final BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers;
public final BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers;

private final TestSpanHandler testSpanHandler;

public BraveBuildingBlocks(Tracing tracing, Tracer tracer, BravePropagator propagator, HttpTracing httpTracing, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers, TestSpanHandler testSpanHandler) {
public BraveBuildingBlocks(Tracing tracing, Tracer tracer, BravePropagator propagator, HttpTracing httpTracing, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers, TestSpanHandler testSpanHandler) {
this.tracing = tracing;
this.tracer = tracer;
this.propagator = propagator;
Expand Down Expand Up @@ -169,7 +168,7 @@ public HttpClientHandler getHttpClientHandler() {
}

@Override
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> getCustomizers() {
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> getCustomizers() {
return this.customizers;
}

Expand Down Expand Up @@ -209,7 +208,7 @@ public Builder httpTracing(Function<Tracing, HttpTracing> httpTracing) {
return this;
}

public Builder observationHandlerCustomizer(BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers) {
public Builder observationHandlerCustomizer(BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers) {
this.customizers = customizers;
return this;
}
Expand All @@ -224,7 +223,7 @@ public Builder httpClientHandler(Function<HttpTracing, HttpClientHandler> httpCl
return this;
}

public Builder handlers(Function<BraveBuildingBlocks, ObservationHandler> tracingHandlers) {
public Builder handlers(Function<BraveBuildingBlocks, ObservationHandler<? extends Observation.Context>> tracingHandlers) {
this.handlers = tracingHandlers;
return this;
}
Expand All @@ -247,10 +246,10 @@ public InMemoryBraveSetup register(ObservationRegistry registry) {
HttpTracing httpTracing = this.httpTracing != null ? this.httpTracing.apply(tracing) : httpTracing(tracing);
HttpServerHandler httpServerHandler = this.httpServerHandler != null ? this.httpServerHandler.apply(httpTracing) : httpServerHandler(httpTracing);
HttpClientHandler httpClientHandler = this.httpClientHandler != null ? this.httpClientHandler.apply(httpTracing) : httpClientHandler(httpTracing);
BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers = this.customizers != null ? this.customizers : (t, h) -> {
BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers = this.customizers != null ? this.customizers : (t, h) -> {
};
BraveBuildingBlocks braveBuildingBlocks = new BraveBuildingBlocks(tracing, tracer, new BravePropagator(tracing), httpTracing, httpServerHandler, httpClientHandler, customizers, testSpanHandler);
ObservationHandler tracingHandlers = this.handlers != null ? this.handlers.apply(braveBuildingBlocks) : tracingHandlers(braveBuildingBlocks);
ObservationHandler<? extends Observation.Context> tracingHandlers = this.handlers != null ? this.handlers.apply(braveBuildingBlocks) : tracingHandlers(braveBuildingBlocks);
registry.observationConfig().observationHandler(tracingHandlers);
Consumer<BraveBuildingBlocks> closingFunction = this.closingFunction != null ? this.closingFunction : closingFunction();
return new InMemoryBraveSetup(closingFunction, braveBuildingBlocks);
Expand Down Expand Up @@ -288,12 +287,16 @@ private static Consumer<BraveBuildingBlocks> closingFunction() {
}

@SuppressWarnings("rawtypes")
private static ObservationHandler tracingHandlers(BraveBuildingBlocks braveBuildingBlocks) {
private static ObservationHandler<Observation.Context> tracingHandlers(BraveBuildingBlocks braveBuildingBlocks) {
Tracer tracer = braveBuildingBlocks.tracer;
HttpServerHandler httpServerHandler = braveBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = braveBuildingBlocks.httpClientHandler;
LinkedList<ObservationHandler<Observation.Context>> handlers = new LinkedList(Arrays.asList(new HttpServerTracingObservationHandler(tracer, httpServerHandler), new HttpClientTracingObservationHandler(tracer, httpClientHandler), new DefaultTracingObservationHandler(tracer)));
LinkedList<ObservationHandler<? extends Observation.Context>> handlers = new LinkedList<>();
handlers.add(new HttpServerTracingObservationHandler(tracer, httpServerHandler));
handlers.add(new HttpClientTracingObservationHandler(tracer, httpClientHandler));
handlers.add(new DefaultTracingObservationHandler(tracer));
braveBuildingBlocks.customizers.accept(braveBuildingBlocks, handlers);

return new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.micrometer.tracing.test.reporter.inmemory;

import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
Expand Down Expand Up @@ -109,13 +108,13 @@ public static class Builder {

private Function<Tracer, OtelTracer> otelTracer;

private BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers;
private BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers;

private Function<OpenTelemetrySdk, HttpServerHandler> httpServerHandler;

private Function<OpenTelemetrySdk, HttpClientHandler> httpClientHandler;

private Function<OtelBuildingBlocks, ObservationHandler> handlers;
private Function<OtelBuildingBlocks, ObservationHandler<? extends Observation.Context>> handlers;

private Consumer<OtelBuildingBlocks> closingFunction;

Expand All @@ -138,11 +137,11 @@ public static class OtelBuildingBlocks implements BuildingBlocks {

public final HttpClientHandler httpClientHandler;

public final BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers;
public final BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers;

private final ArrayListSpanProcessor arrayListSpanProcessor;

public OtelBuildingBlocks(SdkTracerProvider sdkTracerProvider, OpenTelemetrySdk openTelemetrySdk, Tracer tracer, OtelTracer otelTracer, OtelPropagator propagator, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers, ArrayListSpanProcessor arrayListSpanProcessor) {
public OtelBuildingBlocks(SdkTracerProvider sdkTracerProvider, OpenTelemetrySdk openTelemetrySdk, Tracer tracer, OtelTracer otelTracer, OtelPropagator propagator, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers, ArrayListSpanProcessor arrayListSpanProcessor) {
this.sdkTracerProvider = sdkTracerProvider;
this.openTelemetrySdk = openTelemetrySdk;
this.tracer = tracer;
Expand Down Expand Up @@ -170,7 +169,7 @@ public HttpClientHandler getHttpClientHandler() {
}

@Override
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> getCustomizers() {
public BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> getCustomizers() {
return this.customizers;
}

Expand Down Expand Up @@ -210,7 +209,7 @@ public Builder otelTracer(Function<Tracer, OtelTracer> otelTracer) {
return this;
}

public Builder observationHandlerCustomizer(BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers) {
public Builder observationHandlerCustomizer(BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers) {
this.customizers = customizers;
return this;
}
Expand All @@ -225,7 +224,7 @@ public Builder httpClientHandler(Function<OpenTelemetrySdk, HttpClientHandler> h
return this;
}

public Builder handlers(Function<OtelBuildingBlocks, ObservationHandler> tracingHandlers) {
public Builder handlers(Function<OtelBuildingBlocks, ObservationHandler<? extends Observation.Context>> tracingHandlers) {
this.handlers = tracingHandlers;
return this;
}
Expand All @@ -249,10 +248,10 @@ public InMemoryOtelSetup register(ObservationRegistry registry) {
OtelTracer otelTracer = this.otelTracer != null ? this.otelTracer.apply(tracer) : otelTracer(tracer);
HttpServerHandler httpServerHandler = this.httpServerHandler != null ? this.httpServerHandler.apply(openTelemetrySdk) : httpServerHandler(openTelemetrySdk);
HttpClientHandler httpClientHandler = this.httpClientHandler != null ? this.httpClientHandler.apply(openTelemetrySdk) : httpClientHandler(openTelemetrySdk);
BiConsumer<BuildingBlocks, Deque<ObservationHandler<Observation.Context>>> customizers = this.customizers != null ? this.customizers : (t, h) -> {
BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers = this.customizers != null ? this.customizers : (t, h) -> {
};
OtelBuildingBlocks otelBuildingBlocks = new OtelBuildingBlocks(sdkTracerProvider, openTelemetrySdk, tracer, otelTracer, new OtelPropagator(propagators(Collections.singletonList(B3Propagator.injectingMultiHeaders())), tracer), httpServerHandler, httpClientHandler, customizers, arrayListSpanProcessor);
ObservationHandler tracingHandlers = this.handlers != null ? this.handlers.apply(otelBuildingBlocks) : tracingHandlers(otelBuildingBlocks);
ObservationHandler<? extends Observation.Context> tracingHandlers = this.handlers != null ? this.handlers.apply(otelBuildingBlocks) : tracingHandlers(otelBuildingBlocks);
registry.observationConfig().observationHandler(tracingHandlers);
Consumer<OtelBuildingBlocks> closingFunction = this.closingFunction != null ? this.closingFunction : closingFunction();
return new InMemoryOtelSetup(closingFunction, otelBuildingBlocks);
Expand Down Expand Up @@ -300,12 +299,17 @@ private static Consumer<OtelBuildingBlocks> closingFunction() {
}

@SuppressWarnings("rawtypes")
private static ObservationHandler tracingHandlers(OtelBuildingBlocks otelBuildingBlocks) {
private static ObservationHandler<Observation.Context> tracingHandlers(OtelBuildingBlocks otelBuildingBlocks) {
OtelTracer tracer = otelBuildingBlocks.otelTracer;
HttpServerHandler httpServerHandler = otelBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = otelBuildingBlocks.httpClientHandler;
LinkedList<ObservationHandler<Observation.Context>> handlers = new LinkedList(Arrays.asList(new HttpServerTracingObservationHandler(tracer, httpServerHandler), new HttpClientTracingObservationHandler(tracer, httpClientHandler), new DefaultTracingObservationHandler(tracer)));

LinkedList<ObservationHandler<? extends Observation.Context>> handlers = new LinkedList<>();
handlers.add(new HttpServerTracingObservationHandler(tracer, httpServerHandler));
handlers.add(new HttpClientTracingObservationHandler(tracer, httpClientHandler));
handlers.add(new DefaultTracingObservationHandler(tracer));
otelBuildingBlocks.customizers.accept(otelBuildingBlocks, handlers);

return new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers);
}

Expand Down
Loading