-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
146 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...pentelemetry/instrumentation/observation/handler/TracingAwareMeterObservationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.smallrye.opentelemetry.instrumentation.observation.handler; | ||
|
||
import io.micrometer.core.instrument.observation.MeterObservationHandler; | ||
import io.micrometer.observation.Observation; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.context.Scope; | ||
import io.smallrye.opentelemetry.instrumentation.observation.context.TracingObservationContext; | ||
|
||
public class TracingAwareMeterObservationHandler<T extends Observation.Context> implements MeterObservationHandler<T> { | ||
|
||
private final MeterObservationHandler<T> delegate; | ||
|
||
private final Tracer tracer; | ||
|
||
/** | ||
* Creates a new instance of {@link TracingAwareMeterObservationHandler}. | ||
* | ||
* @param delegate a {@link MeterObservationHandler} delegate | ||
* @param tracer tracer | ||
*/ | ||
public TracingAwareMeterObservationHandler(MeterObservationHandler<T> delegate, Tracer tracer) { | ||
this.delegate = delegate; | ||
this.tracer = tracer; | ||
} | ||
|
||
@Override | ||
public void onStart(T context) { | ||
this.delegate.onStart(context); | ||
} | ||
|
||
@Override | ||
public void onError(T context) { | ||
this.delegate.onError(context); | ||
} | ||
|
||
@Override | ||
public void onEvent(Observation.Event event, T context) { | ||
this.delegate.onEvent(event, context); | ||
} | ||
|
||
@Override | ||
public void onScopeOpened(T context) { | ||
this.delegate.onScopeOpened(context); | ||
} | ||
|
||
@Override | ||
public void onScopeClosed(T context) { | ||
this.delegate.onScopeClosed(context); | ||
} | ||
|
||
@Override | ||
public void onStop(T context) { | ||
TracingObservationContext tracingContext = context | ||
.getRequired(TracingObservationContext.class); | ||
Span currentSpan = tracingContext.getSpan(); | ||
if (currentSpan != null) { | ||
try (Scope scope = currentSpan.makeCurrent()) { | ||
this.delegate.onStop(context); | ||
} | ||
} else { | ||
this.delegate.onStop(context); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supportsContext(Observation.Context context) { | ||
return this.delegate.supportsContext(context); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters