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

Register SpanLinkAdapter and SpanLinkJson for reflection #6892

Merged
merged 1 commit into from
Apr 11, 2024
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 @@ -47,6 +47,19 @@
{"name": "fromJson"}
]
},
{
"name" : "datadog.trace.agent.core.DDSpanLink$SpanLinkAdapter",
"methods": [
{"name": "toSpanLinkJson"}
]
},
{
"name" : "datadog.trace.agent.core.DDSpanLink$SpanLinkJson",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "datadog.trace.instrumentation.springweb.HandlerMappingResourceNameFilter",
"methods": [
Expand Down
17 changes: 12 additions & 5 deletions dd-trace-core/src/main/java/datadog/trace/core/DDSpanLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class DDSpanLink extends SpanLink {
private static final Logger LOGGER = LoggerFactory.getLogger(DDSpanLink.class);
/** The maximum of characters a span tag value can hold. */
private static final int TAG_MAX_LENGTH = 25_000;
/** JSON encoder (lazily initialized) */
private static JsonAdapter<AgentSpanLink> encoder;

protected DDSpanLink(
DDTraceId traceId, long spanId, byte traceFlags, String traceState, Attributes attributes) {
Expand Down Expand Up @@ -95,11 +93,20 @@ public static String toTag(List<AgentSpanLink> links) {
}

private static JsonAdapter<AgentSpanLink> getEncoder() {
if (encoder == null) {
return EncoderHolder.ENCODER;
}

/**
* JSON encoder (lazily initialized). This is not folded at native image build time, so it works
* as expected.
*/
private static class EncoderHolder {
static final JsonAdapter<AgentSpanLink> ENCODER = createEncoder();

private static JsonAdapter<AgentSpanLink> createEncoder() {
Moshi moshi = new Moshi.Builder().add(new SpanLinkAdapter()).build();
encoder = moshi.adapter(AgentSpanLink.class);
return moshi.adapter(AgentSpanLink.class);
}
return encoder;
}

private static class SpanLinkAdapter {
Expand Down
Loading