-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add instrumentation to transport service * Add instrumentation to transport service * Add javadoc --------- Signed-off-by: Gagan Juneja <[email protected]> Co-authored-by: Gagan Juneja <[email protected]>
- Loading branch information
1 parent
4563ebc
commit 27bedac
Showing
8 changed files
with
188 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
107 changes: 107 additions & 0 deletions
107
...main/java/org/opensearch/telemetry/tracing/handler/TraceableTransportResponseHandler.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,107 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.tracing.handler; | ||
|
||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.transport.TransportResponse; | ||
import org.opensearch.telemetry.tracing.Span; | ||
import org.opensearch.telemetry.tracing.SpanScope; | ||
import org.opensearch.telemetry.tracing.Tracer; | ||
import org.opensearch.transport.TransportException; | ||
import org.opensearch.transport.TransportResponseHandler; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Tracer wrapped {@link TransportResponseHandler} | ||
* @param <T> TransportResponse | ||
*/ | ||
public class TraceableTransportResponseHandler<T extends TransportResponse> implements TransportResponseHandler<T> { | ||
|
||
private final Span span; | ||
private final TransportResponseHandler<T> delegate; | ||
private final Tracer tracer; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param delegate delegate | ||
* @param span span | ||
* @param tracer tracer | ||
*/ | ||
private TraceableTransportResponseHandler(TransportResponseHandler<T> delegate, Span span, Tracer tracer) { | ||
this.delegate = Objects.requireNonNull(delegate); | ||
this.span = Objects.requireNonNull(span); | ||
this.tracer = Objects.requireNonNull(tracer); | ||
} | ||
|
||
/** | ||
* Factory method. | ||
* @param delegate delegate | ||
* @param span span | ||
* @param tracer tracer | ||
* @return transportResponseHandler | ||
*/ | ||
public static <S extends TransportResponse> TransportResponseHandler<S> create( | ||
TransportResponseHandler<S> delegate, | ||
Span span, | ||
Tracer tracer | ||
) { | ||
if (FeatureFlags.isEnabled(FeatureFlags.TELEMETRY) == true) { | ||
return new TraceableTransportResponseHandler<S>(delegate, span, tracer); | ||
} else { | ||
return delegate; | ||
} | ||
} | ||
|
||
@Override | ||
public T read(StreamInput in) throws IOException { | ||
return delegate.read(in); | ||
} | ||
|
||
@Override | ||
public void handleResponse(T response) { | ||
try (SpanScope scope = tracer.withSpanInScope(span)) { | ||
delegate.handleResponse(response); | ||
} finally { | ||
span.endSpan(); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleException(TransportException exp) { | ||
try (SpanScope scope = tracer.withSpanInScope(span)) { | ||
delegate.handleException(exp); | ||
} finally { | ||
span.setError(exp); | ||
span.endSpan(); | ||
} | ||
} | ||
|
||
@Override | ||
public String executor() { | ||
return delegate.executor(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return delegate.toString(); | ||
} | ||
|
||
@Override | ||
public void handleRejection(Exception exp) { | ||
try (SpanScope scope = tracer.withSpanInScope(span)) { | ||
delegate.handleRejection(exp); | ||
} finally { | ||
span.endSpan(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/org/opensearch/telemetry/tracing/handler/package-info.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,12 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/** | ||
* This package contains classes needed for tracing requests. | ||
*/ | ||
package org.opensearch.telemetry.tracing.handler; |
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