-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement DroppedSpanStats #1511
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a first pass and left some comments
src/Elastic.Apm/Model/Transaction.cs
Outdated
if (_droppedSpanStatsMap.ContainsKey((destinationServiceResource, outcome))) | ||
{ | ||
_droppedSpanStatsMap[(destinationServiceResource, outcome)].DurationCount++; | ||
_droppedSpanStatsMap[(destinationServiceResource, outcome)].DurationSumUs += duration; | ||
} | ||
else | ||
{ | ||
_droppedSpanStatsMap.Add((destinationServiceResource, outcome), | ||
new DroppedSpanStats(destinationServiceResource, outcome, duration)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.TryGetValue(...)
would likely perform better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed it.
src/Elastic.Apm/Model/Transaction.cs
Outdated
/// </summary> | ||
[JsonIgnore] | ||
public IConfiguration Configuration { get; } | ||
private Dictionary<(string, Outcome), DroppedSpanStats> _droppedSpanStatsMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An internal struct to represent (string, Outcome)
might be preferable, and be a move towards resolving some of the issues encountered with System.ValueTuple and .NET Framework from time to time e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - yeah, I introduced a struct for this.
capturedSpan.Context.Db = new Database | ||
{ | ||
capturedSpan.Context.Db = new Database | ||
{ | ||
Statement = GetDbSpanName(dbCommand), | ||
Instance = dbCommand.Connection.Database, | ||
Type = Database.TypeSql | ||
}; | ||
|
||
capturedSpan.Context.Destination = GetDestination(dbCommand.Connection?.ConnectionString, defaultPort); | ||
} | ||
Statement = GetDbSpanName(dbCommand), Instance = dbCommand.Connection.Database, Type = Database.TypeSql | ||
}; | ||
|
||
capturedSpan.Context.Destination = GetDestination(dbCommand.Connection?.ConnectionString, defaultPort); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these now in theory be captured when starting the span?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think actually this could have been in StartSpan(...)
prior to this change as well. Although I don't think it changes much.
@russcam this is ready for another round. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I left some suggestions for small changes.
One thing that looks missing from this PR is documentation for dropped span stats. Should that be added?
I don't think we need any extra docs in this repo. This is following the spec which documents this. |
|
Introduced a field to store Prior to the commit (benchmark is included - it's 1 transaction with 10 spans, 9 of those are dropped):
After the commit:
|
Another benchmark, 1000spans, 1sampled, the rest isn't. This PR:
master:
So as it seems we don't really add overhead to spans that are not sampled. |
Some more findings: This PR 1K spans, 0,5K sampled
master:
This is all .NET Core - I don't really see any sign of a huge overhead added by this PR. The reason Now, the |
…-agent-dotnet into DroppedSpanStats
Solves elastic/apm#497
According to the spec this PR adds a new field to
Transaction
which contains aggregated data about dropped spans.We had 1 optimization prior to this PR: we did not keep records of destination and resource for dropped spans, which we won't be able to do once we collect DroppenSpansStats.