Skip to content

Commit

Permalink
Use old registering api instead ConfigureBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Alex <sanya_nikiti@mail.ru>
  • Loading branch information
aunikitin committed Feb 4, 2023
1 parent ebb41ce commit ff8550b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ OpenTelemetry.Metrics.MeterProviderBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationMeterOptions> configureOptions) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string optionsName, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationMeterOptions> configureOptions) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ OpenTelemetry.Metrics.MeterProviderBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationMeterOptions> configureOptions) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, string optionsName, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationMeterOptions> configureOptions) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHttpClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Http.HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// limitations under the License.
// </copyright>

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.Http;
using OpenTelemetry.Internal;

Expand Down Expand Up @@ -43,39 +41,18 @@ public static MeterProviderBuilder AddHttpClientInstrumentation(
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddHttpClientInstrumentation(
this MeterProviderBuilder builder,
Action<HttpClientInstrumentationMeterOptions> configureOptions) =>
builder.AddHttpClientInstrumentation(optionsName: null, configureOptions);

/// <summary>
/// Enables HttpClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
/// <param name="optionsName"> Name which is used when retrieving options.</param>
/// <param name="configureOptions">Callback action for configuring <see cref="HttpClientInstrumentationMeterOptions"/>.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddHttpClientInstrumentation(
this MeterProviderBuilder builder,
string optionsName,
Action<HttpClientInstrumentationMeterOptions> configureOptions)
{
// TODO: Implement an IDeferredMeterProviderBuilder

Guard.ThrowIfNull(builder);

optionsName ??= Options.DefaultName;

if (configureOptions != null)
{
builder.ConfigureServices(services => services.Configure(optionsName, configureOptions));
}
var options = new HttpClientInstrumentationMeterOptions();
configureOptions?.Invoke(options);

builder.ConfigureBuilder((sp, builder) =>
{
var options = sp.GetRequiredService<IOptionsMonitor<HttpClientInstrumentationMeterOptions>>().Get(optionsName);
var instrumentation = new HttpClientMetrics(options);
builder.AddMeter(HttpClientMetrics.InstrumentationName);
builder.AddInstrumentation(() => instrumentation);
});
var instrumentation = new HttpClientMetrics(options);
builder.AddMeter(HttpClientMetrics.InstrumentationName);
builder.AddInstrumentation(() => instrumentation);

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@ public void AddHttpClientInstrumentationUsesOptionsApi(string name)
Assert.Equal(1, configurationDelegateInvocations);
}

[Fact]
public void MeterProvider_AddHttpClientInstrumentation_NamedOptions()
{
int defaultExporterOptionsConfigureOptionsInvocations = 0;
int namedExporterOptionsConfigureOptionsInvocations = 0;

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddHttpClientInstrumentation(configureOptions: _ => defaultExporterOptionsConfigureOptionsInvocations++)
.AddHttpClientInstrumentation(
"Instrumentation2",
configureOptions: _ => namedExporterOptionsConfigureOptionsInvocations++)
.Build();

Assert.Equal(1, defaultExporterOptionsConfigureOptionsInvocations);
Assert.Equal(1, namedExporterOptionsConfigureOptionsInvocations);
}

[Fact]
public void TraceProvider_AddHttpClientInstrumentation_NullBuilder()
{
Expand Down

0 comments on commit ff8550b

Please sign in to comment.