Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ public int offsetOf(String attribute) {
return contextSetter.offsetOf(attribute);
}

public void setSpanContext(long spanId, long rootSpanId) {
public void setSpanContext(long rootSpanId, long spanId, long traceIdHigh, long traceIdLow) {
debugLogging(rootSpanId);
try {
profiler.setContext(spanId, rootSpanId);
profiler.setContext(rootSpanId, spanId, traceIdHigh, traceIdLow);
} catch (Throwable e) {
log.debug("Failed to clear context", e);
}
Expand All @@ -365,28 +365,16 @@ public void setSpanContext(long spanId, long rootSpanId) {
public void clearSpanContext() {
debugLogging(0L);
try {
profiler.setContext(0L, 0L);
profiler.setContext(0L, 0L, 0L, 0L);
} catch (Throwable e) {
log.debug("Failed to set context", e);
}
}

public boolean setContextValue(int offset, int encoding) {
if (contextSetter != null && offset >= 0) {
try {
return contextSetter.setContextValue(offset, encoding);
} catch (Throwable e) {
log.debug("Failed to set context", e);
}
}
return false;
}

public boolean setContextValue(int offset, CharSequence value) {
if (contextSetter != null && offset >= 0) {
int encoding = encode(value);
if (contextSetter != null && offset >= 0 && value != null) {
try {
return contextSetter.setContextValue(offset, encoding);
return contextSetter.setContextValue(offset, value.toString());
} catch (Throwable e) {
log.debug("Failed to set context", e);
}
Expand Down Expand Up @@ -425,13 +413,6 @@ private void debugLogging(long localRootSpanId) {
}
}

int encode(CharSequence constant) {
if (constant != null && profiler != null) {
return contextSetter.encode(constant.toString());
}
return 0;
}

public int[] snapshot() {
if (contextSetter != null) {
return contextSetter.snapshotTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public void close() {
public void activate(Object context) {
if (context instanceof ProfilerContext) {
ProfilerContext profilerContext = (ProfilerContext) context;
DDPROF.setSpanContext(profilerContext.getSpanId(), profilerContext.getRootSpanId());
DDPROF.setContextValue(SPAN_NAME_INDEX, profilerContext.getEncodedOperationName());
DDPROF.setContextValue(RESOURCE_NAME_INDEX, profilerContext.getEncodedResourceName());
DDPROF.setSpanContext(
profilerContext.getRootSpanId(),
profilerContext.getSpanId(),
profilerContext.getTraceIdHigh(),
profilerContext.getTraceIdLow());
DDPROF.setContextValue(SPAN_NAME_INDEX, profilerContext.getOperationName());
DDPROF.setContextValue(RESOURCE_NAME_INDEX, profilerContext.getResourceName());
}
}
};
Expand All @@ -67,27 +71,6 @@ public void onDetach() {
}
}

@Override
public int encode(CharSequence constant) {
return DDPROF.encode(constant);
}

@Override
public int encodeOperationName(CharSequence constant) {
if (SPAN_NAME_INDEX >= 0) {
return DDPROF.encode(constant);
}
return 0;
}

@Override
public int encodeResourceName(CharSequence constant) {
if (RESOURCE_NAME_INDEX >= 0) {
return DDPROF.encode(constant);
}
return 0;
}

@Override
public String name() {
return "ddprof";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

public class DatadogProfilingScope implements ProfilingScope {
private final DatadogProfiler profiler;
private final int[] snapshot;

public DatadogProfilingScope(DatadogProfiler profiler) {
this.profiler = profiler;
this.snapshot = profiler.snapshot();
}

@Override
Expand Down Expand Up @@ -38,8 +36,7 @@ public void clearContextValue(ProfilingContextAttribute attribute) {

@Override
public void close() {
for (int i = 0; i < snapshot.length; i++) {
profiler.setContextValue(i, snapshot[i]);
}
// ddprof 1.41.0 removed the int-encoding setter; snapshot/restore of tag
// context across nested scopes is no longer supported by the library.
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.datadog.profiling.ddprof;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -180,7 +179,6 @@ public void testContextRegistration() {

DatadogProfilerContextSetter fooSetter = new DatadogProfilerContextSetter("foo", profiler);
DatadogProfilerContextSetter barSetter = new DatadogProfilerContextSetter("bar", profiler);
int[] snapshot0 = profiler.snapshot();
try (ProfilingScope ignored = new DatadogProfilingScope(profiler)) {
fooSetter.set("foo0");
barSetter.set("bar0");
Expand All @@ -194,9 +192,7 @@ public void testContextRegistration() {
inner.setContextValue("bar", "bar2");
assertFalse(Arrays.equals(snapshot2, profiler.snapshot()));
}
assertArrayEquals(snapshot1, profiler.snapshot());
}
assertArrayEquals(snapshot0, profiler.snapshot());
}

private static ConfigProvider configProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ public long getRootSpanId() {
return getRootSpanContextOrThis().spanId;
}

@Override
public long getTraceIdHigh() {
return traceId.toHighOrderLong();
}

@Override
public long getTraceIdLow() {
return traceId.toLong();
}

@Override
public int getEncodedOperationName() {
return encodedOperationName;
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ forbiddenapis = "3.10"
spotbugs_annotations = "4.9.8"

# DataDog libs and forks
ddprof = "1.40.1"
ddprof = "1.41.0"
dogstatsd = "4.4.5"
okhttp = "3.12.15" # Datadog fork to support Java 7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ public interface ProfilerContext {
*/
long getRootSpanId();

/**
* @return upper 64 bits of the 128-bit trace id, or 0 if not available
*/
default long getTraceIdHigh() {
return 0L;
}

/**
* @return lower 64 bits of the 128-bit trace id, or 0 if not available
*/
default long getTraceIdLow() {
return 0L;
}

int getEncodedOperationName();

CharSequence getOperationName();
Expand Down
Loading