-
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.
[Tracing Instrumentation] Add instrumentation in InboundHandler (#10143)
* Add instrumentation in InboundHandler Signed-off-by: Gagan Juneja <[email protected]> * Add CHANGELOG Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> * Empty-Commit Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> * Address review comment Signed-off-by: Gagan Juneja <[email protected]> --------- Signed-off-by: Gagan Juneja <[email protected]> Signed-off-by: Gagan Juneja <[email protected]> Co-authored-by: Gagan Juneja <[email protected]>
- Loading branch information
1 parent
2965e69
commit aac0f09
Showing
41 changed files
with
374 additions
and
129 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
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
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
112 changes: 112 additions & 0 deletions
112
...src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTcpTransportChannel.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,112 @@ | ||
/* | ||
* 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.channels; | ||
|
||
import org.opensearch.Version; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.core.action.ActionListener; | ||
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.BaseTcpTransportChannel; | ||
import org.opensearch.transport.TcpTransportChannel; | ||
import org.opensearch.transport.TransportChannel; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Tracer wrapped {@link TransportChannel} | ||
*/ | ||
public class TraceableTcpTransportChannel extends BaseTcpTransportChannel { | ||
|
||
private final TransportChannel delegate; | ||
private final Span span; | ||
private final Tracer tracer; | ||
|
||
/** | ||
* Constructor. | ||
* @param delegate delegate | ||
* @param span span | ||
* @param tracer tracer | ||
*/ | ||
public TraceableTcpTransportChannel(TcpTransportChannel delegate, Span span, Tracer tracer) { | ||
super(delegate.getChannel()); | ||
this.delegate = delegate; | ||
this.span = span; | ||
this.tracer = tracer; | ||
} | ||
|
||
/** | ||
* Factory method. | ||
* | ||
* @param delegate delegate | ||
* @param span span | ||
* @param tracer tracer | ||
* @return transport channel | ||
*/ | ||
public static TransportChannel create(TcpTransportChannel delegate, final Span span, final Tracer tracer) { | ||
if (FeatureFlags.isEnabled(FeatureFlags.TELEMETRY) == true) { | ||
delegate.getChannel().addCloseListener(new ActionListener<Void>() { | ||
@Override | ||
public void onResponse(Void unused) { | ||
onFailure(null); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
span.addEvent("The TransportChannel was closed without sending the response"); | ||
span.setError(e); | ||
span.endSpan(); | ||
} | ||
}); | ||
|
||
return new TraceableTcpTransportChannel(delegate, span, tracer); | ||
} else { | ||
return delegate; | ||
} | ||
} | ||
|
||
@Override | ||
public String getProfileName() { | ||
return delegate.getProfileName(); | ||
} | ||
|
||
@Override | ||
public String getChannelType() { | ||
return delegate.getChannelType(); | ||
} | ||
|
||
@Override | ||
public void sendResponse(TransportResponse response) throws IOException { | ||
try (SpanScope scope = tracer.withSpanInScope(span)) { | ||
delegate.sendResponse(response); | ||
} catch (final IOException ex) { | ||
span.setError(ex); | ||
throw ex; | ||
} finally { | ||
span.endSpan(); | ||
} | ||
} | ||
|
||
@Override | ||
public void sendResponse(Exception exception) throws IOException { | ||
try (SpanScope scope = tracer.withSpanInScope(span)) { | ||
delegate.sendResponse(exception); | ||
} finally { | ||
span.setError(exception); | ||
span.endSpan(); | ||
} | ||
} | ||
|
||
@Override | ||
public Version getVersion() { | ||
return delegate.getVersion(); | ||
} | ||
} |
Oops, something went wrong.