Skip to content

Commit a790e7b

Browse files
authored
Merge pull request #124 from DataDog/tyler/prevent-0-duration
Prevent traces from finishing with 0 duration
2 parents 17de05e + ed6729c commit a790e7b

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

dd-trace/src/main/java/com/datadoghq/trace/DDBaseSpan.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public final void finish() {
5050
}
5151

5252
public final void finish(final long stoptimeMicros) {
53-
this.durationNano = TimeUnit.MICROSECONDS.toNanos(stoptimeMicros - this.startTimeMicro);
53+
// Ensure that duration is at least 1. Less than 1 is possible due to our use of system clock instead of nano time.
54+
this.durationNano =
55+
Math.max(1, TimeUnit.MICROSECONDS.toNanos(stoptimeMicros - this.startTimeMicro));
5456
afterFinish();
5557
}
5658

dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,16 @@ private DDSpan startSpan() {
223223

224224
@Override
225225
public ActiveSpan startActive() {
226-
final ActiveSpan activeSpan = spanSource.makeActive(startSpan());
227-
log.debug("{} - Starting a new active span.", activeSpan);
226+
final DDSpan span = startSpan();
227+
final ActiveSpan activeSpan = spanSource.makeActive(span);
228+
log.debug("Starting a new active span: {}", span);
228229
return activeSpan;
229230
}
230231

231232
@Override
232233
public DDSpan startManual() {
233234
final DDSpan span = startSpan();
234-
log.debug("{} - Starting a new manuel span.", span);
235+
log.debug("Starting a new manual span: {}", span);
235236
return span;
236237
}
237238

dd-trace/src/main/java/com/datadoghq/trace/writer/DDAgentWriter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ public void run() {
141141
final Future<Long> future = executor.submit(new SendingTask());
142142
try {
143143
final long nbTraces = future.get(API_TIMEOUT_SECONDS, TimeUnit.SECONDS);
144-
log.debug("Successfully sending {} traces to the API", nbTraces);
144+
if (nbTraces > 0) {
145+
log.debug("Successfully sent {} traces to the API", nbTraces);
146+
}
145147
} catch (final TimeoutException e) {
146-
log.debug("Timeout! Fail to send traces to the API: {}", e.getMessage());
148+
log.debug("Timeout! Failed to send traces to the API: {}", e.getMessage());
147149
} catch (final Throwable e) {
148-
log.debug("Fail to send traces to the API: {}", e.getMessage());
150+
log.debug("Failed to send traces to the API: {}", e.getMessage());
149151
}
150152
}
151153

0 commit comments

Comments
 (0)