Skip to content

Commit

Permalink
Change AspNetCoreMetricEnrichmentFunc signature to ref instead of out
Browse files Browse the repository at this point in the history
  • Loading branch information
Temppus committed Dec 1, 2022
1 parent 1cc9003 commit d6b0126
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class AspNetCoreMetricsInstrumentationOptions
/// Delegate for enrichment of recorded metric with additional tags.
/// </summary>
/// <param name="context"><see cref="HttpContext"/>: the HttpContext object. Both Request and Response are available.</param>
/// <param name="tags"><see cref="TagList"/>: List of tags to add. </param>
public delegate void AspNetCoreMetricEnrichmentFunc(HttpContext context, out TagList tags);
/// <param name="tags"><see cref="TagList"/>: List of current tags. You can add additional tags to this list. </param>
public delegate void AspNetCoreMetricEnrichmentFunc(HttpContext context, ref TagList tags);

/// <summary>
/// Gets or sets a Filter function that determines whether or not to collect telemetry about requests on a per request basis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ public override void OnEventWritten(string name, object payload)
{
try
{
this.options.Enrich(context, out var enrichedTags);

foreach (var keyValuePair in enrichedTags)
{
tags.Add(keyValuePair);
}
this.options.Enrich(context, ref tags);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ public async Task MetricEnrichedWithCustomTags()
void ConfigureTestServices(IServiceCollection services)
{
this.meterProvider = Sdk.CreateMeterProviderBuilder()
.AddAspNetCoreInstrumentation(opt => opt.Enrich = (HttpContext _, out TagList tags) =>
.AddAspNetCoreInstrumentation(opt => opt.Enrich = (HttpContext _, ref TagList tags) =>
{
tags = new TagList(new Span<KeyValuePair<string, object>>(tagsToAdd));
foreach (var keyValuePair in tagsToAdd)
{
tags.Add(keyValuePair);
}
})
.AddInMemoryExporter(metricItems)
.Build();
Expand Down

0 comments on commit d6b0126

Please sign in to comment.