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.
\elastic#3030: Reduce dependency on elastic APM tracer in plugins but…
… rather depend on a more general API.
- Loading branch information
Showing
130 changed files
with
1,131 additions
and
729 deletions.
There are no files selected for viewing
451 changes: 451 additions & 0 deletions
451
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java
Large diffs are not rendered by default.
Oops, something went wrong.
423 changes: 96 additions & 327 deletions
423
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
26 changes: 26 additions & 0 deletions
26
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/MetricsAwareTracer.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,26 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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. | ||
*/ | ||
package co.elastic.apm.agent.impl; | ||
|
||
import co.elastic.apm.agent.metrics.MetricRegistry; | ||
|
||
public interface MetricsAwareTracer extends SpanAwareTracer { | ||
|
||
MetricRegistry getMetricRegistry(); | ||
} |
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
41 changes: 41 additions & 0 deletions
41
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/SpanAwareTracer.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,41 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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. | ||
*/ | ||
package co.elastic.apm.agent.impl; | ||
|
||
import co.elastic.apm.agent.impl.transaction.AbstractSpan; | ||
import co.elastic.apm.agent.impl.transaction.ElasticContext; | ||
import co.elastic.apm.agent.impl.transaction.Span; | ||
import co.elastic.apm.agent.impl.transaction.TraceContext; | ||
|
||
public interface SpanAwareTracer extends Tracer { | ||
|
||
TraceContext createSpanLink(); | ||
|
||
void recycle(TraceContext context); | ||
|
||
void recycle(Span span); | ||
|
||
Span startSpan(AbstractSpan<?> parent, long epochMicros); | ||
|
||
void activate(ElasticContext<?> context); | ||
|
||
void deactivate(ElasticContext<?> context); | ||
|
||
Scope activateInScope(ElasticContext<?> context); | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...ent-core/src/main/java/co/elastic/apm/agent/impl/transaction/MetricsAwareTransaction.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,91 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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. | ||
*/ | ||
package co.elastic.apm.agent.impl.transaction; | ||
|
||
import co.elastic.apm.agent.impl.MetricsAwareTracer; | ||
import co.elastic.apm.agent.metrics.Labels; | ||
import co.elastic.apm.agent.metrics.MetricRegistry; | ||
import co.elastic.apm.agent.metrics.Timer; | ||
import co.elastic.apm.agent.util.KeyListConcurrentHashMap; | ||
|
||
import java.util.List; | ||
|
||
public class MetricsAwareTransaction extends Transaction { | ||
|
||
private static final ThreadLocal<Labels.Mutable> labelsThreadLocal = new ThreadLocal<Labels.Mutable>() { | ||
@Override | ||
protected Labels.Mutable initialValue() { | ||
return Labels.Mutable.of(); | ||
} | ||
}; | ||
|
||
public MetricsAwareTransaction(MetricsAwareTracer tracer) { | ||
super(tracer); | ||
} | ||
|
||
protected void trackMetrics() { | ||
try { | ||
phaser.readerLock(); | ||
phaser.flipPhase(); | ||
// timers are guaranteed to be stable now | ||
// - no concurrent updates possible as finished is true | ||
// - no other thread is running the incrementTimer method, | ||
// as flipPhase only returns when all threads have exited that method | ||
|
||
final String type = getType(); | ||
if (type == null) { | ||
return; | ||
} | ||
final Labels.Mutable labels = labelsThreadLocal.get(); | ||
labels.resetState(); | ||
labels.serviceName(getTraceContext().getServiceName()) | ||
.serviceVersion(getTraceContext().getServiceVersion()) | ||
.transactionName(name) | ||
.transactionType(type); // TODO: | ||
final MetricRegistry metricRegistry = ((MetricsAwareTracer) tracer).getMetricRegistry(); | ||
long criticalValueAtEnter = metricRegistry.writerCriticalSectionEnter(); | ||
try { | ||
if (collectBreakdownMetrics) { | ||
List<String> types = timerBySpanTypeAndSubtype.keyList(); | ||
for (int i = 0; i < types.size(); i++) { | ||
String spanType = types.get(i); | ||
KeyListConcurrentHashMap<String, Timer> timerBySubtype = timerBySpanTypeAndSubtype.get(spanType); | ||
List<String> subtypes = timerBySubtype.keyList(); | ||
for (int j = 0; j < subtypes.size(); j++) { | ||
String subtype = subtypes.get(j); | ||
final Timer timer = timerBySubtype.get(subtype); | ||
if (timer.getCount() > 0) { | ||
if (subtype.equals("")) { | ||
subtype = null; | ||
} | ||
labels.spanType(spanType).spanSubType(subtype); | ||
metricRegistry.updateTimer("span.self_time", labels, timer.getTotalTimeUs(), timer.getCount()); | ||
timer.resetState(); | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
metricRegistry.writerCriticalSectionExit(criticalValueAtEnter); | ||
} | ||
} finally { | ||
phaser.readerUnlock(); | ||
} | ||
} | ||
} |
Oops, something went wrong.