Skip to content
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

[Azure Monitor Exporter] Change foreach loop to use ref readonly for tag/event/link enumeration #36544

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void OnEnd(Activity activity)
private void ReportRequestDurationMetric(Activity activity, string statusCodeAttribute)
{
string? statusCodeAttributeValue = null;
foreach (var tag in activity.EnumerateTagObjects())
foreach (ref readonly var tag in activity.EnumerateTagObjects())
{
if (tag.Key == statusCodeAttribute)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal static void AddActivityLinksToProperties(Activity activity, ref AzMonLi
{
var linksJson = new StringBuilder();
linksJson.Append('[');
foreach (var link in activity.EnumerateLinks())
foreach (ref readonly var link in activity.EnumerateLinks())
{
linksJson
.Append('{')
Expand Down Expand Up @@ -186,7 +186,7 @@ internal static string GetOperationName(Activity activity, ref AzMonList MappedT

private static void AddTelemetryFromActivityEvents(Activity activity, TelemetryItem telemetryItem, List<TelemetryItem> telemetryItems)
{
foreach (var evnt in activity.EnumerateEvents())
foreach (ref readonly var evnt in activity.EnumerateEvents())
{
try
{
Expand Down Expand Up @@ -227,7 +227,7 @@ private static void AddTelemetryFromActivityEvents(Activity activity, TelemetryI

var messageData = new MessageData(Version, activityEvent.Name);

foreach (var tag in activityEvent.EnumerateTagObjects())
foreach (ref readonly var tag in activityEvent.EnumerateTagObjects())
{
if (tag.Value is Array arrayValue)
{
Expand All @@ -252,7 +252,7 @@ private static void AddTelemetryFromActivityEvents(Activity activity, TelemetryI
string? exceptionStackTrace = null;
string? exceptionMessage = null;

foreach (var tag in activityEvent.EnumerateTagObjects())
foreach (ref readonly var tag in activityEvent.EnumerateTagObjects())
{
// TODO: see if these can be cached
if (tag.Key == SemanticConventions.AttributeExceptionType)
Expand Down