forked from elastic/apm-agent-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: ExecutorService instrumentation
closes elastic#145
- Loading branch information
1 parent
58084b0
commit 51df3c4
Showing
16 changed files
with
403 additions
and
64 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
90 changes: 90 additions & 0 deletions
90
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ContextInScopeRunnableWrapper.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-2019 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.TraceContext; | ||
import co.elastic.apm.agent.objectpool.Recyclable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@VisibleForAdvice | ||
public class ContextInScopeRunnableWrapper implements Runnable, Recyclable { | ||
private static final Logger logger = LoggerFactory.getLogger(ContextInScopeRunnableWrapper.class); | ||
private final ElasticApmTracer tracer; | ||
private final TraceContext context; | ||
@Nullable | ||
private volatile Runnable delegate; | ||
|
||
ContextInScopeRunnableWrapper(ElasticApmTracer tracer) { | ||
this.tracer = tracer; | ||
context = TraceContext.with64BitId(tracer); | ||
} | ||
|
||
ContextInScopeRunnableWrapper wrap(Runnable delegate, TraceContext context) { | ||
this.context.copyFrom(context); | ||
// ordering is important: volatile write has to be after copying the TraceContext to ensure visibility in #run | ||
this.delegate = delegate; | ||
return this; | ||
} | ||
|
||
// Exceptions in the agent may never affect the monitored application | ||
// normally, advices act as the boundary of user and agent code and exceptions are handled via @Advice.OnMethodEnter(suppress = Throwable.class) | ||
// In this case, this class acts as the boundary of user and agent code so we have to do the tedious exception handling here | ||
@Override | ||
public void run() { | ||
try { | ||
context.activate(); | ||
} catch (Throwable t) { | ||
try { | ||
logger.error("Unexpected error while activating span", t); | ||
} catch (Throwable ignore) { | ||
} | ||
} | ||
try { | ||
//noinspection ConstantConditions | ||
delegate.run(); | ||
} catch (Exception e) { | ||
// although the corresponding span may be ended at this point, | ||
// we still have a copy of it's TraceContext so we can track errors here | ||
// (in contrast to SpanInScopeRunnableWrapper) | ||
context.captureException(e); | ||
} finally { | ||
try { | ||
context.deactivate(); | ||
tracer.recycle(this); | ||
} catch (Throwable t) { | ||
try { | ||
logger.error("Unexpected error while activating span", t); | ||
} catch (Throwable ignore) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void resetState() { | ||
context.resetState(); | ||
delegate = 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>apm-agent-plugins</artifactId> | ||
<groupId>co.elastic.apm</groupId> | ||
<version>1.3.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>apm-java-concurrent-plugin</artifactId> | ||
|
||
</project> |
Oops, something went wrong.