@@ -35,22 +35,45 @@ public static class TracerProviderBuilderExtensions
3535 /// Enables the incoming requests automatic data collection for ASP.NET Core.
3636 /// </summary>
3737 /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
38- /// <param name="configureAspNetCoreInstrumentationOptions">ASP.NET Core Request configuration options.</param>
38+ /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
39+ public static TracerProviderBuilder AddAspNetCoreInstrumentation ( this TracerProviderBuilder builder )
40+ => AddAspNetCoreInstrumentation ( builder , name : null , configureAspNetCoreInstrumentationOptions : null ) ;
41+
42+ /// <summary>
43+ /// Enables the incoming requests automatic data collection for ASP.NET Core.
44+ /// </summary>
45+ /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
46+ /// <param name="configureAspNetCoreInstrumentationOptions">Callback action for configuring <see cref="AspNetCoreInstrumentationOptions"/>.</param>
3947 /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
4048 public static TracerProviderBuilder AddAspNetCoreInstrumentation (
4149 this TracerProviderBuilder builder ,
42- Action < AspNetCoreInstrumentationOptions > configureAspNetCoreInstrumentationOptions = null )
50+ Action < AspNetCoreInstrumentationOptions > configureAspNetCoreInstrumentationOptions )
51+ => AddAspNetCoreInstrumentation ( builder , name : null , configureAspNetCoreInstrumentationOptions ) ;
52+
53+ /// <summary>
54+ /// Enables the incoming requests automatic data collection for ASP.NET Core.
55+ /// </summary>
56+ /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
57+ /// <param name="name">Name which is used when retrieving options.</param>
58+ /// <param name="configureAspNetCoreInstrumentationOptions">Callback action for configuring <see cref="AspNetCoreInstrumentationOptions"/>.</param>
59+ /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
60+ public static TracerProviderBuilder AddAspNetCoreInstrumentation (
61+ this TracerProviderBuilder builder ,
62+ string name ,
63+ Action < AspNetCoreInstrumentationOptions > configureAspNetCoreInstrumentationOptions )
4364 {
4465 Guard . ThrowIfNull ( builder ) ;
4566
67+ name ??= Options . DefaultName ;
68+
4669 if ( configureAspNetCoreInstrumentationOptions != null )
4770 {
48- builder . ConfigureServices ( services => services . Configure ( configureAspNetCoreInstrumentationOptions ) ) ;
71+ builder . ConfigureServices ( services => services . Configure ( name , configureAspNetCoreInstrumentationOptions ) ) ;
4972 }
5073
5174 return builder . ConfigureBuilder ( ( sp , builder ) =>
5275 {
53- var options = sp . GetRequiredService < IOptions < AspNetCoreInstrumentationOptions > > ( ) . Value ;
76+ var options = sp . GetRequiredService < IOptionsMonitor < AspNetCoreInstrumentationOptions > > ( ) . Get ( name ) ;
5477
5578 AddAspNetCoreInstrumentation ( builder , new AspNetCoreInstrumentation ( new HttpInListener ( options ) ) , sp ) ;
5679 } ) ;
0 commit comments