Skip to content

Commit

Permalink
Merge branch 'main' into utpilla/Fix-gRPC-Instrumentation-For-Sibling…
Browse files Browse the repository at this point in the history
…-Activity-UsingSameOperationName
  • Loading branch information
cijothomas authored May 3, 2021
2 parents 39f60a4 + 073ce6c commit 33fd687
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
abstract OpenTelemetry.Trace.TracerProviderBuilder.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
OpenTelemetry.Trace.TracerProviderBuilder.TracerProviderBuilder() -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
abstract OpenTelemetry.Trace.TracerProviderBuilder.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
OpenTelemetry.Trace.TracerProviderBuilder.TracerProviderBuilder() -> void
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ please check the latest changes

## Unreleased

* Adds `AddLegacySource()` to `TracerProviderBuilder`
([#2019](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2019))

## 1.1.0-beta2

Released 2021-Apr-23
Expand Down
11 changes: 11 additions & 0 deletions src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>
using System;
using System.Diagnostics;

namespace OpenTelemetry.Trace
{
Expand Down Expand Up @@ -45,5 +46,15 @@ public abstract TracerProviderBuilder AddInstrumentation<TInstrumentation>(
/// <param name="names">Activity source names.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public abstract TracerProviderBuilder AddSource(params string[] names);

/// <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 created without using the <see cref="System.Diagnostics.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>
public abstract TracerProviderBuilder AddLegacySource(string operationName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation(string instrume
OpenTelemetry.Trace.TracerProviderBuilderBase.Build() -> OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProviderBuilderBase.TracerProviderBuilderBase() -> void
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddSource(params string[] names) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetErrorStatusOnException(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, bool enabled = true) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
2 changes: 1 addition & 1 deletion src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation(string instrume
OpenTelemetry.Trace.TracerProviderBuilderBase.Build() -> OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProviderBuilderBase.TracerProviderBuilderBase() -> void
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddSource(params string[] names) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetErrorStatusOnException(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, bool enabled = true) -> 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
Expand Up @@ -17,8 +17,8 @@ OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation(string instrume
OpenTelemetry.Trace.TracerProviderBuilderBase.Build() -> OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProviderBuilderBase.TracerProviderBuilderBase() -> void
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddSource(params string[] names) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetErrorStatusOnException(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, bool enabled = true) -> 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
Expand Up @@ -17,8 +17,8 @@ OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation(string instrume
OpenTelemetry.Trace.TracerProviderBuilderBase.Build() -> OpenTelemetry.Trace.TracerProvider
OpenTelemetry.Trace.TracerProviderBuilderBase.TracerProviderBuilderBase() -> void
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Trace.TracerProviderBuilderBase.AddSource(params string[] names) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddLegacySource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.SetErrorStatusOnException(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, bool enabled = true) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderExtensions.ForceFlush(this OpenTelemetry.Trace.TracerProvider provider, int timeoutMilliseconds = -1) -> bool
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ please check the latest changes

## Unreleased

* `AddLegacySource()` moved out of `TracerProviderBuilderExtensions` and into
public API
([#2019](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2019))

## 1.1.0-beta2

Released 2021-Apr-23
Expand Down
33 changes: 13 additions & 20 deletions src/OpenTelemetry/Trace/TracerProviderBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public override TracerProviderBuilder AddSource(params string[] names)
return this;
}

/// <inheritdoc />
public override TracerProviderBuilder AddLegacySource(string operationName)
{
if (string.IsNullOrWhiteSpace(operationName))
{
throw new ArgumentException($"{nameof(operationName)} contains null or whitespace string.");
}

this.legacyActivityOperationNames[operationName] = true;

return this;
}

/// <summary>
/// Sets whether the status of <see cref="System.Diagnostics.Activity"/>
/// should be set to <c>Status.Error</c> when it ended abnormally due to an unhandled exception.
Expand Down Expand Up @@ -160,26 +173,6 @@ internal TracerProviderBuilder AddProcessor(BaseProcessor<Activity> processor)
return this;
}

/// <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 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 AddLegacySource(string operationName)
{
if (string.IsNullOrWhiteSpace(operationName))
{
throw new ArgumentException($"{nameof(operationName)} contains null or whitespace string.");
}

this.legacyActivityOperationNames[operationName] = true;

return this;
}

/// <summary>
/// Adds instrumentation to the provider.
/// </summary>
Expand Down
19 changes: 0 additions & 19 deletions src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,6 @@ public static TracerProviderBuilder AddProcessor(this TracerProviderBuilder trac
return tracerProviderBuilder;
}

/// <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 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 AddLegacySource(this TracerProviderBuilder tracerProviderBuilder, string operationName)
{
if (tracerProviderBuilder is TracerProviderBuilderBase tracerProviderBuilderBase)
{
tracerProviderBuilderBase.AddLegacySource(operationName);
}

return tracerProviderBuilder;
}

/// <summary>
/// Run the given actions to initialize the <see cref="TracerProvider"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,6 @@ public class TracerProviderBuilderExtensionsTest
{
private const string ActivitySourceName = "TracerProviderBuilderExtensionsTest";

[Fact]
public void AddLegacyOperationName_NullBuilder_Noop()
{
TracerProviderBuilder builder = null;

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

var emptyActivitySource = new ActivitySource(string.Empty);
Assert.False(emptyActivitySource.HasListeners()); // Check if AddLegacyOperationName was noop after TracerProviderBuilder.Build
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void AddLegacyOperationName_BadArgs(string operationName)
{
var builder = Sdk.CreateTracerProviderBuilder();
Assert.Throws<ArgumentException>(() => builder.AddLegacySource(operationName));
}

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

Assert.False(emptyActivitySource.HasListeners());
using var provider = builder.Build();
Assert.True(emptyActivitySource.HasListeners());
}

[Fact]
public void SetErrorStatusOnExceptionEnabled()
{
Expand Down
22 changes: 22 additions & 0 deletions test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,28 @@ public void TracerProviderSdkBuildsWithDefaultResource()
Assert.Contains("unknown_service", (string)resource.Attributes.FirstOrDefault().Value);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void AddLegacyOperationName_BadArgs(string operationName)
{
var builder = Sdk.CreateTracerProviderBuilder();
Assert.Throws<ArgumentException>(() => builder.AddLegacySource(operationName));
}

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

Assert.False(emptyActivitySource.HasListeners());
using var provider = builder.Build();
Assert.True(emptyActivitySource.HasListeners());
}

[Fact]
public void TracerProviderSdkBuildsWithSDKResource()
{
Expand Down

0 comments on commit 33fd687

Please sign in to comment.