Skip to content
Open
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 @@ -414,4 +414,9 @@ class TrackingSpanDecorator implements AgentSpan {
boolean isOutbound() {
return delegate.isOutbound()
}

@Override
boolean isFinished() {
return delegate.isFinished()
}
}
10 changes: 10 additions & 0 deletions dd-trace-core/src/test/java/datadog/trace/core/DDSpanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import datadog.trace.api.datastreams.NoopPathwayContext;
import datadog.trace.api.gateway.RequestContextSlot;
import datadog.trace.api.sampling.PrioritySampling;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
import datadog.trace.bootstrap.instrumentation.api.TagContext;
Expand Down Expand Up @@ -61,6 +62,15 @@ void setup() {
tracer = tracerBuilder().writer(writer).sampler(new RateByServiceTraceSampler()).build();
}

@Test
void isFinishedReflectsSpanCompletion() {
// Exercised via the AgentSpan interface to prove the new default resolves to DDSpan's override.
AgentSpan span = tracer.buildSpan("datadog", "finishTest").start();
assertFalse(span.isFinished(), "span must not report finished before finish()");
span.finish();
assertTrue(span.isFinished(), "span must report finished after finish()");
}

@Test
void gettersAndSetters() {
DDSpan span =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ default AgentSpan asAgentSpan() {
return this;
}

/**
* @return {@code true} once this span has finished (its duration is set). Implementations that do
* not track finish state always return {@code false}.
*/
Comment thread
Copilot marked this conversation as resolved.
default boolean isFinished() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to not have this default to false? i.e. just boolean isFinished();

It looks like the classes that implement AgentSpan, are TrackingSpanDecorator (addressed in PR already), DDSpan (already has isFinished() defined, so just needs an @Override), and ImmutableSpan (would need implementation). This would make behavior explicit per span implementation.

return false;
}

default void copyPropagationAndBaggage(final AgentSpan source) {
// no op default
}
Expand Down