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

Add support for some AspNetCoreMetricsInstrumentationOptions #3948

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename function name to Enrich and fixed typo in comment
Temppus committed Nov 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit be5e04370e6667c3d36181ce82a62bba4550c705
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ public class AspNetCoreMetricsInstrumentationOptions
public Func<HttpContext, bool> Filter { get; set; }

/// <summary>
/// Gets or sets an function to enrich an recorded metric with additional custom tags.
/// Gets or sets an function to enrich a recorded metric with additional custom tags.
/// </summary>
public AspNetCoreMetricEnrichmentFunc EnrichWithCustomTags { get; set; }
public AspNetCoreMetricEnrichmentFunc Enrich { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -99,11 +99,11 @@ public override void OnEventWritten(string name, object payload)
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRoute, route));
}
#endif
if (this.options.EnrichWithCustomTags != null)
if (this.options.Enrich != null)
{
try
{
this.options.EnrichWithCustomTags(context, out var enrichedTags);
this.options.Enrich(context, out var enrichedTags);

foreach (var keyValuePair in enrichedTags)
{
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ public async Task MetricEnrichedWithCustomTags()
void ConfigureTestServices(IServiceCollection services)
{
this.meterProvider = Sdk.CreateMeterProviderBuilder()
.AddAspNetCoreInstrumentation(opt => opt.EnrichWithCustomTags = (HttpContext _, out TagList tags) =>
.AddAspNetCoreInstrumentation(opt => opt.Enrich = (HttpContext _, out TagList tags) =>
{
tags = new TagList(new Span<KeyValuePair<string, object>>(tagsToAdd));
})