Skip to content

Commit

Permalink
Rollback options renaming
Browse files Browse the repository at this point in the history
Signed-off-by: aunikitin <sanya_nikiti@mail.ru>
  • Loading branch information
aunikitin committed Jan 15, 2023
1 parent 6a04512 commit dcb5abf
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddHttpClientInstrum
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.HttpClientInstrumentationSamplingOptions> configureHttpClientInstrumentationOptions) -> 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 @@ -31,7 +31,7 @@ internal sealed class HttpClientInstrumentation : IDisposable
/// Initializes a new instance of the <see cref="HttpClientInstrumentation"/> class.
/// </summary>
/// <param name="options">Configuration options for HTTP client instrumentation.</param>
public HttpClientInstrumentation(HttpClientInstrumentationSamplingOptions options)
public HttpClientInstrumentation(HttpClientInstrumentationOptions options)
{
// For .NET7.0 activity will be created using activitySource.
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="HttpClientInstrumentationSamplingOptions.cs" company="OpenTelemetry Authors">
// <copyright file="HttpClientInstrumentationOptions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,7 +27,7 @@ namespace OpenTelemetry.Instrumentation.Http
/// <summary>
/// Options for HttpClient instrumentation.
/// </summary>
public class HttpClientInstrumentationSamplingOptions
public class HttpClientInstrumentationOptions
{
/// <summary>
/// Gets or sets a filter function that determines whether or not to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal sealed class HttpHandlerDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<HttpResponseMessage> stopResponseFetcher = new("Response");
private readonly PropertyFetcher<Exception> stopExceptionFetcher = new("Exception");
private readonly PropertyFetcher<TaskStatus> stopRequestStatusFetcher = new("RequestTaskStatus");
private readonly HttpClientInstrumentationSamplingOptions options;
private readonly HttpClientInstrumentationOptions options;

static HttpHandlerDiagnosticListener()
{
Expand All @@ -57,7 +57,7 @@ static HttpHandlerDiagnosticListener()
}
}

public HttpHandlerDiagnosticListener(HttpClientInstrumentationSamplingOptions options)
public HttpHandlerDiagnosticListener(HttpClientInstrumentationOptions options)
: base("HttpHandlerDiagnosticListener")
{
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ private void OnStopActivity(Activity activity, object payload)
}

var request = response.RequestMessage;
if (!this.TryFilterHttpRequestMessage(activity.OperationName, request))
{
return;
}

var tags = new List<KeyValuePair<string, object>>
{
new(SemanticConventions.AttributeHttpMethod, HttpTagHelper.GetNameForHttpMethod(request.Method)),
Expand All @@ -74,11 +79,6 @@ private void OnStopActivity(Activity activity, object payload)
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerPort, request.RequestUri.Port));
}

if (!this.TryFilterHttpRequestMessage(activity.OperationName, request))
{
return;
}

this.EnrichWithHttpRequestMessage(tags, request);

