Skip to content

Commit e6e7749

Browse files
authored
Make traceparent header creation thread-safe (#2747)
1 parent e9aacfd commit e6e7749

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ version of classes that are available also in the parent (bootstrap) class loade
5151
* Avoid warning when log correlation option is provided in remote config - {pull}2765[#2765]
5252
* Update `async-profiler` to 1.8.8 to avoid missing symbol spam - {pull}2775[#2775]
5353
* Fix container ID discovery for containers managed through AWS Fargate - {pull}2772[#2772]
54+
* Make `traceparent` header computation thread-safe - {pull}2747[#2747]
5455
5556
[[release-notes-1.x]]
5657
=== Java Agent version 1.x

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,14 @@ <C> boolean propagateTraceContext(C carrier, BinaryHeaderSetter<C> headerSetter)
586586
*/
587587
StringBuilder getOutgoingTraceParentTextHeader() {
588588
if (outgoingTextHeader.length() == 0) {
589-
// for unsampled traces, propagate the ID of the transaction in calls to downstream services
590-
// such that the parentID of those transactions point to a transaction that exists
591-
// remember that we do report unsampled transactions
592-
fillTraceParentHeader(outgoingTextHeader, isSampled() ? id : transactionId);
589+
synchronized (outgoingTextHeader) {
590+
if (outgoingTextHeader.length() == 0) {
591+
// for unsampled traces, propagate the ID of the transaction in calls to downstream services
592+
// such that the parentID of those transactions point to a transaction that exists
593+
// remember that we do report unsampled transactions
594+
fillTraceParentHeader(outgoingTextHeader, isSampled() ? id : transactionId);
595+
}
596+
}
593597
}
594598
return outgoingTextHeader;
595599
}

0 commit comments

Comments
 (0)