-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap Runnable in AsyncContext.start (#388)
- Loading branch information
Showing
15 changed files
with
348 additions
and
99 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
90 changes: 90 additions & 0 deletions
90
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/InScopeRunnableWrapper.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,90 @@ | ||
/*- | ||
* #%L | ||
* Elastic APM Java agent | ||
* %% | ||
* Copyright (C) 2018 Elastic and contributors | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package co.elastic.apm.agent.impl; | ||
|
||
|
||
import co.elastic.apm.agent.bci.VisibleForAdvice; | ||
import co.elastic.apm.agent.impl.transaction.AbstractSpan; | ||
import co.elastic.apm.agent.objectpool.Recyclable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@VisibleForAdvice | ||
public class InScopeRunnableWrapper implements Runnable, Recyclable { | ||
private final Logger logger = LoggerFactory.getLogger(InScopeRunnableWrapper.class); | ||
|
||
@Nullable | ||
private Runnable delegate; | ||
@Nullable | ||
private AbstractSpan<?> span; | ||
|
||
private final ElasticApmTracer tracer; | ||
|
||
InScopeRunnableWrapper(ElasticApmTracer tracer) { | ||
this.tracer = tracer; | ||
} | ||
|
||
public InScopeRunnableWrapper wrap(Runnable delegate, AbstractSpan<?> span) { | ||
this.delegate = delegate; | ||
this.span = span; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (span != null) { | ||
try { | ||
span.activate(); | ||
} catch (Throwable throwable) { | ||
try { | ||
logger.warn("Failed to activate span"); | ||
} catch (Throwable t) { | ||
// do nothing, just never fail | ||
} | ||
} | ||
} | ||
|
||
try { | ||
//noinspection ConstantConditions | ||
delegate.run(); | ||
} finally { | ||
try { | ||
if (span != null) { | ||
span.deactivate(); | ||
} | ||
tracer.recycle(this); | ||
} catch (Throwable throwable) { | ||
try { | ||
logger.warn("Failed to deactivate span or recycle"); | ||
} catch (Throwable t) { | ||
// do nothing, just never fail | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void resetState() { | ||
delegate = null; | ||
span = null; | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
...n/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
co.elastic.apm.agent.servlet.ServletInstrumentation | ||
co.elastic.apm.agent.servlet.FilterChainInstrumentation | ||
co.elastic.apm.agent.servlet.AsyncInstrumentation | ||
co.elastic.apm.agent.servlet.AsyncInstrumentation$StartAsyncInstrumentation | ||
co.elastic.apm.agent.servlet.AsyncInstrumentation$AsyncContextInstrumentation |
Oops, something went wrong.