Skip to content

Commit

Permalink
add detailed debug logging for tracing/profiler context integration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstartin authored Jun 4, 2024
1 parent 47cdadc commit ad2cc7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static com.datadog.profiling.utils.ProfilingMode.CPU;
import static com.datadog.profiling.utils.ProfilingMode.MEMLEAK;
import static com.datadog.profiling.utils.ProfilingMode.WALL;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DETAILED_DEBUG_LOGGING;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DETAILED_DEBUG_LOGGING_DEFAULT;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS_DEFAULT;

Expand Down Expand Up @@ -62,6 +64,8 @@ public final class DatadogProfiler {

private static final int MAX_NUM_ENDPOINTS = 8192;

private final boolean detailedDebugLogging;

/**
* Creates a profiler API with default configuration, may result in loading the profiler native
* library if that has not already happened, but this will not happen more than once. Applying
Expand Down Expand Up @@ -106,6 +110,9 @@ private DatadogProfiler(ConfigProvider configProvider) {
DatadogProfiler(ConfigProvider configProvider, Set<String> contextAttributes) {
this.configProvider = configProvider;
this.profiler = JavaProfilerLoader.PROFILER;
this.detailedDebugLogging =
configProvider.getBoolean(
PROFILING_DETAILED_DEBUG_LOGGING, PROFILING_DETAILED_DEBUG_LOGGING_DEFAULT);
if (JavaProfilerLoader.REASON_NOT_LOADED != null) {
throw new UnsupportedOperationException(
"Unable to instantiate datadog profiler", JavaProfilerLoader.REASON_NOT_LOADED);
Expand Down Expand Up @@ -301,6 +308,7 @@ public int offsetOf(String attribute) {
}

public void setSpanContext(long spanId, long rootSpanId) {
debugLogging(rootSpanId);
try {
profiler.setContext(spanId, rootSpanId);
} catch (IllegalStateException e) {
Expand All @@ -309,6 +317,7 @@ public void setSpanContext(long spanId, long rootSpanId) {
}

public void clearSpanContext() {
debugLogging(0L);
try {
profiler.setContext(0L, 0L);
} catch (IllegalStateException e) {
Expand Down Expand Up @@ -352,6 +361,12 @@ public boolean clearContextValue(int offset) {
return false;
}

private void debugLogging(long localRootSpanId) {
if (detailedDebugLogging && log.isDebugEnabled()) {
log.debug("localRootSpanId={}", localRootSpanId, new Throwable());
}
}

int encode(CharSequence constant) {
if (constant != null && profiler != null) {
return contextSetter.encode(constant.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,8 @@ public final class ProfilingConfig {
"profiling.timeline.events.enabled";
public static final boolean PROFILING_TIMELINE_EVENTS_ENABLED_DEFAULT = false;

public static final String PROFILING_DETAILED_DEBUG_LOGGING = "profiling.detailed.debug.logging";
public static final boolean PROFILING_DETAILED_DEBUG_LOGGING_DEFAULT = false;

private ProfilingConfig() {}
}

0 comments on commit ad2cc7a

Please sign in to comment.