Skip to content

Commit

Permalink
Register types for reflection and use holder idiom
Browse files Browse the repository at this point in the history
  • Loading branch information
luneo7 committed Apr 7, 2024
1 parent 734e3c5 commit e2a383c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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

0 comments on commit e2a383c

Please sign in to comment.