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

Updated AddLegacyActivity method name to AddLegacySource #1860

Merged
Show file tree
Hide file tree
Changes from 4 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static TracerProviderBuilder AddAspNetInstrumentation(

builder.AddInstrumentation(() => new AspNetInstrumentation(aspnetOptions));
builder.AddSource(HttpInListener.ActivitySourceName);
builder.AddLegacyActivity("Microsoft.AspNet.HttpReqIn"); // for the activities created by AspNetCore
builder.AddLegacyActivity("ActivityCreatedByHttpInListener"); // for the sibling activities created by the instrumentation library
builder.AddLegacySource("Microsoft.AspNet.HttpReqIn"); // for the activities created by AspNetCore
builder.AddLegacySource("ActivityCreatedByHttpInListener"); // for the sibling activities created by the instrumentation library

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static TracerProviderBuilder AddAspNetCoreInstrumentation(
configureAspNetCoreInstrumentationOptions?.Invoke(aspnetCoreOptions);
builder.AddInstrumentation(() => new AspNetCoreInstrumentation(aspnetCoreOptions));
builder.AddSource(HttpInListener.ActivitySourceName);
builder.AddLegacyActivity(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
builder.AddLegacyActivity(HttpInListener.ActivityNameByHttpInListener); // for the sibling activities created by the instrumentation library
builder.AddLegacySource(HttpInListener.ActivityOperationName); // for the activities created by AspNetCore
builder.AddLegacySource(HttpInListener.ActivityNameByHttpInListener); // for the sibling activities created by the instrumentation library

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static TracerProviderBuilder AddGrpcClientInstrumentation(

builder.AddInstrumentation(() => new GrpcClientInstrumentation(grpcOptions));
builder.AddSource(GrpcClientDiagnosticListener.ActivitySourceName);
builder.AddLegacyActivity("Grpc.Net.Client.GrpcOut");
builder.AddLegacySource("Grpc.Net.Client.GrpcOut");

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static TracerProviderBuilder AddHttpClientInstrumentation(

builder.AddInstrumentation(() => new HttpClientInstrumentation(httpClientOptions));
builder.AddSource(HttpHandlerDiagnosticListener.ActivitySourceName);
builder.AddLegacyActivity("System.Net.Http.HttpRequestOut");
builder.AddLegacySource("System.Net.Http.HttpRequestOut");

#if NETFRAMEWORK
builder.AddHttpWebRequestInstrumentation(configureHttpWebRequestInstrumentationOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OpenTelemetry.Trace.ParentBasedSampler.ParentBasedSampler(OpenTelemetry.Trace.Sampler rootSampler, OpenTelemetry.Trace.Sampler remoteParentSampled = null, OpenTelemetry.Trace.Sampler remoteParentNotSampled = null, OpenTelemetry.Trace.Sampler localParentSampled = null, OpenTelemetry.Trace.Sampler localParentNotSampled = null) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacyActivity(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OpenTelemetry.Trace.ParentBasedSampler.ParentBasedSampler(OpenTelemetry.Trace.Sampler rootSampler, OpenTelemetry.Trace.Sampler remoteParentSampled = null, OpenTelemetry.Trace.Sampler remoteParentNotSampled = null, OpenTelemetry.Trace.Sampler localParentSampled = null, OpenTelemetry.Trace.Sampler localParentNotSampled = null) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacyActivity(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OpenTelemetry.Trace.ParentBasedSampler.ParentBasedSampler(OpenTelemetry.Trace.Sampler rootSampler, OpenTelemetry.Trace.Sampler remoteParentSampled = null, OpenTelemetry.Trace.Sampler remoteParentNotSampled = null, OpenTelemetry.Trace.Sampler localParentSampled = null, OpenTelemetry.Trace.Sampler localParentNotSampled = null) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacyActivity(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OpenTelemetry.Trace.ParentBasedSampler.ParentBasedSampler(OpenTelemetry.Trace.Sampler rootSampler, OpenTelemetry.Trace.Sampler remoteParentSampled = null, OpenTelemetry.Trace.Sampler remoteParentNotSampled = null, OpenTelemetry.Trace.Sampler localParentSampled = null, OpenTelemetry.Trace.Sampler localParentNotSampled = null) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacyActivity(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
16 changes: 10 additions & 6 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ please check the latest changes

## Unreleased

* Added `ForceFlush` to `TracerProvider`. ([#1837](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1837))
* Updated the method name of `AddLegacyActivity` to `AddLegacySource`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need of this. as this was never released.

[#1860](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1860)

* Added a TracerProvierBuilder extension method called
`AddLegacyActivityOperationName` which is used by instrumentation libraries
that use DiagnosticSource to get activities processed without
ActivitySourceAdapter.
* Added `ForceFlush` to `TracerProvider`.
([#1837](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1837))

* Added a TracerProviderBuilder extension method called `AddLegacyActivity`
utpilla marked this conversation as resolved.
Show resolved Hide resolved
which is used by instrumentation libraries that use DiagnosticSource to get
activities processed without ActivitySourceAdapter.
[#1836](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1836)

* Added new constructor with optional parameters to allow customization of
`ParentBasedSampler` behavior. ([#1727](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1727))
`ParentBasedSampler` behavior.
([#1727](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1727))

* The application base directory is now tested after the current directory when
searching for the
Expand Down
13 changes: 8 additions & 5 deletions src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ public static TracerProviderBuilder AddProcessor(this TracerProviderBuilder trac
}

/// <summary>
/// Adds activity with a given operation name to the list of subscribed activities. This is only for legacy activities (i.e. activities created without using ActivitySource API).
/// Adds a listener for <see cref="Activity"/> objects created with the given operation name to the <see cref="TracerProviderBuilder"/>.
/// </summary>
/// <param name="tracerProviderBuilder">TracerProviderBuilder instance.</param>
/// <param name="operationName">OperationName to add.</param>
/// <remarks>
/// This is provided to capture legacy <see cref="Activity"/> objects created without using the <see cref="ActivitySource"/> API.
/// </remarks>
/// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/> instance.</param>
/// <param name="operationName">Operation name of the <see cref="Activity"/> objects to capture.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddLegacyActivity(this TracerProviderBuilder tracerProviderBuilder, string operationName)
public static TracerProviderBuilder AddLegacySource(this TracerProviderBuilder tracerProviderBuilder, string operationName)
{
if (tracerProviderBuilder is TracerProviderBuilderSdk tracerProviderBuilderSdk)
{
tracerProviderBuilderSdk.AddLegacyActivity(operationName);
tracerProviderBuilderSdk.AddLegacySource(operationName);
}

return tracerProviderBuilder;
Expand Down
9 changes: 6 additions & 3 deletions src/OpenTelemetry/Trace/TracerProviderBuilderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ internal TracerProviderBuilder AddProcessor(BaseProcessor<Activity> processor)
}

/// <summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code comments should use a plural tense. Here's an alternative:

        /// <summary>
        /// Adds a listener for <see cref="Activity"/> objects created with the given operation name to the <see cref="TracerProviderBuilder"/>.
        /// </summary>
        /// <remarks>
        /// This is provided to capture legacy <see cref="Activity"/> objects creared without using the <see cref="ActivitySource"/> API.
        /// </remarks>
        /// <param name="tracerProviderBuilder"><see cref="TracerProviderBuilder"/> instance.</param>
        /// <param name="operationName">Operation name of the <see cref="Activity"/> objects to capture.</param>
        /// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
        public static TracerProviderBuilder AddLegacyActivity(this TracerProviderBuilder tracerProviderBuilder, string operationName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code comments.

/// Adds activity with a given operation name to the list of subscribed activities. This is only for legacy activities (i.e. activities created without using ActivitySource API).
/// Adds a listener for <see cref="Activity"/> objects created with the given operation name to the <see cref="TracerProviderBuilder"/>.
/// </summary>
/// <param name="operationName">OperationName to add.</param>
/// <remarks>
/// This is provided to capture legacy <see cref="Activity"/> objects created without using the <see cref="ActivitySource"/> API.
/// </remarks>
/// <param name="operationName">Operation name of the <see cref="Activity"/> objects to capture.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
internal TracerProviderBuilder AddLegacyActivity(string operationName)
internal TracerProviderBuilder AddLegacySource(string operationName)
{
if (string.IsNullOrWhiteSpace(operationName))
{
Expand Down
6 changes: 3 additions & 3 deletions test/Benchmarks/Trace/TraceBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public TraceBenchmarks()
Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddSource(this.sourceWithOneLegacyActivityOperationNameSubscription.Name)
.AddLegacyActivity("TestOperationName")
.AddLegacySource("TestOperationName")
.AddProcessor(new DummyActivityProcessor())
.Build();

Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddSource(this.sourceWithTwoLegacyActivityOperationNameSubscriptions.Name)
.AddLegacyActivity("TestOperationName1")
.AddLegacyActivity("TestOperationName2")
.AddLegacySource("TestOperationName1")
.AddLegacySource("TestOperationName2")
.AddProcessor(new DummyActivityProcessor())
.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void AddLegacyOperationName_NullBuilder_Noop()
TracerProviderBuilder builder = null;

// No exception is thrown on executing this line
builder.AddLegacyActivity("TestOperationName");
builder.AddLegacySource("TestOperationName");
using var provider = builder.Build();

var emptyActivitySource = new ActivitySource(string.Empty);
Expand All @@ -43,15 +43,15 @@ public void AddLegacyOperationName_NullBuilder_Noop()
public void AddLegacyOperationName_BadArgs(string operationName)
{
var builder = Sdk.CreateTracerProviderBuilder();
Assert.Throws<ArgumentException>(() => builder.AddLegacyActivity(operationName));
Assert.Throws<ArgumentException>(() => builder.AddLegacySource(operationName));
}

[Fact]
public void AddLegacyOperationNameAddsActivityListenerForEmptyActivitySource()
{
var emptyActivitySource = new ActivitySource(string.Empty);
var builder = Sdk.CreateTracerProviderBuilder();
builder.AddLegacyActivity("TestOperationName");
builder.AddLegacySource("TestOperationName");

Assert.False(emptyActivitySource.HasListeners());
using var provider = builder.Build();
Expand Down
22 changes: 11 additions & 11 deletions test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void SdkSamplesAndProcessesLegacyActivityWithRightConfig()
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddProcessor(testActivityProcessor)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Assert.True(emptyActivitySource.HasListeners()); // Listener for empty ActivitySource added after TracerProvider build
Expand Down Expand Up @@ -412,7 +412,7 @@ public void SdkSamplesAndProcessesLegacyActivityWithRightConfigOnWildCardMode()
.SetSampler(sampler)
.AddSource("ABCCompany.XYZProduct.*") // Adding a wild card source
.AddProcessor(testActivityProcessor)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Assert.True(emptyActivitySource.HasListeners()); // Listener for empty ActivitySource added after TracerProvider build
Expand Down Expand Up @@ -459,7 +459,7 @@ public void SdkCallsOnlyProcessorOnStartForLegacyActivityWhenActivitySourceIsUpd

// AddLegacyOperationName chained to TracerProviderBuilder
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.AddProcessor(testActivityProcessor)
.Build();

Expand Down Expand Up @@ -509,7 +509,7 @@ public void SdkProcessesLegacyActivityWhenActivitySourceIsUpdatedWithAddSource()
// AddLegacyOperationName chained to TracerProviderBuilder
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(activitySourceForLegacyActvity.Name) // Add the updated ActivitySource as a Source
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.AddProcessor(testActivityProcessor)
.Build();

Expand Down Expand Up @@ -554,7 +554,7 @@ public void SdkProcessesLegacyActivityEvenAfterAddingNewProcessor()
// AddLegacyOperationName chained to TracerProviderBuilder
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddProcessor(testActivityProcessor)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Activity activity = new Activity(operationNameForLegacyActivity);
Expand Down Expand Up @@ -603,7 +603,7 @@ public void SdkSamplesLegacyActivityWithAlwaysOnSampler()
var operationNameForLegacyActivity = "TestOperationName";
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOnSampler())
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Activity activity = new Activity(operationNameForLegacyActivity);
Expand All @@ -621,7 +621,7 @@ public void SdkSamplesLegacyActivityWithAlwaysOffSampler()
var operationNameForLegacyActivity = "TestOperationName";
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(new AlwaysOffSampler())
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Activity activity = new Activity(operationNameForLegacyActivity);
Expand All @@ -644,7 +644,7 @@ public void SdkSamplesLegacyActivityWithCustomSampler(SamplingDecision samplingD

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

Activity activity = new Activity(operationNameForLegacyActivity);
Expand All @@ -671,7 +671,7 @@ public void SdkPopulatesSamplingParamsCorrectlyForRootLegacyActivity()

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

// Start activity without setting parent. i.e it'll have null parent
Expand Down Expand Up @@ -707,7 +707,7 @@ public void SdkPopulatesSamplingParamsCorrectlyForLegacyActivityWithRemoteParent

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

// Create an activity with remote parent id.
Expand Down Expand Up @@ -746,7 +746,7 @@ public void SdkPopulatesSamplingParamsCorrectlyForLegacyActivityWithInProcParent

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddLegacyActivity(operationNameForLegacyActivity)
.AddLegacySource(operationNameForLegacyActivity)
.Build();

// This activity will have a inproc parent.
Expand Down