Skip to content

Commit

Permalink
rename AddActivitySource to AddSource, use params (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
reyang authored Aug 11, 2020
1 parent 8af9b32 commit ce0bf3f
Show file tree
Hide file tree
Showing 31 changed files with 102 additions and 111 deletions.
2 changes: 1 addition & 1 deletion docs/trace/building-your-own-exporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Program
public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
.AddSource("MyCompany.MyProduct.MyLibrary")
.AddMyExporter()
.Build();

Expand Down
2 changes: 1 addition & 1 deletion docs/trace/building-your-own-processor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Program
public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
.AddSource("MyCompany.MyProduct.MyLibrary")
.AddProcessor(new MyActivityProcessor("A"))
.AddProcessor(new MyActivityProcessor("B"))
.Build();
Expand Down
2 changes: 1 addition & 1 deletion docs/trace/building-your-own-sampler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Program
public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
.AddSource("MyCompany.MyProduct.MyLibrary")
.SetSampler(new MySampler())
.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())))
.Build();
Expand Down
2 changes: 1 addition & 1 deletion docs/trace/getting-started/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Program
public static void Main()
{
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
.AddSource("MyCompany.MyProduct.MyLibrary")
.AddProcessor(new SimpleActivityProcessor(new ConsoleExporter(new ConsoleExporterOptions())))
.Build();

Expand Down
3 changes: 2 additions & 1 deletion examples/Console/TestConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ internal static object Run(ConsoleOptions options)
{
// Enable TracerProvider for the source "MyCompany.MyProduct.MyWebServer"
// and use a custom MyProcessor, along with Console exporter.
using var tracerProvider = Sdk.CreateTracerProviderBuilder().AddActivitySource("MyCompany.MyProduct.MyWebServer")
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("MyCompany.MyProduct.MyWebServer")
.SetResource(Resources.CreateServiceResource("MyServiceName"))
.AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter
.UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson)
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static object Run()
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddHttpClientInstrumentation()
.SetResource(Resources.CreateServiceResource("http-service-example"))
.AddActivitySource("http-client-test")
.AddSource("http-client-test")
.UseConsoleExporter(opt => opt.DisplayAsJson = false)
.Build();

Expand Down
3 changes: 1 addition & 2 deletions examples/Console/TestJaegerExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ internal static object RunWithActivity(string host, int port)
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
// and use the Jaeger exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("Samples.SampleServer")
.AddActivitySource("Samples.SampleClient")
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.UseJaegerExporter(o =>
{
o.ServiceName = "jaeger-test";
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestOTelShimWithConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static object Run(OpenTelemetryShimOptions options)
// Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer"
// and use a single pipeline with a custom MyProcessor, and Console exporter.
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyWebServer")
.AddSource("MyCompany.MyProduct.MyWebServer")
.SetResource(Resources.CreateServiceResource("MyServiceName"))
.UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson)
.Build();
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestOpenTracingWithConsoleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static object Run(OpenTracingShimOptions options)
// Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer"
// and use Console exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("MyCompany.MyProduct.MyWebServer")
.AddSource("MyCompany.MyProduct.MyWebServer")
.SetResource(Resources.CreateServiceResource("MyServiceName"))
.UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson)
.Build();
Expand Down
3 changes: 1 addition & 2 deletions examples/Console/TestOtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ private static object RunWithActivitySource(string endpoint)
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
// and use OTLP exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("Samples.SampleServer")
.AddActivitySource("Samples.SampleClient")
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.UseOtlpExporter(opt => opt.Endpoint = endpoint)
.Build();

Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestRedis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static object Run(string zipkinUri)
// changing flushinterval from 10s to 5s
options.FlushInterval = TimeSpan.FromSeconds(5);
})
.AddActivitySource("redis-test")
.AddSource("redis-test")
.Build();

ActivitySource activitySource = new ActivitySource("redis-test");
Expand Down
2 changes: 1 addition & 1 deletion examples/Console/TestZPagesExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static object Run()
httpServer.Start();

