From 67e175f8dc12e320e149a90c064557adc6074086 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 3 Jan 2022 16:06:57 +0100 Subject: [PATCH] WIP --- .../tx/TracePlatformTransactionManager.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/tx/TracePlatformTransactionManager.java b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/tx/TracePlatformTransactionManager.java index 9cd9d6367..2a71e9479 100644 --- a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/tx/TracePlatformTransactionManager.java +++ b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/tx/TracePlatformTransactionManager.java @@ -70,7 +70,7 @@ public class TracePlatformTransactionManager implements PlatformTransactionManag try { TransactionDefinition def = (definition != null ? definition : TransactionDefinition.withDefaults()); TransactionStatus status = this.delegate.getTransaction(definition); - span = taggedSpan(currentSpan, span, def, status); + taggedSpan(currentSpan, span, def, status); return status; } catch (Exception e) { @@ -89,17 +89,18 @@ public class TracePlatformTransactionManager implements PlatformTransactionManag } private Span taggedSpan(Span currentSpan, Span span, TransactionDefinition def, TransactionStatus status) { + Span taggedSpan = span; if (status.isNewTransaction() || currentSpan == null) { if (log.isDebugEnabled()) { - log.debug("Creating new span cause a new transaction is started"); + log.debug("Creating new span [" + taggedSpan + "] cause a new transaction is started"); } - TracePlatformTransactionManagerTags.tag(span, def, this.delegate.getClass()); + TracePlatformTransactionManagerTags.tag(taggedSpan, def, this.delegate.getClass()); } else { - span = currentSpan; + taggedSpan = currentSpan; } - this.threadLocalSpan.set(span); - return span; + this.threadLocalSpan.set(taggedSpan); + return taggedSpan; } @Override @@ -127,13 +128,16 @@ public class TracePlatformTransactionManager implements PlatformTransactionManag } finally { SleuthTxSpan.TX_SPAN.wrap(span).event(SleuthTxSpan.Events.COMMIT); - span.end(); + spanAndScope.close(); if (ex == null) { if (log.isDebugEnabled()) { log.debug("No exception was found - will clear thread local span"); } this.threadLocalSpan.remove(); } + if (log.isDebugEnabled()) { + log.debug("Restored thread local span [" + this.threadLocalSpan.get() + "]"); + } } } @@ -160,8 +164,11 @@ public class TracePlatformTransactionManager implements PlatformTransactionManag } finally { SleuthTxSpan.TX_SPAN.wrap(span).event(SleuthTxSpan.Events.ROLLBACK); - span.end(); + spanAndScope.close(); this.threadLocalSpan.remove(); + if (log.isDebugEnabled()) { + log.debug("Restored thread local span [" + this.threadLocalSpan.get() + "]"); + } } }