-
Notifications
You must be signed in to change notification settings - Fork 311
WebSocket support for Netty #8632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e619f2a
Implemented WebSocket support for Netty 4.1
ValentinZakharov 1ab91db
Let propagate unhandled events and fix tests
amarziali 7f96ea2
Refactoring
ValentinZakharov b2d45a7
Refactor netty test and fix instrumentation
amarziali 0d7330c
Improved pipeline processing - now you can insert handler in any place
ValentinZakharov 7f1138f
Merge branch 'master' into vzakharov/websockets_netty
ValentinZakharov ee2c5fd
Merge branch 'master' into vzakharov/websockets_netty
ValentinZakharov 203e468
Fixed helper
ValentinZakharov d753e90
Refactoring
ValentinZakharov af33164
WebSocket Server support for netty-4.0
ValentinZakharov e79c661
Missing handlers use cases for netty-4.1
ValentinZakharov 19417b9
Fixed handlers for netty-4.0
ValentinZakharov 6e94f0f
Tests for netty-4.0
ValentinZakharov c9a7c20
Refactoring
ValentinZakharov 86715ec
WebSocket Server support for netty-3.8
ValentinZakharov dabfe2d
Tests for netty-3.8
ValentinZakharov e7f4d7f
Spotless
ValentinZakharov 5fd4cf2
Fixed tests
ValentinZakharov 091ee80
Add profiler env check command to AgentCLI (#8671)
jbachorik eb18875
Remove dependency on bash from crash/oome uploder scripts (#8652)
jbachorik 66f7b9f
Do not apply JUnit 4 instrumentation to MUnit runners (#8675)
nikita-tkachenko-datadog d851aa9
Shutdown CI Visibility test event handlers before tracer (#8677)
nikita-tkachenko-datadog c7ec7ce
Prevent double reporting of Scalatest events when using SBT with test…
nikita-tkachenko-datadog ba3f346
Fix In-Product when config is empty (#8679)
jpbempel 2203ec4
Expand MUnit runners filter to catch munit.MUnitRunner in JUnit 4 ins…
daniel-mohedano fef00c7
Remove unused TestEventsHandler methods (#8674)
nikita-tkachenko-datadog 15889fc
Delete print line (#8686)
sarahchen6 b838ed1
Exclude ProxyLeakTask exception from exception profiling (#8666)
jbachorik 690dd95
Use jvmstat for JDKs 9+ programmatically (#8641)
MattAlp 6510fa4
Update test.retry_reason to use full name of the feature (#8689)
daniel-mohedano b8b8dab
Allow dogstatsd port to be configurable with DD_DOGSTATSD_PORT (#8693)
randomanderson 5922b70
wait the client handshake
amarziali 78e9c9c
move netty ws client to interested modules
amarziali bc4b6f0
Merge remote-tracking branch 'origin/master' into vzakharov/websocket…
amarziali 97e7d2f
Added WebSocket tracing check
ValentinZakharov c817fc9
Merge branch 'master' into vzakharov/websockets_netty
ValentinZakharov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
135 changes: 135 additions & 0 deletions
135
.../trace/instrumentation/netty38/server/websocket/WebSocketServerRequestTracingHandler.java
This file contains hidden or 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,135 @@ | ||
package datadog.trace.instrumentation.netty38.server.websocket; | ||
|
||
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; | ||
import static datadog.trace.bootstrap.instrumentation.decorator.WebsocketDecorator.DECORATE; | ||
import static datadog.trace.bootstrap.instrumentation.websocket.HandlersExtractor.MESSAGE_TYPE_TEXT; | ||
|
||
import datadog.trace.bootstrap.ContextStore; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrum FB22 entation.websocket.HandlerContext; | ||
import datadog.trace.instrumentation.netty38.ChannelTraceContext; | ||
import org.jboss.netty.channel.Channel; | ||
import org.jboss.netty.channel.ChannelHandlerContext; | ||
import org.jboss.netty.channel.MessageEvent; | ||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler; | ||
import org.jboss.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; | ||
import org.jboss.netty.handler.codec.http.websocketx.CloseWebSocketFrame; | ||
import org.jboss.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame; | ||
import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; | ||
import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; | ||
|
||
public class WebSocketServerRequestTracingHandler extends SimpleChannelUpstreamHandler { | ||
|
||
private final ContextStore<Channel, ChannelTraceContext> contextStore; | ||
|
||
public WebSocketServerRequestTracingHandler( | ||
final ContextStore<Channel, ChannelTraceContext> contextStore) { | ||
this.contextStore = contextStore; | ||
} | ||
|
||
@Override | ||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception { | ||
Object frame = event.getMessage(); | ||
if (frame instanceof WebSocketFrame) { | ||
Channel channel = ctx.getChannel(); | ||
|
||
ChannelTraceContext traceContext = this.contextStore.get(channel); | ||
if (traceContext != null) { | ||
|
||
HandlerContext.Receiver receiverContext = traceContext.getReceiverHandlerContext(); | ||
if (receiverContext == null) { | ||
HandlerContext.Sender sessionState = traceContext.getSenderHandlerContext(); | ||
if (sessionState != null) { | ||
receiverContext = | ||
new HandlerContext.Receiver( | ||
sessionState.getHandshakeSpan(), channel.getId().toString()); | ||
traceContext.setReceiverHandlerContext(receiverContext); | ||
} | ||
} | ||
if (receiverContext != null) { | ||
if (frame instanceof TextWebSocketFrame) { | ||
// WebSocket Read Text Start | ||
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; | ||
|
||
final AgentSpan span = | ||
DECORATE.onReceiveFrameStart( | ||
receiverContext, textFrame.getText(), textFrame.isFinalFragment()); | ||
try (final AgentScope scope = activateSpan(span)) { | ||
ctx.sendUpstream(event); | ||
// WebSocket Read Text Start | ||
} finally { | ||
if (textFrame.isFinalFragment()) { | ||
traceContext.setReceiverHandlerContext(null); | ||
DECORATE.onFrameEnd(receiverContext); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
if (frame instanceof BinaryWebSocketFrame) { | ||
// WebSocket Read Binary Start | ||
BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame; | ||
final AgentSpan span = | ||
DECORATE.onReceiveFrameStart( | ||
receiverContext, | ||
binaryFrame.getBinaryData().array(), | ||
binaryFrame.isFinalFragment()); | ||
try (final AgentScope scope = activateSpan(span)) { | ||
ctx.sendUpstream(event); | ||
} finally { | ||
// WebSocket Read Binary End | ||
if (binaryFrame.isFinalFragment()) { | ||
traceContext.setReceiverHandlerContext(null); | ||
DECORATE.onFrameEnd(receiverContext); | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (frame instanceof ContinuationWebSocketFrame) { | ||
ContinuationWebSocketFrame continuationWebSocketFrame = | ||
(ContinuationWebSocketFrame) frame; | ||
final AgentSpan span = | ||
DECORATE.onReceiveFrameStart( | ||
receiverContext, | ||
MESSAGE_TYPE_TEXT.equals(receiverContext.getMessageType()) | ||
? continuationWebSocketFrame.getText() | ||
: continuationWebSocketFrame.getBinaryData().array(), | ||
continuationWebSocketFrame.isFinalFragment()); | ||
try (final AgentScope scope = activateSpan(span)) { | ||
ctx.sendUpstream(event); | ||
} finally { | ||
if (continuationWebSocketFrame.isFinalFragment()) { | ||
traceContext.setReceiverHandlerContext(null); | ||
DECORATE.onFrameEnd(receiverContext); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
if (frame instanceof CloseWebSocketFrame) { | ||
// WebSocket Closed by client | ||
CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame; | ||
int statusCode = closeFrame.getStatusCode(); | ||
String reasonText = closeFrame.getReasonText(); | ||
traceContext.setSenderHandlerContext(null); | ||
traceContext.setReceiverHandlerContext(null); | ||
final AgentSpan span = | ||
DECORATE.onSessionCloseReceived(receiverContext, reasonText, statusCode); | ||
try (final AgentScope scope = activateSpan(span)) { | ||
ctx.sendUpstream(event); | ||
if (closeFrame.isFinalFragment()) { | ||
DECORATE.onFrameEnd(receiverContext); | ||
} | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
ctx.sendUpstream(event); // superclass does not throw | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be added only if websocket tracing is enabled