Skip to content

Commit

Permalink
Use ServiceTracer where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Aug 9, 2023
1 parent b26eb81 commit ac78bc8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public Transaction currentTransaction() {

@Nullable
@Override
public co.elastic.apm.agent.tracer.ErrorCapture getActiveError() {
public ErrorCapture getActiveError() {
return ErrorCapture.getActive();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.tracer.ErrorCapture;
import co.elastic.apm.agent.tracer.GlobalTracer;
import co.elastic.apm.agent.tracer.Transaction;
import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils;
import co.elastic.apm.agent.tracer.service.ServiceTracer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -166,7 +166,7 @@ public SetServiceInfoForClassLoaderInstrumentation() {
public static class AdviceClass {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void setServiceInfoForClassLoader(@Advice.Argument(0) @Nullable ClassLoader classLoader, @Advice.Argument(1) String serviceName, @Advice.Argument(2) @Nullable String serviceVersion) {
tracer.require(Tracer.class).setServiceInfoForClassLoader(classLoader, ServiceInfo.of(serviceName, serviceVersion));
tracer.require(ServiceTracer.class).setServiceInfoForClassLoader(classLoader, ServiceInfo.of(serviceName, serviceVersion));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package co.elastic.apm.agent.pluginapi;

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.impl.transaction.Id;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.tracer.service.ServiceTracer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -176,7 +176,7 @@ public static class AdviceClass {
public static void useServiceInfoForClassLoader(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction,
@Advice.Argument(0) ClassLoader classLoader) {
if (transaction instanceof Transaction) {
ServiceInfo serviceInfo = tracer.require(Tracer.class).getServiceInfoForClassLoader(classLoader);
ServiceInfo serviceInfo = tracer.require(ServiceTracer.class).getServiceInfoForClassLoader(classLoader);
if (serviceInfo != null) {
((Transaction) transaction).getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
package co.elastic.apm.agent.ecs_logging;

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent;
import co.elastic.apm.agent.sdk.weakconcurrent.WeakSet;
import co.elastic.apm.agent.tracer.GlobalTracer;
import co.elastic.apm.agent.tracer.configuration.CoreConfiguration;
import co.elastic.apm.agent.tracer.service.ServiceTracer;

import javax.annotation.Nullable;
import java.util.Objects;
Expand All @@ -38,7 +38,7 @@ public class EcsLoggingUtils {
private static final WeakSet<Object> versionChecked = WeakConcurrent.buildSet();
private static final WeakSet<Object> environmentChecked = WeakConcurrent.buildSet();

private static final ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class);
private static final ServiceTracer tracer = GlobalTracer.get().require(ServiceTracer.class);

@Nullable
public static String getServiceName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
package co.elastic.apm.agent.servlet;

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.agent.sdk.state.GlobalState;
import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent;
import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap;
import co.elastic.apm.agent.servlet.adapter.ServletContextAdapter;
import co.elastic.apm.agent.tracer.Tracer;
import co.elastic.apm.agent.tracer.service.ServiceTracer;

import javax.annotation.Nullable;
import java.io.InputStream;
Expand All @@ -44,8 +44,8 @@ public static <ServletContext> void determineServiceName(ServletContextAdapter<S
@Nullable ServletContext servletContext,
Tracer tracer) {

ElasticApmTracer elasticApmTracer = tracer.probe(ElasticApmTracer.class);
if (elasticApmTracer == null) {
ServiceTracer serviceTracer = tracer.probe(ServiceTracer.class);
if (serviceTracer == null) {
return;
}

Expand All @@ -63,7 +63,7 @@ public static <ServletContext> void determineServiceName(ServletContextAdapter<S
return;
}
ServiceInfo serviceInfo = detectServiceInfo(adapter, servletContext, servletContextClassLoader);
elasticApmTracer.setServiceInfoForClassLoader(servletContextClassLoader, serviceInfo);
serviceTracer.setServiceInfoForClassLoader(servletContextClassLoader, serviceInfo);
}

public static <ServletContext> ServiceInfo detectServiceInfo(ServletContextAdapter<ServletContext> adapter, ServletContext servletContext, ClassLoader servletContextClassLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
package co.elastic.apm.agent.springwebmvc;

import co.elastic.apm.agent.tracer.service.ServiceInfo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import co.elastic.apm.agent.servlet.Constants;
import co.elastic.apm.agent.servlet.ServletServiceNameHelper;
import co.elastic.apm.agent.servlet.adapter.ServletContextAdapter;
import co.elastic.apm.agent.tracer.GlobalTracer;
import co.elastic.apm.agent.tracer.Tracer;
import co.elastic.apm.agent.tracer.service.ServiceTracer;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -76,14 +76,14 @@ public static class Helper {

public static <ServletContext> void detectSpringServiceName(ServletContextAdapter<ServletContext> adapter,
WebApplicationContext applicationContext, @Nullable ServletContext servletContext) {
ElasticApmTracer elasticApmTracer = tracer.probe(ElasticApmTracer.class);
if (elasticApmTracer == null) {
ServiceTracer serviceTracer = tracer.probe(ServiceTracer.class);
if (serviceTracer == null) {
return;
}

// avoid having two service names for a standalone jar
// one based on Implementation-Title and one based on spring.application.name
if (!ElasticApmTracer.AUTO_DETECTED_SERVICE_INFO.isMultiServiceContainer()) {
if (!serviceTracer.autoDetectedServiceInfo().isMultiServiceContainer()) {
return;
}

Expand All @@ -105,7 +105,7 @@ public static <ServletContext> void detectSpringServiceName(ServletContextAdapte
ServiceInfo fromSpringApplicationNameProperty = ServiceInfo.of(applicationContext.getEnvironment().getProperty("spring.application.name", ""));
ServiceInfo fromApplicationContextApplicationName = ServiceInfo.of(removeLeadingSlash(applicationContext.getApplicationName()));

elasticApmTracer.setServiceInfoForClassLoader(classLoader, fromSpringApplicationNameProperty
serviceTracer.setServiceInfoForClassLoader(classLoader, fromSpringApplicationNameProperty
.withFallback(fromServletContext)
.withFallback(fromApplicationContextApplicationName));
}
Expand Down

0 comments on commit ac78bc8

Please sign in to comment.