From 183427771a01da1ef94e90ce7e0582e69ec3547c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Neum=C3=BCller?= Date: Mon, 13 Jun 2022 16:16:42 +0200 Subject: [PATCH] Rename ConfigureResources to sg ConfigureResource. --- docs/logs/customizing-the-sdk/Program.cs | 2 +- docs/logs/customizing-the-sdk/README.md | 6 +++--- examples/AspNetCore/Program.cs | 6 +++--- examples/Console/TestConsoleExporter.cs | 2 +- examples/Console/TestHttpClient.cs | 2 +- examples/Console/TestInMemoryExporter.cs | 2 +- examples/Console/TestJaegerExporter.cs | 2 +- examples/Console/TestMetrics.cs | 2 +- examples/Console/TestOTelShimWithConsoleExporter.cs | 2 +- examples/Console/TestOpenTracingShim.cs | 2 +- examples/Console/TestOtlpExporter.cs | 2 +- examples/Console/TestZipkinExporter.cs | 2 +- examples/GrpcService/Startup.cs | 2 +- src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt | 2 +- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 2 +- src/OpenTelemetry/CHANGELOG.md | 2 +- src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs | 4 ++-- src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs | 4 ++-- src/OpenTelemetry/README.md | 2 +- src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs | 4 ++-- .../Instrumentation/InstrumentedHttpClientBenchmark.cs | 2 +- test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs | 2 +- 22 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/logs/customizing-the-sdk/Program.cs b/docs/logs/customizing-the-sdk/Program.cs index 4e74c286d8f..b6b3afd07d8 100644 --- a/docs/logs/customizing-the-sdk/Program.cs +++ b/docs/logs/customizing-the-sdk/Program.cs @@ -30,7 +30,7 @@ public static void Main() builder.AddOpenTelemetry(options => { options.IncludeScopes = true; - options.ConfigureResources(r => r.AddService(serviceName: "MyService", serviceVersion: "1.0.0")); + options.ConfigureResource(r => r.AddService(serviceName: "MyService", serviceVersion: "1.0.0")); options.AddConsoleExporter(); }); }); diff --git a/docs/logs/customizing-the-sdk/README.md b/docs/logs/customizing-the-sdk/README.md index ebe07bba08b..8b1d9bcb944 100644 --- a/docs/logs/customizing-the-sdk/README.md +++ b/docs/logs/customizing-the-sdk/README.md @@ -52,14 +52,14 @@ var loggerFactory = LoggerFactory.Create(builder => For more information on Processors, please review [Extending the SDK](../extending-the-sdk/README.md#processor) -### ConfigureResources +### ConfigureResource [Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md) is the immutable representation of the entity producing the telemetry. If no `Resource` is explicitly configured, the default is to use a resource indicating this [Telemetry SDK](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#telemetry-sdk). -The `ConfigureResources` method on `OpenTelemetryLoggerOptions` can be used to +The `ConfigureResource` method on `OpenTelemetryLoggerOptions` can be used to configure the `ResourceBuilder`. It is not possible to change the resources *after* creating the `LoggerFactory`. @@ -70,7 +70,7 @@ var loggerFactory = LoggerFactory.Create(builder => { builder.AddOpenTelemetry(options => { - options.ConfigureResources(r => r.AddService( + options.ConfigureResource(r => r.AddService( serviceName: "MyService", serviceVersion: "1.0.0" )); diff --git a/examples/AspNetCore/Program.cs b/examples/AspNetCore/Program.cs index 0136a364999..576dc4f7b2a 100644 --- a/examples/AspNetCore/Program.cs +++ b/examples/AspNetCore/Program.cs @@ -45,7 +45,7 @@ builder.Services.AddOpenTelemetryTracing(options => { options - .ConfigureResources(configureResources) + .ConfigureResource(configureResources) .SetSampler(new AlwaysOnSampler()) .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(); @@ -89,7 +89,7 @@ builder.Logging.AddOpenTelemetry(options => { - options.ConfigureResources(configureResources); + options.ConfigureResource(configureResources); var logExporter = builder.Configuration.GetValue("UseLogExporter").ToLowerInvariant(); switch (logExporter) { @@ -115,7 +115,7 @@ // Metrics builder.Services.AddOpenTelemetryMetrics(options => { - options.ConfigureResources(configureResources) + options.ConfigureResource(configureResources) .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(); diff --git a/examples/Console/TestConsoleExporter.cs b/examples/Console/TestConsoleExporter.cs index 4abcce7f7b0..031e6fc4e09 100644 --- a/examples/Console/TestConsoleExporter.cs +++ b/examples/Console/TestConsoleExporter.cs @@ -39,7 +39,7 @@ private static object RunWithActivitySource() // and use Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResources(res => res.AddService("console-test")) + .ConfigureResource(res => res.AddService("console-test")) .AddProcessor(new MyProcessor()) // This must be added before ConsoleExporter .AddConsoleExporter() .Build(); diff --git a/examples/Console/TestHttpClient.cs b/examples/Console/TestHttpClient.cs index 16c836abd4f..ba122c5f09a 100644 --- a/examples/Console/TestHttpClient.cs +++ b/examples/Console/TestHttpClient.cs @@ -34,7 +34,7 @@ internal static object Run() using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation() - .ConfigureResources(r => r.AddService("http-service-example")) + .ConfigureResource(r => r.AddService("http-service-example")) .AddSource("http-client-test") .AddConsoleExporter() .Build(); diff --git a/examples/Console/TestInMemoryExporter.cs b/examples/Console/TestInMemoryExporter.cs index 1c653f605f1..5cfbe327417 100644 --- a/examples/Console/TestInMemoryExporter.cs +++ b/examples/Console/TestInMemoryExporter.cs @@ -51,7 +51,7 @@ private static void RunWithActivitySource(ICollection exportedItems) // and use InMemory exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResources(r => r.AddService("inmemory-test")) + .ConfigureResource(r => r.AddService("inmemory-test")) .AddInMemoryExporter(exportedItems) .Build(); diff --git a/examples/Console/TestJaegerExporter.cs b/examples/Console/TestJaegerExporter.cs index 8534beda7e9..aca3909886e 100644 --- a/examples/Console/TestJaegerExporter.cs +++ b/examples/Console/TestJaegerExporter.cs @@ -56,7 +56,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 tracerProvider = Sdk.CreateTracerProviderBuilder() - .ConfigureResources(r => r.AddService("jaeger-test")) + .ConfigureResource(r => r.AddService("jaeger-test")) .AddSource("Samples.SampleClient", "Samples.SampleServer") .AddJaegerExporter(o => { diff --git a/examples/Console/TestMetrics.cs b/examples/Console/TestMetrics.cs index 669788af4d1..78ee9cbed97 100644 --- a/examples/Console/TestMetrics.cs +++ b/examples/Console/TestMetrics.cs @@ -33,7 +33,7 @@ internal static object Run(MetricsOptions options) using var meter = new Meter("TestMeter"); var providerBuilder = Sdk.CreateMeterProviderBuilder() - .ConfigureResources(r => r.AddService("myservice")) + .ConfigureResource(r => r.AddService("myservice")) .AddMeter(meter.Name); // All instruments from this meter are enabled. if (options.UseExporter.Equals("otlp", StringComparison.OrdinalIgnoreCase)) diff --git a/examples/Console/TestOTelShimWithConsoleExporter.cs b/examples/Console/TestOTelShimWithConsoleExporter.cs index 26b866d9d69..31bb3c85f6b 100644 --- a/examples/Console/TestOTelShimWithConsoleExporter.cs +++ b/examples/Console/TestOTelShimWithConsoleExporter.cs @@ -28,7 +28,7 @@ internal static object Run(OpenTelemetryShimOptions options) // and use a single pipeline with a custom MyProcessor, and Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") - .ConfigureResources(r => r.AddService("MyServiceName")) + .ConfigureResource(r => r.AddService("MyServiceName")) .AddConsoleExporter() .Build(); diff --git a/examples/Console/TestOpenTracingShim.cs b/examples/Console/TestOpenTracingShim.cs index ae9995ea083..7361c3aa4d5 100644 --- a/examples/Console/TestOpenTracingShim.cs +++ b/examples/Console/TestOpenTracingShim.cs @@ -31,7 +31,7 @@ internal static object Run(OpenTracingShimOptions options) // and use Console exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("MyCompany.MyProduct.MyWebServer") - .ConfigureResources(r => r.AddService("MyServiceName")) + .ConfigureResource(r => r.AddService("MyServiceName")) .AddConsoleExporter() .Build(); diff --git a/examples/Console/TestOtlpExporter.cs b/examples/Console/TestOtlpExporter.cs index 51202fd7c60..f5417e77c66 100644 --- a/examples/Console/TestOtlpExporter.cs +++ b/examples/Console/TestOtlpExporter.cs @@ -71,7 +71,7 @@ private static object RunWithActivitySource(string endpoint, string protocol) // and use OTLP exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResources(r => r.AddService("otlp-test")) + .ConfigureResource(r => r.AddService("otlp-test")) .AddOtlpExporter(opt => { // If endpoint was not specified, the proper one will be selected according to the protocol. diff --git a/examples/Console/TestZipkinExporter.cs b/examples/Console/TestZipkinExporter.cs index 4a1ee7efd91..0f6bbce2272 100644 --- a/examples/Console/TestZipkinExporter.cs +++ b/examples/Console/TestZipkinExporter.cs @@ -39,7 +39,7 @@ internal static object Run(string zipkinUri) // and use the Zipkin exporter. using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("Samples.SampleClient", "Samples.SampleServer") - .ConfigureResources(r => r.AddService("zipkin-test")) + .ConfigureResource(r => r.AddService("zipkin-test")) .AddZipkinExporter(o => { o.Endpoint = new Uri(zipkinUri); diff --git a/examples/GrpcService/Startup.cs b/examples/GrpcService/Startup.cs index 5e0ab4c2574..c7034011b02 100644 --- a/examples/GrpcService/Startup.cs +++ b/examples/GrpcService/Startup.cs @@ -45,7 +45,7 @@ public void ConfigureServices(IServiceCollection services) { case "jaeger": services.AddOpenTelemetryTracing((builder) => builder - .ConfigureResources(r => r.AddService(this.Configuration.GetValue("Jaeger:ServiceName"))) + .ConfigureResource(r => r.AddService(this.Configuration.GetValue("Jaeger:ServiceName"))) .AddAspNetCoreInstrumentation() .AddJaegerExporter(jaegerOptions => { diff --git a/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt index e5e4770ac82..8d8412a4627 100644 --- a/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,4 +1,4 @@ #nullable enable OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResources(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! ~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResources(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder -~static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResources(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +~static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index e5e4770ac82..8d8412a4627 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,4 +1,4 @@ #nullable enable OpenTelemetry.Logs.OpenTelemetryLoggerOptions.ConfigureResources(System.Action! configure) -> OpenTelemetry.Logs.OpenTelemetryLoggerOptions! ~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResources(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action configure) -> OpenTelemetry.Metrics.MeterProviderBuilder -~static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResources(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder +~static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder tracerProviderBuilder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 074d14c1dda..9af5b14b7f8 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -24,7 +24,7 @@ Released 2022-June-1 * Swallow `ObjectDisposedException` in `BatchExportProcessor` and `PeriodicExportingMetricReader`. ([#3291](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3291)) -* Add `ConfigureResources` which can replace SetResourceBuilder more succinctly +* Add `ConfigureResource` which can replace SetResourceBuilder more succinctly in most cases and has greater flexibility (applies to TracerProvicerBuilder, MeterProviderBuilder, OpenTelemetryLoggingOptions). ([#3307](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3307)) diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs index 0900f9271b7..d20fcce2b47 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerOptions.cs @@ -74,7 +74,7 @@ public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor processo /// /// Sets the from which the Resource associated with /// this provider is built from. Overwrites currently set ResourceBuilder. - /// You should usually use instead + /// You should usually use instead /// (call if desired). /// /// from which Resource will be built. @@ -93,7 +93,7 @@ public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBui /// /// An action which modifies the provided in-place. /// Returns for chaining. - public OpenTelemetryLoggerOptions ConfigureResources(Action configure) + public OpenTelemetryLoggerOptions ConfigureResource(Action configure) { Guard.ThrowIfNull(configure, nameof(configure)); configure(this.ResourceBuilder); diff --git a/src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs b/src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs index 751dadc0d51..c9ab4726712 100644 --- a/src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs +++ b/src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs @@ -183,7 +183,7 @@ public static MeterProviderBuilder SetMaxMetricPointsPerMetricStream(this MeterP /// /// Sets the from which the Resource associated with /// this provider is built from. Overwrites currently set ResourceBuilder. - /// You should usually use instead + /// You should usually use instead /// (call if desired). /// /// MeterProviderBuilder instance. @@ -206,7 +206,7 @@ public static MeterProviderBuilder SetResourceBuilder(this MeterProviderBuilder /// MeterProviderBuilder instance. /// An action which modifies the provided in-place. /// Returns for chaining. - public static MeterProviderBuilder ConfigureResources(this MeterProviderBuilder meterProviderBuilder, Action configure) + public static MeterProviderBuilder ConfigureResource(this MeterProviderBuilder meterProviderBuilder, Action configure) { Guard.ThrowIfNull(meterProviderBuilder, nameof(meterProviderBuilder)); Guard.ThrowIfNull(configure, nameof(configure)); diff --git a/src/OpenTelemetry/README.md b/src/OpenTelemetry/README.md index 2b5d1e2acb0..0f41b3808da 100644 --- a/src/OpenTelemetry/README.md +++ b/src/OpenTelemetry/README.md @@ -255,7 +255,7 @@ using OpenTelemetry.Resources; using OpenTelemetry.Trace; using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .ConfigureResources(r => r.AddService("MyServiceName")) + .ConfigureResource(r => r.AddService("MyServiceName")) .Build(); ``` diff --git a/src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs index 1a2ce2ba4a6..24f26e98e01 100644 --- a/src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderBuilderExtensions.cs @@ -62,7 +62,7 @@ public static TracerProviderBuilder SetSampler(this TracerProviderBuilder tracer /// /// Sets the from which the Resource associated with /// this provider is built from. Overwrites currently set ResourceBuilder. - /// You should usually use instead + /// You should usually use instead /// (call if desired). /// /// TracerProviderBuilder instance. @@ -85,7 +85,7 @@ public static TracerProviderBuilder SetResourceBuilder(this TracerProviderBuilde /// TracerProviderBuilder instance. /// An action which modifies the provided in-place. /// Returns for chaining. - public static TracerProviderBuilder ConfigureResources(this TracerProviderBuilder tracerProviderBuilder, Action configure) + public static TracerProviderBuilder ConfigureResource(this TracerProviderBuilder tracerProviderBuilder, Action configure) { Guard.ThrowIfNull(tracerProviderBuilder, nameof(tracerProviderBuilder)); Guard.ThrowIfNull(configure, nameof(configure)); diff --git a/test/Benchmarks/Instrumentation/InstrumentedHttpClientBenchmark.cs b/test/Benchmarks/Instrumentation/InstrumentedHttpClientBenchmark.cs index 65c143afb29..ff2555eaeb3 100644 --- a/test/Benchmarks/Instrumentation/InstrumentedHttpClientBenchmark.cs +++ b/test/Benchmarks/Instrumentation/InstrumentedHttpClientBenchmark.cs @@ -52,7 +52,7 @@ public void GlobalSetup() this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation() - .ConfigureResources(r => r.AddService(ServiceName)) + .ConfigureResource(r => r.AddService(ServiceName)) .AddSource(SourceName) .Build(); diff --git a/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs b/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs index a6967aa1762..ab5702654eb 100644 --- a/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs +++ b/test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs @@ -1068,7 +1068,7 @@ public void TracerProviderSdkBuildsWithSDKResource(bool useConfigure) var tracerProvider = useConfigure ? Sdk.CreateTracerProviderBuilder().SetResourceBuilder( ResourceBuilder.CreateDefault().AddTelemetrySdk()).Build() : - Sdk.CreateTracerProviderBuilder().ConfigureResources(r => r.AddTelemetrySdk()).Build(); + Sdk.CreateTracerProviderBuilder().ConfigureResource(r => r.AddTelemetrySdk()).Build(); var resource = tracerProvider.GetResource(); var attributes = resource.Attributes;