Skip to content

Commit 7cc5b0c

Browse files
authored
Merge pull request #2088 from newrelic/lazy-guid-init
Lazy init of GUIDs on DefaultTracers
2 parents eb28f6c + 6fba5c8 commit 7cc5b0c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

newrelic-agent/src/main/java/com/newrelic/agent/trace/TransactionGuidFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.concurrent.ThreadLocalRandom;
1111

1212
public class TransactionGuidFactory {
13+
private static final char[] hexchars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
1314

1415
private TransactionGuidFactory() {
1516
}
@@ -21,7 +22,6 @@ public static String generate16CharGuid() {
2122
// return Long.toHexString(Math.abs(randomHolder.get().nextLong()))
2223
// In addition, this one returns 16 useful digits, while the obvious one returns slightly fewer.
2324
// Note that the digits are generated in "reverse order", which is perfectly fine here.
24-
final char[] hexchars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
2525
long random = ThreadLocalRandom.current().nextLong();
2626
char[] result = new char[16];
2727
for (int i = 0; i < 16; ++i) {

newrelic-agent/src/main/java/com/newrelic/agent/tracers/DefaultTracer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public DefaultTracer(TransactionActivity txa, ClassMethodSignature sig, Object o
145145
}
146146

147147
this.tracerFlags = (byte) tracerFlags;
148-
this.guid = TransactionGuidFactory.generate16CharGuid();
149148
}
150149

151150
public DefaultTracer(TransactionActivity txa, ClassMethodSignature sig, Object object,
@@ -169,7 +168,10 @@ public void removeTransactionSegment() {
169168

170169
@Override
171170
public String getGuid() {
172-
return guid;
171+
if (this.guid == null) {
172+
this.guid = TransactionGuidFactory.generate16CharGuid();
173+
}
174+
return this.guid;
173175
}
174176

175177
@Override

0 commit comments

Comments
 (0)