I have an issue with the Java APM agent, after updating from 1.36 to 1.37 or 1.38 one of my plugins stopped working. I have a plugin which adds instrumentation for the r2dbc postgres driver. The relevant code of this plugins looks like this:
@Advice.OnMethodExit(inline = false)
@Advice.AssignReturned.ToReturned(typing = Assigner.Typing.DYNAMIC)
public static Flux<PostgresqlResult> onExitExecute(@Advice.Argument(0) String sql,
@Advice.Return Flux<io.r2dbc.postgresql.api.PostgresqlResult> result) {
return Mono.defer(() -> Mono.just(createSpan(sql)))
.flatMapMany(spanBuilder -> {
LOG.debug("Starting span");
LOG.debug("Parent: {}", Span.current());
Span span = spanBuilder
.startSpan();
return result
.doOnComplete(() -> {
LOG.debug("Closing span");
span.setStatus(StatusCode.OK).end();
})
.doOnError(throwable -> {
LOG.debug("Closing span");
span.recordException(throwable).end();
});
});
}
After updating the APM agent version in the application using this plugin, 'Span.current()' is no longer the actual active span. See this logging:
1.36
2023-05-08 13:27:00,504 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (133)
2023-05-08 13:27:00.504 DEBUG 7220 --- [actor-tcp-nio-3] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Found signature SELECT FROM patient
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (134)
2023-05-08 13:27:00.504 DEBUG 7220 --- [actor-tcp-nio-3] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Starting span
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (135)
2023-05-08 13:27:00.504 DEBUG 7220 --- [actor-tcp-nio-3] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Parent: OtelSpan['PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919)]
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.Span - startSpan '' 00-5b0577cff59fc51336b6c0bf5a6904d0-fb1827a00c5e18a0-01 (53382723)
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (136)
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to '' 00-5b0577cff59fc51336b6c0bf5a6904d0-fb1827a00c5e18a0-01 (53382723) (1)
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (137)
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-5b0577cff59fc51336b6c0bf5a6904d0-53bb7f8cac0efe8e-01 (6582d919) (138)
2023-05-08 13:27:00,504 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'SELECT FROM patient' 00-5b0577cff59fc51336b6c0bf5a6904d0-fb1827a00c5e18a0-01 (53382723) (2)
1.38
2023-05-08 13:30:27,100 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (116)
2023-05-08 13:30:27,100 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (117)
2023-05-08 13:30:27.100 DEBUG 7533 --- [actor-tcp-nio-2] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Creating R2DBC span
2023-05-08 13:30:27.100 DEBUG 7533 --- [actor-tcp-nio-2] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Found signature SELECT FROM patient
2023-05-08 13:30:27,100 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (118)
2023-05-08 13:30:27.100 DEBUG 7533 --- [actor-tcp-nio-2] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Starting span
2023-05-08 13:30:27.100 DEBUG 7533 --- [actor-tcp-nio-2] [default] h.a.a.r.p.R2dbcPostgresqlInstrumentation : Parent: PropagatedSpan{ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}}
2023-05-08 13:30:27,100 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (119)
2023-05-08 13:30:27,100 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (120)
2023-05-08 13:30:27,100 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (121)
2023-05-08 13:30:27,100 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (122)
2023-05-08 13:30:27,101 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (123)
2023-05-08 13:30:27,101 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (124)
2023-05-08 13:30:27,101 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (125)
2023-05-08 13:30:27,101 [reactor-tcp-nio-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (126)
2023-05-08 13:30:27,101 [reactor-tcp-nio-2] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'PatientRestController#getAllPatients' 00-a95764c6e36e44a2475a09fea27c21bb-cc15f9b7457009c6-01 (2f0e0a86) (127)
As you can see 'Parent:' log line is not showing the actual active span when running with agent version 1.38. The only change between these two runs is the APM agent version. I've tried to look through the changes made between 1.36 and 1.37/1.38 what could have broken this, but so for I've been unable to narrow down the actual cause.
I could really use some pointers on how to debug this, because at the moment I don't really know where to start.