-
Notifications
You must be signed in to change notification settings - Fork 784
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
Allow to filter requests when collecting ASP.NET Core metrics. #3323
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using OpenTelemetry.Instrumentation.AspNetCore; | ||
using OpenTelemetry.Internal; | ||
|
||
|
@@ -28,23 +29,47 @@ public static class MeterProviderBuilderExtensions | |
/// Enables the incoming requests automatic data collection for ASP.NET Core. | ||
/// </summary> | ||
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param> | ||
/// <param name="configureAspNetCoreInstrumentationOptions">ASP.NET Core Request configuration options.</param> | ||
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns> | ||
public static MeterProviderBuilder AddAspNetCoreInstrumentation( | ||
this MeterProviderBuilder builder) | ||
this MeterProviderBuilder builder, | ||
Action<AspNetCoreInstrumentationOptions> configureAspNetCoreInstrumentationOptions = null) | ||
{ | ||
Guard.ThrowIfNull(builder); | ||
|
||
// TODO: Implement an IDeferredMeterProviderBuilder | ||
|
||
// TODO: Handle AspNetCoreInstrumentationOptions | ||
// Filter - makes sense for metric instrumentation | ||
// Enrich - do we want a similar kind of functionality for metrics? | ||
// RecordException - probably doesn't make sense for metric instrumentation | ||
// EnableGrpcAspNetCoreSupport - this instrumentation will also need to also handle gRPC requests | ||
// EnableGrpcAspNetCoreSupport - this instrumentation will also need to handle gRPC requests | ||
|
||
if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) | ||
{ | ||
return deferredMeterProviderBuilder.Configure((sp, builder) => | ||
{ | ||
AddAspNetCoreInstrumentation(builder, sp.GetOptions<AspNetCoreInstrumentationOptions>(), configureAspNetCoreInstrumentationOptions); | ||
}); | ||
} | ||
|
||
return AddAspNetCoreInstrumentation(builder, new AspNetCoreInstrumentationOptions(), configureAspNetCoreInstrumentationOptions); | ||
} | ||
|
||
var instrumentation = new AspNetCoreMetrics(); | ||
internal static MeterProviderBuilder AddAspNetCoreInstrumentation( | ||
this MeterProviderBuilder builder, | ||
AspNetCoreMetrics instrumentation) | ||
{ | ||
builder.AddMeter(AspNetCoreMetrics.InstrumentationName); | ||
return builder.AddInstrumentation(() => instrumentation); | ||
} | ||
|
||
private static MeterProviderBuilder AddAspNetCoreInstrumentation( | ||
MeterProviderBuilder builder, | ||
AspNetCoreInstrumentationOptions options, | ||
Action<AspNetCoreInstrumentationOptions> configure = null) | ||
{ | ||
configure?.Invoke(options); | ||
return AddAspNetCoreInstrumentation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the discrepancy is between traces and metrics - in traces we will new-up |
||
builder, | ||
new AspNetCoreMetrics(options)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't bump the event versions. It doesn't seem like we care about ETW consumers that cache manifests.