Skip to content

Commit bb96b4f

Browse files
committed
Clean-up
Fixing comments builder -> ledger Restoring size estimation
1 parent f59e69c commit bb96b4f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ public static CoreTracerBuilder builder() {
193193

194194
/** A set of tags that are added to every span */
195195
private final TagMap defaultSpanTags;
196-
197-
private boolean defaultSpanTagsNeedsIntercept;
196+
private final boolean defaultSpanTagsNeedsIntercept;
198197

199198
/** number of spans in a pending trace before they get flushed */
200199
private final int partialFlushMinSpans;
@@ -308,8 +307,6 @@ public static class CoreTracerBuilder {
308307
private SingleSpanSampler singleSpanSampler;
309308
private HttpCodec.Injector injector;
310309
private HttpCodec.Extractor extractor;
311-
312-
private ContinuableScopeManager scopeManager;
313310
private TagMap localRootSpanTags;
314311
private TagMap defaultSpanTags;
315312
private Map<String, String> serviceNameMappings;
@@ -1526,14 +1523,14 @@ public CoreSpanBuilder withTag(final String tag, final Object value) {
15261523
}
15271524
TagMap.Ledger tagLedger = this.tagLedger;
15281525
if (tagLedger == null) {
1529-
// Insertion order is important, so using TagBuilder which builds up a set
1526+
// Insertion order is important, so using TagLedger which builds up a set
15301527
// of Entry modifications in order
15311528
this.tagLedger = tagLedger = TagMap.ledger();
15321529
}
15331530
if (value == null) {
15341531
// DQH - Use of smartRemove is important to avoid clobbering entries added by another map
15351532
// smartRemove only records the removal if a prior matching put has already occurred in the
1536-
// builder
1533+
// ledger
15371534
// smartRemove is O(n) but since removes are rare, this is preferable to a more complicated
15381535
// implementation in setAll
15391536
tagLedger.smartRemove(tag);
@@ -1699,7 +1696,7 @@ private DDSpanContext buildSpanContext() {
16991696
TagContext tc = (TagContext) parentContext;
17001697
traceConfig = (ConfigSnapshot) tc.getTraceConfig();
17011698
coreTags = tc.getTags();
1702-
coreTagsNeedsIntercept = true; // may intercept isn't needed?
1699+
coreTagsNeedsIntercept = true; // maybe intercept isn't needed?
17031700
origin = tc.getOrigin();
17041701
baggage = tc.getBaggage();
17051702
requestContextDataAppSec = tc.getRequestContextDataAppSec();
@@ -1771,7 +1768,12 @@ private DDSpanContext buildSpanContext() {
17711768
final TagMap mergedTracerTags = traceConfig.mergedTracerTags;
17721769
boolean mergedTracerTagsNeedsIntercept = traceConfig.mergedTracerTagsNeedsIntercept;
17731770

1774-
final int tagsSize = 0;
1771+
final int tagsSize =
1772+
mergedTracerTags.size()
1773+
+ (null == tagLedger ? 0 : tagLedger.estimateSize())
1774+
+ (null == coreTags ? 0 : coreTags.size())
1775+
+ (null == rootSpanTags ? 0 : rootSpanTags.size())
1776+
+ (null == contextualTags ? 0 : contextualTags.size());
17751777

17761778
if (builderRequestContextDataAppSec != null) {
17771779
requestContextDataAppSec = builderRequestContextDataAppSec;
@@ -1876,7 +1878,7 @@ protected ConfigSnapshot(
18761878
*/
18771879
static TagMap withTracerTags(
18781880
Map<String, ?> userSpanTags, Config config, TraceConfig traceConfig) {
1879-
final TagMap result = TagMap.create();
1881+
final TagMap result = TagMap.create(userSpanTags.size() + 5);
18801882
result.putAll(userSpanTags);
18811883
if (null != config) { // static
18821884
if (!config.getEnv().isEmpty()) {

0 commit comments

Comments
 (0)