Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ docs/ Developer documentation (see below)
- **Forked tests**: Use `ForkedTest` suffix when tests need a separate JVM
- **Flaky tests**: Annotate with `@Flaky` — they are skipped in CI by default
- **Instrumentation one-shot methods**: Never extract the return values of `triggerClasses()`, `contextStore()`, `classLoaderMatcher()`, or `methodAdvice()` into static constants. These are called once by the framework — extracting to a constant adds constant-pool bloat with no benefit.
- **Scope lifecycle order**: Keep the scope open until all work that needs the current active span is done — decorator calls, async callback registration, etc. Required order: decorator calls and callback registration, then `scope.close()`, then `span.finish()`.

## PR conventions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ public static void methodExit(

if (throwable == null) {
responseFuture.onComplete(new OnCompleteHandler(span), thiz.system().dispatcher());
scope.close();
} else {
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
}
scope.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public static void methodExit(
if (throwable == null) {
responseFuture.onComplete(
new AkkaHttpClientHelpers.OnCompleteHandler(span), thiz.system().dispatcher());
scope.close();
} else {
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
}
scope.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ public static void methodExit(
if (scope == null) {
return;
}
final AgentSpan span = scope.span();
try {
if (throwable != null) {
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();
}
} finally {
scope.close();
if (throwable != null) {
span.finish();
}
}
Comment thread
mcculls marked this conversation as resolved.
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ public static void after(
@Advice.Thrown Throwable error,
@Advice.Local("$$ddSpan") AgentSpan span)
throws Throwable {
if (null != error && null != span) {
DECORATE.onError(span, error);
DECORATE.beforeFinish(span);
}
if (null != scope) {
scope.close();
}
if (null != error && null != span) {
DECORATE.onError(span, error);
DECORATE.beforeFinish(span);
span.finish();
throw error;
}
Expand Down Expand Up @@ -210,8 +212,8 @@ public static void closeObserver(
@Advice.Enter AgentScope scope, @Advice.Argument(0) Status status) {
if (null != scope) {
DECORATE.onClose(scope.span(), status);
scope.span().finish();
scope.close();
scope.span().finish();
}
}
}
Expand All @@ -238,15 +240,17 @@ public static void closeObserver(
@Advice.Argument(0) Status status,
@Advice.FieldValue("closed") boolean closed) {
if (null != scope) {
AgentSpan span = null;
if (closed) {
AgentSpan span =
InstrumentationContext.get(ClientCall.class, AgentSpan.class).remove(call);
span = InstrumentationContext.get(ClientCall.class, AgentSpan.class).remove(call);
if (span != null) {
DECORATE.onClose(span, status);
span.finish();
}
}
scope.close();
if (span != null) {
span.finish();
}
}
}
}
Expand All @@ -268,8 +272,8 @@ public static AgentScope before() {
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void after(@Advice.Enter AgentScope scope) {
if (null != scope) {
scope.span().finish();
scope.close();
scope.span().finish();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ static void exit(

CallDepthThreadLocalMap.reset(RequestHandler.class);

final AgentSpan span = scope.span();
try {
final AgentSpan span = scope.span();
if (throwable != null) {
span.addThrowable(throwable);
}
String lambdaRequestId = awsContext.getAwsRequestId();

if (throwable == null) {
AgentTracer.get().notifyAppSecEnd(span, result);
} else {
span.addThrowable(throwable);
}
// Force the resource name back to the literal placeholder marker right
// before finish so that the Datadog Lambda Extension's filter
Expand All @@ -144,10 +141,11 @@ static void exit(
// and the HTTP/JAX-RS instrumentation will already have written
// HTTP_FRAMEWORK_ROUTE (3) by this point.
span.setResourceName(INVOCATION_SPAN_NAME, ResourceNamePriorities.TAG_INTERCEPTOR);
span.finish();
AgentTracer.get().notifyExtensionEnd(span, result, null != throwable, lambdaRequestId);
} finally {
scope.close();
span.finish();
AgentTracer.get()
.notifyExtensionEnd(span, result, null != throwable, awsContext.getAwsRequestId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ public static void exit(
CallDepthThreadLocalMap.decrementCallDepth(ECIInteraction.class);

if (null != scope) {
DECORATE.onError(scope.span(), throwable);
DECORATE.beforeFinish(scope.span());
scope.span().finish();
AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static void exit(

DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();
scope.close();
span.finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public AgentScope onStepStart(StepDefinition step, Object[] arguments) {
public void onStepFinish(AgentScope scope) {
AgentSpan span = scope.span();
beforeFinish(span);
span.finish();
scope.close();
span.finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public static void endMethod(
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}

Expand Down Expand Up @@ -133,8 +133,8 @@ public static void endMethod(
DECORATE.onOperation(span, entity);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}

Expand Down Expand Up @@ -164,8 +164,8 @@ public static void endMethod(
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}

Expand Down Expand Up @@ -195,8 +195,8 @@ public static void endMethod(
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public static void endExecute(
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static void end(
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);

span.finish();
scope.close();
span.finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by RestResponseListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by RestResponseListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else if (result instanceof Response) {
final AgentSpan span = scope.span();
if (((Response) result).getHost() != null) {
DECORATE.onResponse(span, ((Response) result));
}
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
// async call, span finished by RestResponseListener
}
scope.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by TransportActionListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by TransportActionListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by TransportActionListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by TransportActionListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public static void stopSpan(
final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
scope.close();
span.finish();
} else {
scope.close();
}
scope.close();
// span finished by TransportActionListener
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public static void setupCallback(
if (throwable != null) {
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(scope.context());
span.finish();
scope.close();
span.finish();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public void onSuccess(final Response response) {
}

DECORATE.beforeFinish(scope.context());
span.finish();
scope.close();
span.finish();
}

@Override
public void onFailure(final Throwable cause) {
final AgentSpan span = AgentSpan.fromContext(scope.context());
DECORATE.onError(span, cause);
DECORATE.beforeFinish(scope.context());
span.finish();
scope.close();
span.finish();
}
}
Loading