Clean up Observation from context after command completion.
We now restore the previous Observation parent after completing the Observation to avoid unintentional nesting of observations. Previously, a command became the parent of an earlier command on the same thread regardless of whether the earlier command has been finished or whether it was active.
Observation nesting now considers only commands that are still active restoring their parent after completion to avoid invalid nesting and with that, to not allocate observation graphs that allocate infinite memory.
Closes: #5064
Original Pull Request: #5067
pull/5073/head
Mark Paluch2 months agocommitted byChristoph Strobl
@ -113,10 +113,6 @@ public class MongoObservationCommandListener implements CommandListener {
@@ -113,10 +113,6 @@ public class MongoObservationCommandListener implements CommandListener {
@ -141,22 +137,20 @@ public class MongoObservationCommandListener implements CommandListener {
@@ -141,22 +137,20 @@ public class MongoObservationCommandListener implements CommandListener {
@ -165,18 +159,17 @@ public class MongoObservationCommandListener implements CommandListener {
@@ -165,18 +159,17 @@ public class MongoObservationCommandListener implements CommandListener {
@ -188,7 +181,18 @@ public class MongoObservationCommandListener implements CommandListener {
@@ -188,7 +181,18 @@ public class MongoObservationCommandListener implements CommandListener {
return;
}
action.accept(observation,context);
try{
action.accept(observation,context);
}finally{
observation.stop();
if(log.isDebugEnabled()){
log.debug(
"Restoring parent observation ["+observation+"] for Mongo instrumentation and put it in Mongo context");
@ -210,7 +214,7 @@ public class MongoObservationCommandListener implements CommandListener {
@@ -210,7 +214,7 @@ public class MongoObservationCommandListener implements CommandListener {
}
if(log.isDebugEnabled()){
log.debug("No observation was found - will not create any child observations");
log.debug("No observation was found: Creating a new root observation");