using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("zpages-test")
.AddSource("zpages-test")
.AddProcessor(zpagesProcessor)
.UseZPagesExporter()
.Build();
Expand Down
3 changes: 1 addition & 2 deletions examples/Console/TestZipkinExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ internal static object Run(string zipkinUri)
// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
// and use the Zipkin exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddActivitySource("Samples.SampleServer")
.AddActivitySource("Samples.SampleClient")
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.UseZipkinExporter(o =>
{
o.ServiceName = "test-zipkin";
Expand Down
2 changes: 1 addition & 1 deletion examples/MicroserviceExample/WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddOpenTelemetry((builder) => builder
.AddAspNetCoreInstrumentation()
.AddActivitySource(nameof(MessageSender))
.AddSource(nameof(MessageSender))
.UseZipkinExporter(b =>
{
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
Expand Down
2 changes: 1 addition & 1 deletion examples/MicroserviceExample/WorkerService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
services.AddOpenTelemetry((builder) =>
{
builder
.AddActivitySource(nameof(MessageReceiver))
.AddSource(nameof(MessageReceiver))
.UseZipkinExporter(b =>
{
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal static TracerProviderBuilder AddHttpWebRequestInstrumentation(

HttpWebRequestActivitySource.Options = options;

builder.AddActivitySource(HttpWebRequestActivitySource.ActivitySourceName);
builder.AddSource(HttpWebRequestActivitySource.ActivitySourceName);

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(
configureSqlClientInstrumentationOptions?.Invoke(sqlOptions);

builder.AddInstrumentation((activitySource) => new SqlClientInstrumentation(sqlOptions));
builder.AddActivitySource(SqlClientDiagnosticListener.ActivitySourceName);
builder.AddSource(SqlClientDiagnosticListener.ActivitySourceName);

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

return builder
.AddInstrumentation((activitySourceAdapter) => new StackExchangeRedisCallsInstrumentation(connection, options))
.AddActivitySource(StackExchangeRedisCallsInstrumentation.ActivitySourceName);
.AddSource(StackExchangeRedisCallsInstrumentation.ActivitySourceName);
}
}
}
32 changes: 10 additions & 22 deletions src/OpenTelemetry/Trace/TracerProviderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,28 @@ public TracerProviderBuilder SetResource(Resource resource)
return this;
}

/// <summary>
/// Adds given activitysource name to the list of subscribed sources.
/// </summary>
/// <param name="name">Activity source name.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public TracerProviderBuilder AddActivitySource(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException($"{nameof(name)} is null or whitespace.");
}

// TODO: We need to fix the listening model.
// Today it ignores version.
this.sources.Add(name);

return this;
}

/// <summary>
/// Adds given activitysource names to the list of subscribed sources.
/// </summary>
/// <param name="names">Activity source names.</param>
/// <returns>Returns <see cref="TracerProviderBuilder"/> for chaining.</returns>
public TracerProviderBuilder AddActivitySource(IEnumerable<string> names)
public TracerProviderBuilder AddSource(params string[] names)
{
if (names == null)
{
throw new ArgumentNullException(nameof(names));
}

foreach (var name in names)
{
this.AddActivitySource(name);
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException($"{nameof(names)} contains null or whitespace string.");
}

// TODO: We need to fix the listening model.
// Today it ignores version.
this.sources.Add(name);
}

return this;
Expand Down
14 changes: 9 additions & 5 deletions test/Benchmarks/OpenTelemetrySdkBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ public class OpenTelemetrySdkBenchmarks

public OpenTelemetrySdkBenchmarks()
{
using var openTelemetryAlwaysOnSample = Sdk.CreateTracerProviderBuilder().AddActivitySource("AlwaysOnSample")
.SetSampler(new AlwaysOnSampler()).Build();

using var openTelemetryAlwaysOffSample = Sdk.CreateTracerProviderBuilder().AddActivitySource("AlwaysOffSample")
.SetSampler(new AlwaysOffSampler()).Build();
using var openTelemetryAlwaysOnSample = Sdk.CreateTracerProviderBuilder()
.AddSource("AlwaysOnSample")
.SetSampler(new AlwaysOnSampler())
.Build();

using var openTelemetryAlwaysOffSample = Sdk.CreateTracerProviderBuilder()
.AddSource("AlwaysOffSample")
.SetSampler(new AlwaysOffSampler())
.Build();

using var openTelemetryNoop = Sdk.CreateTracerProviderBuilder().Build();

Expand Down
4 changes: 3 additions & 1 deletion test/Benchmarks/OpenTelemetrySdkBenchmarksActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class OpenTelemetrySdkBenchmarksActivity
public OpenTelemetrySdkBenchmarksActivity()
{
// Not configuring pipeline, which will result in default NoopActivityProcessor.
var openTel = Sdk.CreateTracerProviderBuilder().AddActivitySource("BenchMark");
var openTel = Sdk.CreateTracerProviderBuilder()
.AddSource("BenchMark")
.Build();
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void UseJaegerExporterWithCustomActivityProcessor()
};

var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseJaegerExporter()
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void ToOtlpResourceSpansTest()

// This following is done just to set Resource to Activity.
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(sources[0].Name)
.AddActivitySource(sources[1].Name)
.AddSource(sources[0].Name)
.AddSource(sources[1].Name)
.SetResource(resource)
.Build();

Expand Down Expand Up @@ -260,7 +260,7 @@ public void UseOpenTelemetryProtocolActivityExporterWithCustomActivityProcessor(
};

var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseOtlpExporter()
.Build();
Expand Down
10 changes: 5 additions & 5 deletions test/OpenTelemetry.Exporter.ZPages.Tests/ZPagesExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void ZPagesExporter_CustomActivityProcessor()
};

var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseZPagesExporter()
.Build();
.AddSource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseZPagesExporter()
.Build();

var source = new ActivitySource(ActivitySourceName);
var activity = source.StartActivity("Test Zipkin Activity");
Expand Down Expand Up @@ -130,7 +130,7 @@ public void ZPagesExporter_ZPagesProcessor()
var zpagesProcessor = new ZPagesProcessor(exporter);

using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.AddProcessor(zpagesProcessor)
.UseZPagesExporter()
.Build();
Expand Down
17 changes: 8 additions & 9 deletions test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,14 @@ public void UseZipkinExporterWithCustomActivityProcessor()
};

var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseZipkinExporter(
o =>
{
o.ServiceName = "test-zipkin";
o.Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}");
})
.Build();
.AddSource(ActivitySourceName)
.AddProcessor(testActivityProcessor)
.UseZipkinExporter(o =>
{
o.ServiceName = "test-zipkin";
o.Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}");
})
.Build();

var source = new ActivitySource(ActivitySourceName);
var activity = source.StartActivity("Test Zipkin Activity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ActivityExtensionsTest
public void SetStatus()
{
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.Build();

using var source = new ActivitySource(ActivitySourceName);
Expand All @@ -43,7 +43,7 @@ public void SetStatus()
public void SetStatusWithDescription()
{
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.Build();

using var source = new ActivitySource(ActivitySourceName);
Expand All @@ -60,7 +60,7 @@ public void SetStatusWithDescription()
public void SetCancelledStatus()
{
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.Build();

using var source = new ActivitySource(ActivitySourceName);
Expand All @@ -75,7 +75,7 @@ public void SetCancelledStatus()
public void GetStatusWithNoStatusInActivity()
{
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.Build();

using var source = new ActivitySource(ActivitySourceName);
Expand All @@ -89,7 +89,7 @@ public void GetStatusWithNoStatusInActivity()
public void LastSetStatusWins()
{
using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddActivitySource(ActivitySourceName)
.AddSource(ActivitySourceName)
.Build();

using var source = new ActivitySource(ActivitySourceName);
Expand Down
Loading

0 comments on commit ce0bf3f

Please sign in to comment.