Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-3405 Provide core tracer logger implementation #1953

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions features/dd-sdk-android-trace/api/dd-sdk-android-trace.api
Original file line number Diff line number Diff line change
Expand Up @@ -5954,7 +5954,6 @@ public class com/datadog/trace/core/CoreTracer : com/datadog/trace/bootstrap/ins
public fun addTracerReportToFlare (Ljava/util/zip/ZipOutputStream;)V
public synthetic fun buildSpan (Ljava/lang/String;Ljava/lang/CharSequence;)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentTracer$SpanBuilder;
public fun buildSpan (Ljava/lang/String;Ljava/lang/CharSequence;)Lcom/datadog/trace/core/CoreTracer$CoreSpanBuilder;
public static fun builder ()Lcom/datadog/trace/core/CoreTracer$CoreTracerBuilder;
public fun captureSpan (Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpan;)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentScope$Continuation;
public synthetic fun captureTraceConfig ()Lcom/datadog/trace/api/TraceConfig;
public fun captureTraceConfig ()Lcom/datadog/trace/core/CoreTracer$ConfigSnapshot;
Expand Down Expand Up @@ -6028,7 +6027,7 @@ public class com/datadog/trace/core/CoreTracer$CoreSpanBuilder : com/datadog/tra
}

public class com/datadog/trace/core/CoreTracer$CoreTracerBuilder {
public fun <init> ()V
public fun <init> (Lcom/datadog/android/api/InternalLogger;)V
public fun baggageMapping (Ljava/util/Map;)Lcom/datadog/trace/core/CoreTracer$CoreTracerBuilder;
public fun build ()Lcom/datadog/trace/core/CoreTracer;
public fun config (Lcom/datadog/trace/api/Config;)Lcom/datadog/trace/core/CoreTracer$CoreTracerBuilder;
Expand All @@ -6053,7 +6052,7 @@ public class com/datadog/trace/core/CoreTracer$CoreTracerBuilder {

public class com/datadog/trace/core/DDSpan : com/datadog/trace/api/profiling/TransientProfilingContextHolder, com/datadog/trace/bootstrap/instrumentation/api/AgentSpan, com/datadog/trace/bootstrap/instrumentation/api/AttachableWrapper, com/datadog/trace/core/CoreSpan {
public static final field CHECKPOINTED_TAG Ljava/lang/String;
public fun <init> (Ljava/lang/String;JLcom/datadog/trace/core/DDSpanContext;Ljava/util/List;)V
public fun <init> (Ljava/lang/String;JLcom/datadog/trace/core/DDSpanContext;Ljava/util/List;Lcom/datadog/android/api/InternalLogger;)V
public fun addLink (Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpanLink;)V
public synthetic fun addThrowable (Ljava/lang/Throwable;)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpan;
public synthetic fun addThrowable (Ljava/lang/Throwable;)Lcom/datadog/trace/core/CoreSpan;
Expand Down Expand Up @@ -6359,7 +6358,7 @@ public abstract class com/datadog/trace/core/PendingTraceBuffer : java/lang/Auto
public fun <init> ()V
public abstract fun close ()V
public static fun delaying (Lcom/datadog/trace/api/time/TimeSource;Lcom/datadog/trace/api/Config;Lcom/datadog/trace/core/monitor/HealthMetrics;)Lcom/datadog/trace/core/PendingTraceBuffer;
public static fun discarding ()Lcom/datadog/trace/core/PendingTraceBuffer;
public static fun discarding (Lcom/datadog/android/api/InternalLogger;)Lcom/datadog/trace/core/PendingTraceBuffer;
public abstract fun enqueue (Lcom/datadog/trace/core/PendingTraceBuffer$Element;)V
public abstract fun flush ()V
public fun longRunningSpansEnabled ()Z
Expand Down Expand Up @@ -6761,8 +6760,8 @@ public class com/datadog/trace/core/propagation/ptags/W3CPTagsCodec {
}

public final class com/datadog/trace/core/scopemanager/ContinuableScopeManager : com/datadog/trace/bootstrap/instrumentation/api/AgentScopeManager {
public fun <init> (IZZ)V
public fun <init> (IZZLcom/datadog/trace/bootstrap/instrumentation/api/ProfilingContextIntegration;Lcom/datadog/trace/core/monitor/HealthMetrics;)V
public fun <init> (IZZLcom/datadog/android/api/InternalLogger;)V
public fun <init> (IZZLcom/datadog/trace/bootstrap/instrumentation/api/ProfilingContextIntegration;Lcom/datadog/trace/core/monitor/HealthMetrics;Lcom/datadog/android/api/InternalLogger;)V
public fun activate (Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpan;Lcom/datadog/trace/bootstrap/instrumentation/api/ScopeSource;)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentScope;
public fun activate (Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpan;Lcom/datadog/trace/bootstrap/instrumentation/api/ScopeSource;Z)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentScope;
public fun activateNext (Lcom/datadog/trace/bootstrap/instrumentation/api/AgentSpan;)Lcom/datadog/trace/bootstrap/instrumentation/api/AgentScope;
Expand Down Expand Up @@ -6904,8 +6903,36 @@ public final class com/datadog/trace/lambda/ReadFromInputStreamJsonAdapter : com
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
}

public class com/datadog/trace/logger/DatadogCoreTracerLogger : com/datadog/trace/logger/Logger {
public fun <init> (Ljava/lang/String;Lcom/datadog/android/api/InternalLogger;)V
public fun debug (Ljava/lang/String;)V
public fun debug (Ljava/lang/String;Ljava/lang/Object;)V
public fun debug (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun debug (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun debug (Ljava/lang/String;[Ljava/lang/Object;)V
public fun error (Ljava/lang/String;)V
public fun error (Ljava/lang/String;Ljava/lang/Object;)V
public fun error (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun error (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public fun info (Ljava/lang/String;)V
public fun info (Ljava/lang/String;Ljava/lang/Object;)V
public fun info (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun info (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun isDebugEnabled ()Z
public fun isInfoEnabled ()Z
public fun isWarnEnabled ()Z
public fun warn (Ljava/lang/String;)V
public fun warn (Ljava/lang/String;Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
}

public abstract interface class com/datadog/trace/logger/ILoggerFactory {
public abstract fun getLogger (Ljava/lang/String;)Lcom/datadog/trace/logger/Logger;
public abstract fun getLogger (Ljava/lang/String;Lcom/datadog/android/api/InternalLogger;)Lcom/datadog/trace/logger/Logger;
}

public abstract interface class com/datadog/trace/logger/Logger {
Expand All @@ -6920,22 +6947,14 @@ public abstract interface class com/datadog/trace/logger/Logger {
public abstract fun error (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public abstract fun error (Ljava/lang/String;Ljava/lang/Throwable;)V
public abstract fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun getName ()Ljava/lang/String;
public abstract fun info (Ljava/lang/String;)V
public abstract fun info (Ljava/lang/String;Ljava/lang/Object;)V
public abstract fun info (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public abstract fun info (Ljava/lang/String;Ljava/lang/Throwable;)V
public abstract fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun isDebugEnabled ()Z
public abstract fun isErrorEnabled ()Z
public abstract fun isInfoEnabled ()Z
public abstract fun isTraceEnabled ()Z
public abstract fun isWarnEnabled ()Z
public abstract fun trace (Ljava/lang/String;)V
public abstract fun trace (Ljava/lang/String;Ljava/lang/Object;)V
public abstract fun trace (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public abstract fun trace (Ljava/lang/String;Ljava/lang/Throwable;)V
public abstract fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun warn (Ljava/lang/String;)V
public abstract fun warn (Ljava/lang/String;Ljava/lang/Object;)V
public abstract fun warn (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
Expand All @@ -6948,6 +6967,7 @@ public final class com/datadog/trace/logger/LoggerFactory {
public static fun getILoggerFactory ()Lcom/datadog/trace/logger/ILoggerFactory;
public static fun getLogger (Ljava/lang/Class;)Lcom/datadog/trace/logger/Logger;
public static fun getLogger (Ljava/lang/String;)Lcom/datadog/trace/logger/Logger;
public static fun getLogger (Ljava/lang/String;Lcom/datadog/android/api/InternalLogger;)Lcom/datadog/trace/logger/Logger;
}

public class com/datadog/trace/logger/NoOpLogger : com/datadog/trace/logger/Logger {
Expand All @@ -6962,22 +6982,14 @@ public class com/datadog/trace/logger/NoOpLogger : com/datadog/trace/logger/Logg
public fun error (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun error (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public fun getName ()Ljava/lang/String;
public fun info (Ljava/lang/String;)V
public fun info (Ljava/lang/String;Ljava/lang/Object;)V
public fun info (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun info (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun isDebugEnabled ()Z
public fun isErrorEnabled ()Z
public fun isInfoEnabled ()Z
public fun isTraceEnabled ()Z
public fun isWarnEnabled ()Z
public fun trace (Ljava/lang/String;)V
public fun trace (Ljava/lang/String;Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;)V
public fun warn (Ljava/lang/String;Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import androidx.annotation.VisibleForTesting;

import com.datadog.android.api.InternalLogger;
import com.datadog.trace.api.Config;
import com.datadog.trace.api.DDSpanId;
import com.datadog.trace.api.DDTraceId;
Expand Down Expand Up @@ -104,15 +107,12 @@
* reporting, and propagating traces
*/
public class CoreTracer implements AgentTracer.TracerAPI {
private static final Logger log = LoggerFactory.getLogger(CoreTracer.class);
@VisibleForTesting
final Logger log;
// UINT64 max value
public static final BigInteger TRACE_ID_MAX =
BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE);

public static CoreTracerBuilder builder() {
return new CoreTracerBuilder();
}

public static final String LANG_STATSD_TAG = "lang";
public static final String LANG_VERSION_STATSD_TAG = "lang_version";
public static final String LANG_INTERPRETER_STATSD_TAG = "lang_interpreter";
Expand Down Expand Up @@ -232,6 +232,8 @@ public static CoreTracerBuilder builder() {

private final PropagationTags.Factory propagationTagsFactory;

final InternalLogger internalLogger;

@Override
public ConfigSnapshot captureTraceConfig() {
return dynamicConfig.captureTraceConfig();
Expand Down Expand Up @@ -282,6 +284,7 @@ public static class CoreTracerBuilder {
private TimeSource timeSource;
private ProfilingContextIntegration profilingContextIntegration =
ProfilingContextIntegration.NoOp.INSTANCE;
private InternalLogger internalLogger;
private boolean injectBaggageAsTags;

public CoreTracerBuilder serviceName(String serviceName) {
Expand Down Expand Up @@ -370,9 +373,10 @@ public CoreTracerBuilder injectBaggageAsTags(boolean injectBaggageAsTags) {
return this;
}

public CoreTracerBuilder() {
public CoreTracerBuilder(InternalLogger internalLogger) {
// Apply the default values from config.
config(Config.get());
this.internalLogger = internalLogger;
}

public CoreTracerBuilder withProperties(final Properties properties) {
Expand Down Expand Up @@ -417,7 +421,8 @@ public CoreTracer build() {
instrumentationGateway,
timeSource,
profilingContextIntegration,
injectBaggageAsTags);
injectBaggageAsTags,
internalLogger);
}
}

Expand All @@ -441,14 +446,17 @@ private CoreTracer(
final InstrumentationGateway instrumentationGateway,
final TimeSource timeSource,
final ProfilingContextIntegration profilingContextIntegration,
final boolean injectBaggageAsTags) {
final boolean injectBaggageAsTags,
final InternalLogger internalLogger) {

assert localRootSpanTags != null;
assert defaultSpanTags != null;
assert serviceNameMappings != null;
assert taggedHeaders != null;
assert baggageMapping != null;

this.log = LoggerFactory.getLogger(CoreTracer.class.getSimpleName(), internalLogger);
this.rlLog = new RatelimitedLogger(log, 1, MINUTES);
this.timeSource = timeSource == null ? SystemTimeSource.INSTANCE : timeSource;
startTimeNano = this.timeSource.getCurrentTimeNanos();
startNanoTicks = this.timeSource.getNanoTicks();
Expand Down Expand Up @@ -510,7 +518,8 @@ private CoreTracer(
config.isScopeStrictMode(),
config.isScopeInheritAsyncPropagation(),
profilingContextIntegration,
healthMetrics);
healthMetrics,
internalLogger);
} else {
this.scopeManager = scopeManager;
}
Expand All @@ -520,7 +529,7 @@ private CoreTracer(
this.writer = writer;
pendingTraceBuffer =
strictTraceWrites
? PendingTraceBuffer.discarding()
? PendingTraceBuffer.discarding(internalLogger)
: PendingTraceBuffer.delaying(
this.timeSource, config, healthMetrics);
pendingTraceFactory =
Expand Down Expand Up @@ -577,6 +586,7 @@ private CoreTracer(
} else {
this.localRootSpanTags = localRootSpanTags;
}
this.internalLogger = internalLogger;
}

/**
Expand Down Expand Up @@ -765,7 +775,7 @@ public Timer getTimer() {
return timer;
}

private final RatelimitedLogger rlLog = new RatelimitedLogger(log, 1, MINUTES);
private final RatelimitedLogger rlLog;

/**
* We use the sampler to know if the trace has to be reported/written. The sampler is called on
Expand Down Expand Up @@ -1073,7 +1083,12 @@ public CoreSpanBuilder ignoreActiveSpan() {

private DDSpan buildSpan() {
addTerminatedContextAsLinks();
DDSpan span = DDSpan.create(instrumentationName, timestampMicro, buildSpanContext(), links);
DDSpan span = DDSpan.create(
instrumentationName,
timestampMicro,
buildSpanContext(),
links,
tracer.internalLogger);
if (span.isLocalRootSpan()) {
EndpointTracker tracker = tracer.onRootSpanStarted(span);
span.setEndpointTracker(tracker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.datadog.android.api.InternalLogger;
import com.datadog.trace.api.Config;
import com.datadog.trace.api.DDSpanId;
import com.datadog.trace.api.DDTags;
Expand Down Expand Up @@ -51,17 +52,16 @@
*/
public class DDSpan
implements AgentSpan, CoreSpan<DDSpan>, TransientProfilingContextHolder, AttachableWrapper {
private static final Logger log = LoggerFactory.getLogger(DDSpan.class);

private final Logger log;
public static final String CHECKPOINTED_TAG = "checkpointed";

static DDSpan create(
final String instrumentationName,
final long timestampMicro,
@NonNull DDSpanContext context,
final List<AgentSpanLink> links) {
final DDSpan span = new DDSpan(instrumentationName, timestampMicro, context, links);
log.debug("Started span: {}", span);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I removed it because I could see the log also elsewhere. I will double check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was a call on a static instance log which now it is a private class instance. I will move it to the constructor instead.

final String instrumentationName,
final long timestampMicro,
@NonNull DDSpanContext context,
final List<AgentSpanLink> links,
final InternalLogger internalLogger) {
final DDSpan span = new DDSpan(instrumentationName, timestampMicro, context, links, internalLogger);
context.getTrace().registerSpan(span);
return span;
}
Expand Down Expand Up @@ -128,7 +128,8 @@ public DDSpan(
@NonNull String instrumentationName,
final long timestampMicro,
@NonNull DDSpanContext context,
final List<AgentSpanLink> links) {
final List<AgentSpanLink> links,
final InternalLogger internalLogger) {
this.context = context;
this.metrics = SpanMetricRegistry.getInstance().get(instrumentationName);
this.metrics.onSpanCreated();
Expand All @@ -144,6 +145,8 @@ public DDSpan(
}

this.links = links == null ? new CopyOnWriteArrayList<>() : new CopyOnWriteArrayList<>(links);
this.log = LoggerFactory.getLogger(DDSpan.class.getSimpleName(), internalLogger);
0xnm marked this conversation as resolved.
Show resolved Hide resolved
log.debug("Started span: {}", this);
}

public boolean isFinished() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
public class PendingTrace implements AgentTrace, PendingTraceBuffer.Element {

private static final Logger log = LoggerFactory.getLogger(PendingTrace.class);
private final Logger log;

static class Factory {
private final CoreTracer tracer;
Expand Down Expand Up @@ -162,6 +162,7 @@ private PendingTrace(
this.strictTraceWrites = strictTraceWrites;
this.healthMetrics = healthMetrics;
this.spans = new ConcurrentLinkedDeque<>();
this.log = LoggerFactory.getLogger(PendingTrace.class.getSimpleName(), tracer.internalLogger);
}

CoreTracer getTracer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.datadog.trace.util.AgentThreadFactory.THREAD_JOIN_TIMOUT_MS;
import static com.datadog.trace.util.AgentThreadFactory.newAgentThread;

import com.datadog.android.api.InternalLogger;
import com.datadog.trace.api.Config;
import com.datadog.trace.api.time.TimeSource;
import com.datadog.trace.core.monitor.HealthMetrics;
Expand Down Expand Up @@ -238,8 +239,11 @@ public DelayingPendingTraceBuffer(
}

static class DiscardingPendingTraceBuffer extends PendingTraceBuffer {
private static final Logger log = LoggerFactory.getLogger(DiscardingPendingTraceBuffer.class);
private final Logger log;

public DiscardingPendingTraceBuffer(InternalLogger internalLogger) {
log = LoggerFactory.getLogger(DiscardingPendingTraceBuffer.class.getSimpleName(), internalLogger);
}
@Override
public void start() {}

Expand All @@ -264,8 +268,8 @@ public static PendingTraceBuffer delaying(
BUFFER_SIZE, timeSource, config, healthMetrics);
}

public static PendingTraceBuffer discarding() {
return new DiscardingPendingTraceBuffer();
public static PendingTraceBuffer discarding(InternalLogger internalLogger) {
return new DiscardingPendingTraceBuffer(internalLogger);
}

public abstract void start();
Expand Down
Loading
Loading