Skip to content

Commit

Permalink
Merge branch 'master' into netcoreall/cosmosdb
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam authored Aug 23, 2021
2 parents 25b3666 + 36a7caf commit d499be8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
24 changes: 24 additions & 0 deletions src/Elastic.Apm.Specification/specs/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@
"maxLength": 1024
}
},
"network": {
"description": "Network holds information about the network over which the monitored service is communicating.",
"type": [
"null",
"object"
],
"properties": {
"connection": {
"type": [
"null",
"object"
],
"properties": {
"type": {
"type": [
"null",
"string"
],
"maxLength": 1024
}
}
}
}
},
"process": {
"description": "Process metadata about the monitored service.",
"type": [
Expand Down
31 changes: 19 additions & 12 deletions src/Elastic.Apm/Metrics/MetricsProvider/BreakdownMetricsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the LICENSE file in the project root for more information

using System.Collections.Generic;
using System.Linq;
using Elastic.Apm.Api;
using Elastic.Apm.Helpers;
using Elastic.Apm.Logging;
Expand All @@ -14,14 +15,15 @@ namespace Elastic.Apm.Metrics.MetricsProvider
internal class BreakdownMetricsProvider : IMetricsProvider
{
internal const string SpanSelfTime = "span.self_time";
internal const int MetricLimit = 1000;

private readonly List<MetricSet> _itemsToSend = new();
private readonly IApmLogger _logger;

/// <summary>
/// Indicates if the 10K limit log was already printed.
/// Indicates if the metric limit log was already printed.
/// </summary>
private bool loggedWarning = false;
private bool _loggedWarning;

private readonly object _lock = new();
private int _transactionCount;
Expand Down Expand Up @@ -62,16 +64,18 @@ public void CaptureTransaction(Transaction transaction)
Transaction = new TransactionInfo { Name = transaction.Name, Type = transaction.Type }
};

if (_itemsToSend.Count < 1000)
if (_itemsToSend.Count < MetricLimit)
_itemsToSend.Add(metricSet);
else
{
if (loggedWarning) continue;
if (_loggedWarning) continue;

_logger.Warning()
?.Log(
"The limit of 1000 metricsets has been reached, no new metricsets will be created.");
loggedWarning = true;
"The limit of {MetricLimit} metricsets has been reached, no new metricsets will be created until "
+ "the current set is sent to APM Server.",
MetricLimit);
_loggedWarning = true;
}
}

Expand All @@ -84,30 +88,33 @@ public void CaptureTransaction(Transaction transaction)
new("transaction.breakdown.count", _transactionCount),
}) { Transaction = new TransactionInfo { Name = transaction.Name, Type = transaction.Type } };

if (_itemsToSend.Count < 1000)
if (_itemsToSend.Count < MetricLimit)
_itemsToSend.Add(transactionMetric);
else
{
if (!loggedWarning)
if (!_loggedWarning)
{
_logger.Warning()
?.Log(
"The limit of 1000 metricsets has been reached, no new metricsets will be created until the current set is sent to APM Server.");
?.Log("The limit of {MetricLimit} metricsets has been reached, no new metricsets will be created until "
+ "the current set is sent to APM Server.",
MetricLimit);
_loggedWarning = true;
}
}
}
}

public IEnumerable<MetricSet> GetSamples()
{
var retVal = new List<MetricSet>(_itemsToSend.Count < 1000 ? _itemsToSend.Count : 1000);
List<MetricSet> retVal;

lock (_lock)
{
retVal = new List<MetricSet>(_itemsToSend.Count);
retVal.AddRange(_itemsToSend);
_itemsToSend.Clear();
_transactionCount = 0;
loggedWarning = false;
_loggedWarning = false;
}

return retVal;
Expand Down
1 change: 0 additions & 1 deletion src/Elastic.Apm/Model/DbSpanCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ internal void EndSpan(ISpan span, IDbCommand dbCommand, Outcome outcome, TimeSpa
}

capturedSpan.Outcome = outcome;
capturedSpan.End();
}

span.End();
Expand Down

0 comments on commit d499be8

Please sign in to comment.