Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github-actions-c80…
Browse files Browse the repository at this point in the history
…90e47c1
  • Loading branch information
stevejgordon authored Feb 19, 2024
2 parents 9de958d + 53771b7 commit 5494d03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
- name: Rustup
if: "${{ inputs.rust == 'true' }}"
shell: bash
run: rustup default 1.67.1
run: rustup default 1.69.0

# - name: Cargo make
# if: "${{ inputs.rust == 'true' }}"
Expand Down
43 changes: 20 additions & 23 deletions src/Elastic.Apm/Model/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private void CheckAndCaptureBaggage()
/// <summary>
/// Internal dictionary to keep track of and look up dropped span stats.
/// </summary>
private Dictionary<DroppedSpanStatsKey, DroppedSpanStats> _droppedSpanStatsMap;
private ConcurrentDictionary<DroppedSpanStatsKey, DroppedSpanStats> _droppedSpanStatsMap;

private bool _isEnded;

Expand Down Expand Up @@ -552,38 +552,35 @@ private Activity StartActivity(bool shouldRestartTrace)
return activity;
}

private readonly object _lock = new();
internal void UpdateDroppedSpanStats(string serviceTargetType, string serviceTargetName, string destinationServiceResource, Outcome outcome,
double duration
)
{
//lock the lazy initialization of the dictionary
if (_droppedSpanStatsMap == null)
{
_droppedSpanStatsMap = new Dictionary<DroppedSpanStatsKey, DroppedSpanStats>
{
{
new DroppedSpanStatsKey(serviceTargetType, serviceTargetName, outcome),
new DroppedSpanStats(serviceTargetType, serviceTargetName, destinationServiceResource, outcome, duration)
}
};
lock (_lock)
_droppedSpanStatsMap ??= new ConcurrentDictionary<DroppedSpanStatsKey, DroppedSpanStats>();
}
else

lock (_lock)
{
if (_droppedSpanStatsMap.Count >= 128)
return;

if (_droppedSpanStatsMap.TryGetValue(new DroppedSpanStatsKey(serviceTargetType, serviceTargetName, outcome), out var item))
{
item.Duration ??=
new DroppedSpanStats.DroppedSpanDuration { Sum = new DroppedSpanStats.DroppedSpanDuration.DroppedSpanDurationSum() };

item.Duration.Count++;
item.Duration.Sum.UsRaw += duration;
}
else
{
_droppedSpanStatsMap.Add(new DroppedSpanStatsKey(serviceTargetType, serviceTargetName, outcome),
new DroppedSpanStats(serviceTargetType, serviceTargetName, destinationServiceResource, outcome, duration));
}
//AddOrUpdate callbacks can run multiple times so still wrapping this in a lock
var key = new DroppedSpanStatsKey(serviceTargetType, serviceTargetName, outcome);
_droppedSpanStatsMap.AddOrUpdate(key,
_ => new DroppedSpanStats(serviceTargetType, serviceTargetName, destinationServiceResource, outcome, duration),
(_, stats) =>
{
stats.Duration ??=
new DroppedSpanStats.DroppedSpanDuration { Sum = new DroppedSpanStats.DroppedSpanDuration.DroppedSpanDurationSum() };

stats.Duration.Count++;
stats.Duration.Sum.UsRaw += duration;
return stats;
});
}
}

Expand Down

0 comments on commit 5494d03

Please sign in to comment.