-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add session tracking support to vert.x 3/4
- Loading branch information
1 parent
e7571fd
commit 6fce896
Showing
8 changed files
with
185 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
...main/java/datadog/trace/instrumentation/vertx_3_4/server/RoutingContextSessionAdvice.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,54 @@ | ||
package datadog.trace.instrumentation.vertx_3_4.server; | ||
|
||
import static datadog.trace.api.gateway.Events.EVENTS; | ||
|
||
import datadog.appsec.api.blocking.BlockingException; | ||
import datadog.trace.advice.ActiveRequestContext; | ||
import datadog.trace.advice.RequiresRequestContext; | ||
import datadog.trace.api.gateway.BlockResponseFunction; | ||
import datadog.trace.api.gateway.CallbackProvider; | ||
import datadog.trace.api.gateway.Flow; | ||
import datadog.trace.api.gateway.RequestContext; | ||
import datadog.trace.api.gateway.RequestContextSlot; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentTracer; | ||
import io.vertx.ext.web.Session; | ||
import java.util.function.BiFunction; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@RequiresRequestContext(RequestContextSlot.APPSEC) | ||
class RoutingContextSessionAdvice { | ||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
static void after( | ||
@Advice.Argument(0) final Session session, | ||
@ActiveRequestContext RequestContext reqCtx, | ||
@Advice.Thrown(readOnly = false) Throwable throwable) { | ||
if (session == null || session.id() == null) { | ||
return; | ||
} | ||
|
||
final CallbackProvider cbp = AgentTracer.get().getCallbackProvider(RequestContextSlot.APPSEC); | ||
BiFunction<RequestContext, String, Flow<Void>> callback = | ||
cbp.getCallback(EVENTS.requestSession()); | ||
if (callback == null) { | ||
return; | ||
} | ||
|
||
Flow<Void> flow = callback.apply(reqCtx, session.id()); | ||
Flow.Action action = flow.getAction(); | ||
if (action instanceof Flow.Action.RequestBlockingAction) { | ||
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction(); | ||
if (blockResponseFunction == null) { | ||
return; | ||
} | ||
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action; | ||
blockResponseFunction.tryCommitBlockingResponse( | ||
reqCtx.getTraceSegment(), | ||
rba.getStatusCode(), | ||
rba.getBlockingContentType(), | ||
rba.getExtraHeaders()); | ||
if (throwable == null) { | ||
throwable = new BlockingException("Blocked request (for sessionId)"); | ||
} | ||
} | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...main/java/datadog/trace/instrumentation/vertx_4_0/server/RoutingContextSessionAdvice.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,54 @@ | ||
package datadog.trace.instrumentation.vertx_4_0.server; | ||
|
||
import static datadog.trace.api.gateway.Events.EVENTS; | ||
|
||
import datadog.appsec.api.blocking.BlockingException; | ||
import datadog.trace.advice.ActiveRequestContext; | ||
import datadog.trace.advice.RequiresRequestContext; | ||
import datadog.trace.api.gateway.BlockResponseFunction; | ||
import datadog.trace.api.gateway.CallbackProvider; | ||
import datadog.trace.api.gateway.Flow; | ||
import datadog.trace.api.gateway.RequestContext; | ||
import datadog.trace.api.gateway.RequestContextSlot; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentTracer; | ||
import io.vertx.ext.web.Session; | ||
import java.util.function.BiFunction; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@RequiresRequestContext(RequestContextSlot.APPSEC) | ||
class RoutingContextSessionAdvice { | ||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
static void after( | ||
@Advice.Argument(0) final Session session, | ||
@ActiveRequestContext RequestContext reqCtx, | ||
@Advice.Thrown(readOnly = false) Throwable throwable) { | ||
if (session == null || session.id() == null) { | ||
return; | ||
} | ||
|
||
final CallbackProvider cbp = AgentTracer.get().getCallbackProvider(RequestContextSlot.APPSEC); | ||
BiFunction<RequestContext, String, Flow<Void>> callback = | ||
cbp.getCallback(EVENTS.requestSession()); | ||
if (callback == null) { | ||
return; | ||
} | ||
|
||
Flow<Void> flow = callback.apply(reqCtx, session.id()); | ||
Flow.Action action = flow.getAction(); | ||
if (action instanceof Flow.Action.RequestBlockingAction) { | ||
BlockResponseFunction blockResponseFunction = reqCtx.getBlockResponseFunction(); | ||
if (blockResponseFunction == null) { | ||
return; | ||
} | ||
Flow.Action.RequestBlockingAction rba = (Flow.Action.RequestBlockingAction) action; | ||
blockResponseFunction.tryCommitBlockingResponse( | ||
reqCtx.getTraceSegment(), | ||
rba.getStatusCode(), | ||
rba.getBlockingContentType(), | ||
rba.getExtraHeaders()); | ||
if (throwable == null) { | ||
throwable = new BlockingException("Blocked request (for sessionId)"); | ||
} | ||
} | ||
} | ||
} |
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