Skip to content

Commit

Permalink
Merge pull request #2970 from DataDog/rgs/servlet-checkpoints
Browse files Browse the repository at this point in the history
emit thread migrations in TagSettingAsyncListener
  • Loading branch information
richardstartin authored Jul 29, 2021
2 parents 87b9c98 + 92d96e6 commit 27100a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public ElementMatcher<? super TypeDescription> typeMatcher() {
"org.elasticsearch.transport.netty4.Netty4TcpChannel",
"org.springframework.cglib.core.internal.LoadingCache",
"com.datastax.oss.driver.internal.core.channel.DefaultWriteCoalescer$Flusher",
"com.datastax.oss.driver.api.core.session.SessionBuilder")
"com.datastax.oss.driver.api.core.session.SessionBuilder",
"org.jvnet.hk2.internal.ServiceLocatorImpl")
.or(RX_WORKERS)
.or(GRPC_MANAGED_CHANNEL)
.or(REACTOR_DISABLED_TYPE_INITIALIZERS);
Expand Down Expand Up @@ -135,6 +136,10 @@ public void adviceTransformations(AdviceTransformation transformation) {
named("buildAsync")
.and(isDeclaredBy(named("com.datastax.oss.driver.api.core.session.SessionBuilder"))),
advice);
transformation.applyAdvice(
namedOneOf("getInjecteeDescriptor", "getService")
.and(isDeclaredBy(named("org.jvnet.hk2.internal.ServiceLocatorImpl"))),
advice);
transformation.applyAdvice(
isTypeInitializer().and(isDeclaredBy(REACTOR_DISABLED_TYPE_INITIALIZERS)), advice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public TagSettingAsyncListener(
this.activated = activated;
this.span = span;
this.isDispatch = isDispatch;
span.startThreadMigration();
}

@Override
public void onComplete(final AsyncEvent event) throws IOException {
if (activated.compareAndSet(false, true)) {
span.finishThreadMigration();
if (!isDispatch) {
DECORATE.onResponse(span, (HttpServletResponse) event.getSuppliedResponse());
}
Expand All @@ -46,6 +48,7 @@ public void onComplete(final AsyncEvent event) throws IOException {
@Override
public void onTimeout(final AsyncEvent event) throws IOException {
if (activated.compareAndSet(false, true)) {
span.finishThreadMigration();
if (Config.get().isServletAsyncTimeoutError()) {
span.setError(true);
}
Expand All @@ -58,6 +61,7 @@ public void onTimeout(final AsyncEvent event) throws IOException {
@Override
public void onError(final AsyncEvent event) throws IOException {
if (event.getThrowable() != null && activated.compareAndSet(false, true)) {
span.finishThreadMigration();
if (!isDispatch) {
DECORATE.onResponse(span, (HttpServletResponse) event.getSuppliedResponse());
if (((HttpServletResponse) event.getSuppliedResponse()).getStatus()
Expand All @@ -75,6 +79,7 @@ public void onError(final AsyncEvent event) throws IOException {
/** Transfer the listener over to the new context. */
@Override
public void onStartAsync(final AsyncEvent event) throws IOException {
span.startThreadMigration();
event.getAsyncContext().addListener(this);
}
}

0 comments on commit 27100a0

Please sign in to comment.