Skip to content

Commit 34a0019

Browse files
Fix Java 8 compatibility: Replace Map.of() with HashMap
Replaced all java.util.Map.of() calls with HashMap initialization to support Java 8 compilation. Map.of() was introduced in Java 9. Fixed in: - CoreTracer.java - RemoteWriter.java - PayloadDispatcherImpl.java
1 parent db2d08c commit 34a0019

File tree

3 files changed

+53
-89
lines changed

3 files changed

+53
-89
lines changed

dd-trace-core/src/main/java/datadog/trace/common/writer/PayloadDispatcherImpl.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,49 +110,37 @@ public void accept(int messageCount, ByteBuffer buffer) {
110110
healthMetrics.onSerialize(sizeInBytes);
111111

112112
// Antithesis: Track all send attempts
113-
Assert.sometimes(
114-
true,
115-
"trace_payloads_being_sent",
116-
java.util.Map.of(
117-
"trace_count", messageCount,
118-
"payload_size_bytes", sizeInBytes,
119-
"dropped_traces_in_payload", payload.droppedTraces(),
120-
"dropped_spans_in_payload", payload.droppedSpans()
121-
)
122-
);
113+
java.util.Map<String, Object> sendAttemptDetails = new java.util.HashMap<>();
114+
sendAttemptDetails.put("trace_count", messageCount);
115+
sendAttemptDetails.put("payload_size_bytes", sizeInBytes);
116+
sendAttemptDetails.put("dropped_traces_in_payload", payload.droppedTraces());
117+
sendAttemptDetails.put("dropped_spans_in_payload", payload.droppedSpans());
118+
Assert.sometimes(true, "trace_payloads_being_sent", sendAttemptDetails);
123119

124120
RemoteApi.Response response = api.sendSerializedTraces(payload);
125121
mapper.reset();
126122

127123
if (response.success()) {
128124
// Antithesis: Track successful sends
129-
Assert.sometimes(
130-
true,
131-
"traces_sent_successfully",
132-
java.util.Map.of(
133-
"decision", "sent_success",
134-
"trace_count", messageCount,
135-
"payload_size_bytes", sizeInBytes,
136-
"http_status", response.status()
137-
)
138-
);
125+
java.util.Map<String, Object> successDetails = new java.util.HashMap<>();
126+
successDetails.put("decision", "sent_success");
127+
successDetails.put("trace_count", messageCount);
128+
successDetails.put("payload_size_bytes", sizeInBytes);
129+
successDetails.put("http_status", response.status());
130+
Assert.sometimes(true, "traces_sent_successfully", successDetails);
139131
if (log.isDebugEnabled()) {
140132
log.debug("Successfully sent {} traces to the API", messageCount);
141133
}
142134
healthMetrics.onSend(messageCount, sizeInBytes, response);
143135
} else {
144136
// Antithesis: Track failed sends
145-
Assert.sometimes(
146-
true,
147-
"traces_failed_to_send",
148-
java.util.Map.of(
149-
"decision", "dropped_send_failed",
150-
"trace_count", messageCount,
151-
"payload_size_bytes", sizeInBytes,
152-
"http_status", response.status(),
153-
"has_exception", response.exception() != null
154-
)
155-
);
137+
java.util.Map<String, Object> failedDetails = new java.util.HashMap<>();
138+
failedDetails.put("decision", "dropped_send_failed");
139+
failedDetails.put("trace_count", messageCount);
140+
failedDetails.put("payload_size_bytes", sizeInBytes);
141+
failedDetails.put("http_status", response.status());
142+
failedDetails.put("has_exception", response.exception() != null);
143+
Assert.sometimes(true, "traces_failed_to_send", failedDetails);
156144
if (log.isDebugEnabled()) {
157145
log.debug(
158146
"Failed to send {} traces of size {} bytes to the API", messageCount, sizeInBytes);

dd-trace-core/src/main/java/datadog/trace/common/writer/RemoteWriter.java

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,10 @@ protected RemoteWriter(
7070
public void write(final List<DDSpan> trace) {
7171
if (closed) {
7272
// Antithesis: Track traces dropped during shutdown
73-
Assert.sometimes(
74-
true,
75-
"trace_dropped_writer_closed",
76-
java.util.Map.of(
77-
"decision", "dropped_shutdown",
78-
"span_count", trace.size()
79-
)
80-
);
73+
java.util.Map<String, Object> shutdownDetails = new java.util.HashMap<>();
74+
shutdownDetails.put("decision", "dropped_shutdown");
75+
shutdownDetails.put("span_count", trace.size());
76+
Assert.sometimes(true, "trace_dropped_writer_closed", shutdownDetails);
8177
// We can't add events after shutdown otherwise it will never complete shutting down.
8278
log.debug("Dropped due to shutdown: {}", trace);
8379
handleDroppedTrace(trace);
@@ -91,16 +87,12 @@ public void write(final List<DDSpan> trace) {
9187
switch (traceProcessingWorker.publish(root, samplingPriority, trace)) {
9288
case ENQUEUED_FOR_SERIALIZATION:
9389
// Antithesis: Track traces enqueued for sending
94-
Assert.sometimes(
95-
true,
96-
"trace_enqueued_for_send",
97-
java.util.Map.of(
98-
"decision", "enqueued",
99-
"trace_id", root.getTraceId().toString(),
100-
"span_count", trace.size(),
101-
"sampling_priority", samplingPriority
102-
)
103-
);
90+
java.util.Map<String, Object> enqueuedDetails = new java.util.HashMap<>();
91+
enqueuedDetails.put("decision", "enqueued");
92+
enqueuedDetails.put("trace_id", root.getTraceId().toString());
93+
enqueuedDetails.put("span_count", trace.size());
94+
enqueuedDetails.put("sampling_priority", samplingPriority);
95+
Assert.sometimes(true, "trace_enqueued_for_send", enqueuedDetails);
10496
log.debug("Enqueued for serialization: {}", trace);
10597
healthMetrics.onPublish(trace, samplingPriority);
10698
break;
@@ -109,31 +101,23 @@ public void write(final List<DDSpan> trace) {
109101
break;
110102
case DROPPED_BY_POLICY:
111103
// Antithesis: Track traces dropped by policy
112-
Assert.sometimes(
113-
true,
114-
"trace_dropped_by_policy",
115-
java.util.Map.of(
116-
"decision", "dropped_policy",
117-
"trace_id", root.getTraceId().toString(),
118-
"span_count", trace.size(),
119-
"sampling_priority", samplingPriority
120-
)
121-
);
104+
java.util.Map<String, Object> policyDetails = new java.util.HashMap<>();
105+
policyDetails.put("decision", "dropped_policy");
106+
policyDetails.put("trace_id", root.getTraceId().toString());
107+
policyDetails.put("span_count", trace.size());
108+
policyDetails.put("sampling_priority", samplingPriority);
109+
Assert.sometimes(true, "trace_dropped_by_policy", policyDetails);
122110
log.debug("Dropped by the policy: {}", trace);
123111
handleDroppedTrace(trace);
124112
break;
125113
case DROPPED_BUFFER_OVERFLOW:
126114
// Antithesis: Track traces dropped due to buffer overflow
127-
Assert.sometimes(
128-
true,
129-
"trace_dropped_buffer_overflow",
130-
java.util.Map.of(
131-
"decision", "dropped_buffer_overflow",
132-
"trace_id", root.getTraceId().toString(),
133-
"span_count", trace.size(),
134-
"sampling_priority", samplingPriority
135-
)
136-
);
115+
java.util.Map<String, Object> overflowDetails = new java.util.HashMap<>();
116+
overflowDetails.put("decision", "dropped_buffer_overflow");
117+
overflowDetails.put("trace_id", root.getTraceId().toString());
118+
overflowDetails.put("span_count", trace.size());
119+
overflowDetails.put("sampling_priority", samplingPriority);
120+
Assert.sometimes(true, "trace_dropped_buffer_overflow", overflowDetails);
137121
if (log.isDebugEnabled()) {
138122
log.debug("Dropped due to a buffer overflow: {}", trace);
139123
} else {

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,29 +1249,21 @@ void write(final List<DDSpan> trace) {
12491249
boolean published = forceKeep || traceCollector.sample(spanToSample);
12501250
if (published) {
12511251
// Antithesis: Track traces accepted by sampling
1252-
Assert.sometimes(
1253-
true,
1254-
"trace_accepted_by_sampling",
1255-
java.util.Map.of(
1256-
"decision", "accepted",
1257-
"trace_id", writtenTrace.get(0).getTraceId().toString(),
1258-
"span_count", writtenTrace.size(),
1259-
"sampling_priority", spanToSample.samplingPriority()
1260-
)
1261-
);
1252+
java.util.Map<String, Object> acceptedDetails = new java.util.HashMap<>();
1253+
acceptedDetails.put("decision", "accepted");
1254+
acceptedDetails.put("trace_id", writtenTrace.get(0).getTraceId().toString());
1255+
acceptedDetails.put("span_count", writtenTrace.size());
1256+
acceptedDetails.put("sampling_priority", spanToSample.samplingPriority());
1257+
Assert.sometimes(true, "trace_accepted_by_sampling", acceptedDetails);
12621258
writer.write(writtenTrace);
12631259
} else {
12641260
// Antithesis: Track traces dropped by sampling
1265-
Assert.sometimes(
1266-
true,
1267-
"trace_dropped_by_sampling",
1268-
java.util.Map.of(
1269-
"decision", "dropped_sampling",
1270-
"trace_id", writtenTrace.get(0).getTraceId().toString(),
1271-
"span_count", writtenTrace.size(),
1272-
"sampling_priority", spanToSample.samplingPriority()
1273-
)
1274-
);
1261+
java.util.Map<String, Object> droppedDetails = new java.util.HashMap<>();
1262+
droppedDetails.put("decision", "dropped_sampling");
1263+
droppedDetails.put("trace_id", writtenTrace.get(0).getTraceId().toString());
1264+
droppedDetails.put("span_count", writtenTrace.size());
1265+
droppedDetails.put("sampling_priority", spanToSample.samplingPriority());
1266+
Assert.sometimes(true, "trace_dropped_by_sampling", droppedDetails);
12751267
// with span streaming this won't work - it needs to be changed
12761268
// to track an effective sampling rate instead, however, tests
12771269
// checking that a hard reference on a continuation prevents

0 commit comments

Comments
 (0)