Skip to content

Commit aa9dd27

Browse files
authored
Fix NPE in akka-http and pekko-http integrations (#9019)
Also fix a related issue where spans were not being finished while polling through leftover scopes.
1 parent 60c30c2 commit aa9dd27

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

dd-java-agent/instrumentation/akka-http/akka-http-10.0/src/main/java/datadog/trace/instrumentation/akkahttp/DatadogServerRequestResponseFlowWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ public void onUpstreamFinish() throws Exception {
168168
@Override
169169
public void onUpstreamFailure(final Throwable ex) throws Exception {
170170
ContextScope scope = scopes.poll();
171-
AgentSpan span = AgentSpan.fromContext(scope.context());
172171
if (scope != null) {
173172
// Mark the span as failed
173+
AgentSpan span = AgentSpan.fromContext(scope.context());
174174
DatadogWrapperHelper.finishSpan(span, ex);
175175
}
176176
// We will not receive any more responses from the user code, so clean up any
177177
// remaining spans
178178
scope = scopes.poll();
179179
while (scope != null) {
180-
span.finish();
180+
AgentSpan.fromContext(scope.context()).finish();
181181
scope = scopes.poll();
182182
}
183183
fail(responseOutlet, ex);

dd-java-agent/instrumentation/pekko-http-1.0/src/main/java/datadog/trace/instrumentation/pekkohttp/DatadogServerRequestResponseFlowWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ public void onUpstreamFinish() throws Exception {
141141
@Override
142142
public void onUpstreamFailure(final Throwable ex) throws Exception {
143143
ContextScope scope = scopes.poll();
144-
AgentSpan span = AgentSpan.fromContext(scope.context());
145144
if (scope != null) {
146145
// Mark the span as failed
146+
AgentSpan span = AgentSpan.fromContext(scope.context());
147147
DatadogWrapperHelper.finishSpan(span, ex);
148148
}
149149
// We will not receive any more responses from the user code, so clean up any
150150
// remaining spans
151151
scope = scopes.poll();
152152
while (scope != null) {
153-
span.finish();
153+
AgentSpan.fromContext(scope.context()).finish();
154154
scope = scopes.poll();
155155
}
156156
fail(responseOutlet, ex);

0 commit comments

Comments
 (0)