Skip to content

Commit

Permalink
Fixed wrong generics
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jul 18, 2022
1 parent 81871ee commit 0478643
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Marcin Grzejszczak
* @since 1.0.0
*/
public class PropagatingReceiverTracingObservationHandler<T> implements TracingObservationHandler<ReceiverContext<T>> {
public class PropagatingReceiverTracingObservationHandler<T extends ReceiverContext<T>> implements TracingObservationHandler<T> {

private final Tracer tracer;

Expand All @@ -46,7 +46,7 @@ public PropagatingReceiverTracingObservationHandler(Tracer tracer, Propagator pr
}

@Override
public void onStart(ReceiverContext<T> context) {
public void onStart(T context) {
Span.Builder extractedSpan = this.propagator.extract(context.getCarrier(), (carrier, key) -> context.getGetter().get(carrier, key));
extractedSpan.kind(Span.Kind.valueOf(context.getKind().name()));
String name = context.getContextualName() != null ? context.getContextualName() : context.getName();
Expand All @@ -59,17 +59,17 @@ public void onStart(ReceiverContext<T> context) {
* @param builder span builder
* @return span builder
*/
public Span.Builder customizeExtractedSpan(ReceiverContext<T> context, Span.Builder builder) {
public Span.Builder customizeExtractedSpan(T context, Span.Builder builder) {
return builder;
}

@Override
public void onError(ReceiverContext<T> context) {
public void onError(T context) {
context.getError().ifPresent(throwable -> getRequiredSpan(context).error(throwable));
}

@Override
public void onStop(ReceiverContext<T> context) {
public void onStop(T context) {
Span span = getRequiredSpan(context);
tagSpan(context, span);
customizeReceiverSpan(context, span);
Expand All @@ -81,7 +81,7 @@ public void onStop(ReceiverContext<T> context) {
* @param context context
* @param span span to customize
*/
public void customizeReceiverSpan(ReceiverContext<T> context, Span span) {
public void customizeReceiverSpan(T context, Span span) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Marcin Grzejszczak
* @since 1.0.0
*/
public class PropagatingSenderTracingObservationHandler<T> implements TracingObservationHandler<SenderContext<T>> {
public class PropagatingSenderTracingObservationHandler<T extends SenderContext<T>> implements TracingObservationHandler<T> {
private final Tracer tracer;

private final Propagator propagator;
Expand All @@ -45,7 +45,7 @@ public PropagatingSenderTracingObservationHandler(Tracer tracer, Propagator prop
}

@Override
public void onStart(SenderContext<T> context) {
public void onStart(T context) {
Span childSpan = createSenderSpan(context);
this.propagator.inject(childSpan.context(), context.getCarrier(), (carrier, key, value) -> context.getSetter().set(carrier, key, value));
getTracingContext(context).setSpan(childSpan);
Expand All @@ -56,23 +56,21 @@ public void onStart(SenderContext<T> context) {
* @param context context
* @return sender span
*/
public Span createSenderSpan(SenderContext<T> context) {
// TODO: Rewrite this to use parent spans once they are done
TracingContext tracingContext = getTracingContext(context);
Span span = tracingContext.getSpan();
Span senderSpan = span != null ? getTracer().nextSpan(span) : getTracer().nextSpan();
public Span createSenderSpan(T context) {
Span parentSpan = getParentSpan(context);
Span senderSpan = parentSpan != null ? getTracer().nextSpan(parentSpan) : getTracer().nextSpan();
String name = context.getContextualName() != null ? context.getContextualName() : context.getName();
senderSpan.name(name);
return senderSpan;
}

@Override
public void onError(SenderContext<T> context) {
public void onError(T context) {
context.getError().ifPresent(throwable -> getRequiredSpan(context).error(throwable));
}

@Override
public void onStop(SenderContext<T> context) {
public void onStop(T context) {
Span span = getRequiredSpan(context);
tagSpan(context, span);
customizeSenderSpan(context, span);
Expand All @@ -84,7 +82,7 @@ public void onStop(SenderContext<T> context) {
* @param context context
* @param span span to customize
*/
public void customizeSenderSpan(SenderContext<T> context, Span span) {
public void customizeSenderSpan(T context, Span span) {

}

Expand Down

0 comments on commit 0478643

Please sign in to comment.