in src/Amazon.CloudWatch.EMF/Sink/AgentSink.cs [44:81]
public void Accept(MetricsContext metricsContext)
{
if (!string.IsNullOrEmpty(_logGroupName))
{
metricsContext.PutMetadata("LogGroupName", _logGroupName);
}
if (!string.IsNullOrEmpty(_logStreamName))
{
metricsContext.PutMetadata("LogStreamName", _logStreamName);
}
try
{
foreach (var data in metricsContext.Serialize())
{
_logger.LogDebug("Enqueuing data.");
try
{
if (!_queue.TryAdd(data))
{
_logger.LogWarning("Failed to enqueue metrics because the queue was full.");
}
}
catch (InvalidOperationException e)
{
_logger.LogError("Attempted to publish data after the sink has been shutdown. {}", e);
}
_logger.LogDebug("Data queued successfully.");
}
}
catch (Exception e)
{
_logger.LogError("Failed to serialize the metrics with the exception: {}", e);
}
}