this.httpClientDuration.Record(activity.Duration.TotalMilliseconds, tags.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
[EventSource(Name = "OpenTelemetry-Instrumentation-Http")]
internal sealed class HttpInstrumentationEventSource : EventSource
{
public static readonly HttpInstrumentationEventSource Log = new();
public static HttpInstrumentationEventSource Log = new();

[NonEvent]
public void FailedProcessResult(Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static class HttpWebRequestActivitySource
internal static readonly Func<HttpWebRequest, string, IEnumerable<string>> HttpWebRequestHeaderValuesGetter = (request, name) => request.Headers.GetValues(name);
internal static readonly Action<HttpWebRequest, string, string> HttpWebRequestHeaderValuesSetter = (request, name, value) => request.Headers.Add(name, value);

internal static HttpClientInstrumentationSamplingOptions Options = new HttpClientInstrumentationSamplingOptions();
internal static HttpClientInstrumentationOptions Options = new HttpClientInstrumentationOptions();

private static readonly Version Version = AssemblyName.Version;
private static readonly ActivitySource WebRequestActivitySource = new ActivitySource(ActivitySourceName, Version.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(this TracerProv
/// Enables HttpClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureHttpClientInstrumentationOptions">Callback action for configuring <see cref="HttpClientInstrumentationSamplingOptions"/>.</param>
/// <param name="configureHttpClientInstrumentationOptions">Callback action for configuring <see cref="HttpClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddHttpClientInstrumentation(
this TracerProviderBuilder builder,
Action<HttpClientInstrumentationSamplingOptions> configureHttpClientInstrumentationOptions)
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions)
=> AddHttpClientInstrumentation(builder, name: null, configureHttpClientInstrumentationOptions);

/// <summary>
/// Enables HttpClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configureHttpClientInstrumentationOptions">Callback action for configuring <see cref="HttpClientInstrumentationSamplingOptions"/>.</param>
/// <param name="configureHttpClientInstrumentationOptions">Callback action for configuring <see cref="HttpClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddHttpClientInstrumentation(
this TracerProviderBuilder builder,
string name,
Action<HttpClientInstrumentationSamplingOptions> configureHttpClientInstrumentationOptions)
Action<HttpClientInstrumentationOptions> configureHttpClientInstrumentationOptions)
{
Guard.ThrowIfNull(builder);

Expand All @@ -69,7 +69,7 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(

return builder.ConfigureBuilder((sp, builder) =>
{
var options = sp.GetRequiredService<IOptionsMonitor<HttpClientInstrumentationSamplingOptions>>().Get(name);
var options = sp.GetRequiredService<IOptionsMonitor<HttpClientInstrumentationOptions>>().Get(name);

#if NETFRAMEWORK
HttpWebRequestActivitySource.Options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task MeterProvider_EnrichMetricWithTags_When_EnrichDelegateIsSet(bo
{
// given
var metrics = new List<Metric>();
const string enrichedTagKey = nameof(HttpClientInstrumentationSamplingOptions.EnrichWithHttpRequestMessage);
const string enrichedTagKey = nameof(HttpClientInstrumentationMeterOptions.EnrichWithHttpRequestMessage);
const string enrichedTagValue = "yes";
var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddHttpClientInstrumentation(o =>
Expand Down
10 changes: 4 additions & 6 deletions test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
// limitations under the License.
// </copyright>

using System.ComponentModel;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Text.Json;
using Moq;
using OpenTelemetry.Instrumentation.Http.Tests.Extensions;
using OpenTelemetry.Metrics;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
Expand Down Expand Up @@ -247,13 +245,13 @@ public async Task DebugIndividualTestAsync()
}

[Fact]
public async Task TraceProvider_CheckEnrichmentWhenSampling()
public async Task CheckEnrichmentWhenSampling()
{
await CheckSamplingEnrichment(new AlwaysOffSampler(), false, this.url).ConfigureAwait(false);
await CheckSamplingEnrichment(new AlwaysOnSampler(), true, this.url).ConfigureAwait(false);
await CheckEnrichment(new AlwaysOffSampler(), false, this.url).ConfigureAwait(false);
await CheckEnrichment(new AlwaysOnSampler(), true, this.url).ConfigureAwait(false);
}

private static async Task CheckSamplingEnrichment(Sampler sampler, bool enrichExpected, string url)
private static async Task CheckEnrichment(Sampler sampler, bool enrichExpected, string url)
{
bool enrichWithHttpWebRequestCalled = false;
bool enrichWithHttpWebResponseCalled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class HttpWebRequestActivitySourceTests : IDisposable

static HttpWebRequestActivitySourceTests()
{
HttpClientInstrumentationSamplingOptions options = new()
HttpClientInstrumentationOptions options = new()
{
EnrichWithHttpWebRequest = (activity, httpWebRequest) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public void TraceProvider_AddHttpClientInstrumentation_NamedOptions()
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<HttpClientInstrumentationSamplingOptions>(_ =>
services.Configure<HttpClientInstrumentationOptions>(_ =>
defaultExporterOptionsConfigureOptionsInvocations++);

services.Configure<HttpClientInstrumentationSamplingOptions>(
services.Configure<HttpClientInstrumentationOptions>(
"Instrumentation2",
_ => namedExporterOptionsConfigureOptionsInvocations++);
})
Expand All @@ -63,12 +63,12 @@ public void AddHttpClientInstrumentationUsesOptionsApi(string name)
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<HttpClientInstrumentationSamplingOptions>(name, _ => configurationDelegateInvocations++);
services.Configure<HttpClientInstrumentationOptions>(name, _ => configurationDelegateInvocations++);
})
.AddProcessor(activityProcessor.Object)
.AddHttpClientInstrumentation(
name,
options => Assert.IsType<HttpClientInstrumentationSamplingOptions>(options))
options => Assert.IsType<HttpClientInstrumentationOptions>(options))
.Build();

Assert.Equal(1, configurationDelegateInvocations);
Expand Down

0 comments on commit dcb5abf

Please sign in to comment.