-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for session tracking in Vertx
- Loading branch information
1 parent
9247ce3
commit 5eb9fbd
Showing
8 changed files
with
151 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
55 changes: 55 additions & 0 deletions
55
...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,55 @@ | ||
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( | ||
@ActiveRequestContext final RequestContext reqCtx, | ||
@Advice.Argument(0) final Session session, | ||
@Advice.Thrown(readOnly = false) Throwable throwable) { | ||
|
||
if (session == null) { | ||
return; | ||
} | ||
|
||
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 session)"); | ||
} | ||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...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,55 @@ | ||
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( | ||
@ActiveRequestContext final RequestContext reqCtx, | ||
@Advice.Argument(0) final Session session, | ||
@Advice.Thrown(readOnly = false) Throwable throwable) { | ||
|
||
if (session == null) { | ||
return; | ||
} | ||
|
||
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 session)"); | ||
} | ||
} | ||
} | ||
} |
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