Skip to content

Commit

Permalink
Sender and receiver propagating observation handlers (#36)
Browse files Browse the repository at this point in the history
* Sender and receiver propagating observation handlers

* Removes all the http related code

* Moved Http* related code to Tracing + removed the HttpHandlers

* Fixed compilation issues

* Fixed wrong generics

* Polish

* Set span kind on the sender span
  • Loading branch information
marcingrzejszczak authored Jul 18, 2022
1 parent 792f336 commit 128e288
Show file tree
Hide file tree
Showing 47 changed files with 750 additions and 401 deletions.
6 changes: 2 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def VERSIONS = [
'org.mockito:mockito-inline:latest.release',
'com.github.tomakehurst:wiremock-jre8-standalone:latest.release',
'org.testcontainers:testcontainers:latest.release',
'org.testcontainers:junit-jupiter:latest.release',
'org.apiguardian:apiguardian-api:latest.release' // to make CI pass
'org.testcontainers:junit-jupiter:latest.release'
]

def PLATFORM_VERSIONS = [
Expand All @@ -33,8 +32,7 @@ def PLATFORM_VERSIONS = [
// opentelemetry-instrumentation-api dependency above with this
'io.opentelemetry:opentelemetry-bom:1.+',
'io.opentelemetry:opentelemetry-bom-alpha:1.+',
'org.junit:junit-bom:5.8.2',
'com.fasterxml.jackson:jackson-bom:2.13.3' // to make CI pass
'org.junit:junit-bom:5.8.2'
]

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
api("io.zipkin.brave:brave-instrumentation-http")
api("io.zipkin.aws:brave-propagation-aws")

testImplementation 'org.apiguardian:apiguardian-api' // to make CI pass
testImplementation 'io.micrometer:micrometer-observation-test'
testImplementation project(':micrometer-tracing-test')
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import io.micrometer.common.util.internal.logging.InternalLogger;
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.observation.transport.http.HttpClientResponse;
import io.micrometer.tracing.http.HttpClientRequest;
import io.micrometer.tracing.http.HttpClientResponse;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.TraceContext;
import io.micrometer.tracing.http.HttpClientHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Collection;
import java.util.Collections;

import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.tracing.http.HttpClientRequest;

/**
* Brave implementation of a {@link HttpClientRequest}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Collection;
import java.util.Collections;

import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.observation.transport.http.HttpClientResponse;
import io.micrometer.tracing.http.HttpClientRequest;
import io.micrometer.tracing.http.HttpClientResponse;

/**
* Brave implementation of a {@link HttpClientResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collections;

import io.micrometer.observation.transport.Kind;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.http.HttpRequest;

/**
* Brave implementation of a {@link HttpRequest}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.micrometer.tracing.brave.bridge;

import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.SpanCustomizer;
import io.micrometer.tracing.TraceContext;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.http.HttpRequestParser;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Collections;

import io.micrometer.observation.transport.Kind;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.http.HttpResponse;

/**
* Brave implementation of a {@link HttpResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.micrometer.tracing.brave.bridge;

import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.tracing.http.HttpResponse;
import io.micrometer.tracing.SpanCustomizer;
import io.micrometer.tracing.TraceContext;
import io.micrometer.tracing.http.HttpResponseParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.micrometer.tracing.brave.bridge;

import io.micrometer.observation.transport.http.HttpServerRequest;
import io.micrometer.observation.transport.http.HttpServerResponse;
import io.micrometer.tracing.http.HttpServerRequest;
import io.micrometer.tracing.http.HttpServerResponse;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.http.HttpServerHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collections;

import io.micrometer.observation.transport.Kind;
import io.micrometer.observation.transport.http.HttpServerRequest;
import io.micrometer.tracing.http.HttpServerRequest;

/**
* Brave implementation of a {@link HttpServerRequest}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Collections;

import io.micrometer.observation.transport.Kind;
import io.micrometer.observation.transport.http.HttpServerRequest;
import io.micrometer.observation.transport.http.HttpServerResponse;
import io.micrometer.tracing.http.HttpServerRequest;
import io.micrometer.tracing.http.HttpServerResponse;

/**
* Brave implementation of a {@link HttpServerResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.micrometer.tracing.brave.bridge;

import brave.sampler.SamplerFunctions;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.SamplerFunction;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Collections;
import java.util.List;

import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.observation.transport.http.HttpClientResponse;
import io.micrometer.tracing.http.HttpClientRequest;
import io.micrometer.tracing.http.HttpClientResponse;
import io.micrometer.common.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.Collections;
import java.util.List;

import io.micrometer.observation.transport.http.HttpServerRequest;
import io.micrometer.observation.transport.http.HttpServerResponse;
import io.micrometer.tracing.http.HttpServerRequest;
import io.micrometer.tracing.http.HttpServerResponse;
import io.micrometer.common.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter;

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

package io.micrometer.tracing.otel.bridge;

import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.http.HttpResponse;
import io.micrometer.common.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;

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

package io.micrometer.tracing.otel.bridge;

import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.common.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import io.micrometer.common.lang.Nullable;
import io.micrometer.common.util.internal.logging.InternalLogger;
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
import io.micrometer.observation.transport.http.HttpClientRequest;
import io.micrometer.observation.transport.http.HttpClientResponse;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.http.HttpClientRequest;
import io.micrometer.tracing.http.HttpClientResponse;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.SamplerFunction;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.TraceContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.micrometer.common.util.internal.logging.InternalLogger;
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
import io.micrometer.common.lang.Nullable;
import io.micrometer.observation.transport.http.HttpServerRequest;
import io.micrometer.observation.transport.http.HttpServerResponse;
import io.micrometer.tracing.http.HttpServerRequest;
import io.micrometer.tracing.http.HttpServerResponse;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.http.HttpRequestParser;
import io.micrometer.tracing.http.HttpResponseParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.micrometer.tracing.otel.bridge;

import io.micrometer.common.util.StringUtils;
import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.observation.transport.http.HttpResponse;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.http.HttpResponse;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.regex.Pattern;

import io.micrometer.observation.transport.http.HttpRequest;
import io.micrometer.tracing.http.HttpRequest;
import io.micrometer.tracing.SamplerFunction;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public abstract class SampleTestRunner {

private MeterRegistry meterRegistry;

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

/**
* Creates a new instance of the {@link SampleTestRunner} with a pre-created configuration and {@link MeterRegistry}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import io.micrometer.tracing.brave.bridge.BraveTracer;
import io.micrometer.tracing.exporter.FinishedSpan;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import io.micrometer.tracing.handler.HttpClientTracingObservationHandler;
import io.micrometer.tracing.handler.HttpServerTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler;
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.propagation.Propagator;
Expand Down Expand Up @@ -337,11 +337,9 @@ private static Consumer<BraveBuildingBlocks> closingFunction() {
@SuppressWarnings("rawtypes")
private static ObservationHandler<Observation.Context> tracingHandlers(BraveBuildingBlocks braveBuildingBlocks) {
Tracer tracer = braveBuildingBlocks.tracer;
HttpServerHandler httpServerHandler = braveBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = braveBuildingBlocks.httpClientHandler;
LinkedList<ObservationHandler<? extends Observation.Context>> handlers = new LinkedList<>();
handlers.add(new HttpServerTracingObservationHandler(tracer, httpServerHandler));
handlers.add(new HttpClientTracingObservationHandler(tracer, httpClientHandler));
handlers.add(new PropagatingSenderTracingObservationHandler<>(tracer, braveBuildingBlocks.propagator));
handlers.add(new PropagatingReceiverTracingObservationHandler<>(tracer, braveBuildingBlocks.propagator));
handlers.add(new DefaultTracingObservationHandler(tracer));
braveBuildingBlocks.customizers.accept(braveBuildingBlocks, handlers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import io.micrometer.tracing.SamplerFunction;
import io.micrometer.tracing.exporter.FinishedSpan;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import io.micrometer.tracing.handler.HttpClientTracingObservationHandler;
import io.micrometer.tracing.handler.HttpServerTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler;
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor;
Expand Down Expand Up @@ -366,12 +366,10 @@ private static Consumer<OtelBuildingBlocks> closingFunction() {
@SuppressWarnings("rawtypes")
private static ObservationHandler<Observation.Context> tracingHandlers(OtelBuildingBlocks otelBuildingBlocks) {
OtelTracer tracer = otelBuildingBlocks.otelTracer;
HttpServerHandler httpServerHandler = otelBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = otelBuildingBlocks.httpClientHandler;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import io.micrometer.tracing.brave.bridge.BraveTracer;
import io.micrometer.tracing.exporter.FinishedSpan;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import io.micrometer.tracing.handler.HttpClientTracingObservationHandler;
import io.micrometer.tracing.handler.HttpServerTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler;
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.reporter.wavefront.WavefrontBraveSpanHandler;
Expand Down Expand Up @@ -419,11 +419,10 @@ private static Consumer<BraveBuildingBlocks> closingFunction() {
@SuppressWarnings("rawtypes")
private static ObservationHandler<Observation.Context> tracingHandlers(BraveBuildingBlocks braveBuildingBlocks) {
Tracer tracer = braveBuildingBlocks.tracer;
HttpServerHandler httpServerHandler = braveBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = braveBuildingBlocks.httpClientHandler;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import io.micrometer.tracing.SamplerFunction;
import io.micrometer.tracing.exporter.FinishedSpan;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import io.micrometer.tracing.handler.HttpClientTracingObservationHandler;
import io.micrometer.tracing.handler.HttpServerTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler;
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler;
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor;
Expand Down Expand Up @@ -158,7 +158,7 @@ public static class OtelBuildingBlocks implements BuildingBlocks {

private final OtelTracer otelTracer;

private final OtelPropagator otelPropagator;
private final OtelPropagator propagator;

private final HttpServerHandler httpServerHandler;

Expand All @@ -173,16 +173,16 @@ public static class OtelBuildingBlocks implements BuildingBlocks {
*
* @param wavefrontOTelSpanHandler span handler
* @param otelTracer otel tracer
* @param otelPropagator otel propagator
* @param propagator otel propagator
* @param httpServerHandler otel http server handler
* @param httpClientHandler otel http client handler
* @param customizers observation customizers
* @param arrayListSpanProcessor array list span processor
*/
public OtelBuildingBlocks(WavefrontOtelSpanHandler wavefrontOTelSpanHandler, OtelTracer otelTracer, OtelPropagator otelPropagator, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers, ArrayListSpanProcessor arrayListSpanProcessor) {
public OtelBuildingBlocks(WavefrontOtelSpanHandler wavefrontOTelSpanHandler, OtelTracer otelTracer, OtelPropagator propagator, HttpServerHandler httpServerHandler, HttpClientHandler httpClientHandler, BiConsumer<BuildingBlocks, Deque<ObservationHandler<? extends Observation.Context>>> customizers, ArrayListSpanProcessor arrayListSpanProcessor) {
this.wavefrontOTelSpanHandler = wavefrontOTelSpanHandler;
this.otelTracer = otelTracer;
this.otelPropagator = otelPropagator;
this.propagator = propagator;
this.httpServerHandler = httpServerHandler;
this.httpClientHandler = httpClientHandler;
this.customizers = customizers;
Expand All @@ -196,7 +196,7 @@ public io.micrometer.tracing.Tracer getTracer() {

@Override
public Propagator getPropagator() {
return this.otelPropagator;
return this.propagator;
}

@Override
Expand Down Expand Up @@ -450,11 +450,10 @@ private static Consumer<OtelBuildingBlocks> closingFunction() {
@SuppressWarnings("rawtypes")
private static ObservationHandler<Observation.Context> tracingHandlers(OtelBuildingBlocks otelBuildingBlocks) {
OtelTracer tracer = otelBuildingBlocks.otelTracer;
HttpServerHandler httpServerHandler = otelBuildingBlocks.httpServerHandler;
HttpClientHandler httpClientHandler = otelBuildingBlocks.httpClientHandler;

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

Expand Down
Loading

0 comments on commit 128e288

Please sign in to comment.