From 35fec21699158ec9287d845798d2526676db6ff9 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 5 Oct 2022 12:55:57 -0700 Subject: [PATCH 01/13] [HttpClient] Export spans corresponding to retries --- src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 4 ++++ .../HttpRequestMessageContextPropagation.cs | 1 + .../Implementation/HttpHandlerDiagnosticListener.cs | 8 -------- .../HttpClientTests.Basic.cs | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index d3158da9348..1aa38220666 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* In case of .NET Core, additional spans created during retries will now be +exported. +([[#3729](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3729)]) + ## 1.0.0-rc9.7 Released 2022-Sep-29 diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpRequestMessageContextPropagation.cs b/src/OpenTelemetry.Instrumentation.Http/HttpRequestMessageContextPropagation.cs index 16999593811..14b26850e97 100644 --- a/src/OpenTelemetry.Instrumentation.Http/HttpRequestMessageContextPropagation.cs +++ b/src/OpenTelemetry.Instrumentation.Http/HttpRequestMessageContextPropagation.cs @@ -34,6 +34,7 @@ internal static class HttpRequestMessageContextPropagation internal static Action HeaderValueSetter => (request, name, value) => { + request.Headers.Remove(name); request.Headers.Add(name, value); }; } diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs index 2b1e741906d..7b066c0c755 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs @@ -115,14 +115,6 @@ public void OnStartActivity(Activity activity, object payload) return; } - // TODO: Investigate why this check is needed. - if (Propagators.DefaultTextMapPropagator.Extract(default, request, HttpRequestMessageContextPropagation.HeaderValuesGetter) != default) - { - // this request is already instrumented, we should back off - activity.IsAllDataRequested = false; - return; - } - // Propagate context irrespective of sampling decision var textMapPropagator = Propagators.DefaultTextMapPropagator; if (textMapPropagator is not TraceContextPropagator) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs index df742c63634..5207a9865b6 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs @@ -301,7 +301,7 @@ public async Task HttpClientInstrumentation_AddViaFactory_HttpInstrumentation_Co Assert.IsType(processor.Invocations[1].Arguments[0]); } - [Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/3729")] + [Fact] public async Task HttpClientInstrumentationExportsSpansCreatedForRetries() { var exportedItems = new List(); From dbfdb560021d68c20cc15ba44ebd5f8d17b6cbc0 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 5 Oct 2022 12:58:09 -0700 Subject: [PATCH 02/13] nit --- .../HttpClientTests.Basic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs index 5207a9865b6..8d7581e49fe 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.cs @@ -321,7 +321,7 @@ public async Task HttpClientInstrumentationExportsSpansCreatedForRetries() await c.SendAsync(request); // number of exported spans should be 3(maxRetries) - Assert.Equal(3, exportedItems.Count()); + Assert.Equal(maxRetries, exportedItems.Count()); var spanid1 = exportedItems[0].SpanId; var spanid2 = exportedItems[1].SpanId; From 374e9ac9e855be8f30a7bb2c3e1ff3d0ad6cc0c2 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 10 Oct 2022 10:40:14 -0700 Subject: [PATCH 03/13] Update enrich callbacks --- .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 10 +++++--- .../.publicApi/net7.0/PublicAPI.Unshipped.txt | 10 +++++--- .../AspNetCoreInstrumentationOptions.cs | 24 +++++++++++++++---- .../Implementation/HttpInListener.cs | 6 ++--- .../BasicTests.cs | 20 +++++++++++----- .../GrpcTests.client.cs | 12 ++-------- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt index 0327c2bb195..2695441ab98 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -2,8 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool @@ -13,4 +17,4 @@ OpenTelemetry.Trace.TracerProviderBuilderExtensions static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder \ No newline at end of file +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt index 0327c2bb195..2695441ab98 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt @@ -2,8 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool @@ -13,4 +17,4 @@ OpenTelemetry.Trace.TracerProviderBuilderExtensions static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder \ No newline at end of file +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetCoreInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 3b6ecc676c1..2f22055250e 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -38,11 +38,27 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// string: the name of the event. - /// object: the raw object from which additional information can be extracted to enrich the activity. - /// The type of this object depends on the event, which is given by the above parameter. + /// : the HttpRequest object from which additional information can be extracted to enrich the activity during start event. /// - public Action Enrich { get; set; } + public Action EnrichOnStart { get; set; } + + /// + /// Gets or sets an action to enrich an Activity. + /// + /// + /// : the activity being enriched. + /// : the HttpResponse object from which additional information can be extracted to enrich the activity during stop event. + /// + public Action EnrichOnStop { get; set; } + + /// + /// Gets or sets an action to enrich an Activity. + /// + /// + /// : the activity being enriched. + /// : the Exception object from which additional information can be extracted to enrich the activity during exception event. + /// + public Action EnrichOnException { get; set; } /// /// Gets or sets a value indicating whether the exception will be recorded as ActivityEvent or not. diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index e8a214203b3..7cfff4903ed 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -211,7 +211,7 @@ public void OnStartActivity(Activity activity, object payload) try { - this.options.Enrich?.Invoke(activity, "OnStartActivity", request); + this.options.EnrichOnStart?.Invoke(activity, request); } catch (Exception ex) { @@ -246,7 +246,7 @@ public void OnStopActivity(Activity activity, object payload) try { - this.options.Enrich?.Invoke(activity, "OnStopActivity", response); + this.options.EnrichOnStop?.Invoke(activity, response); } catch (Exception ex) { @@ -345,7 +345,7 @@ public void OnException(Activity activity, object payload) try { - this.options.Enrich?.Invoke(activity, "OnException", exc); + this.options.EnrichOnException?.Invoke(activity, exc); } catch (Exception ex) { diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 2ce0e7989c7..0132ed5400f 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -105,7 +105,8 @@ void ConfigureTestServices(IServiceCollection services) { if (shouldEnrich) { - options.Enrich = ActivityEnrichment; + options.EnrichOnStart = (activity, request) => { activity.SetTag("enrichedOnStart", "yes"); }; + options.EnrichOnStop = (activity, response) => { activity.SetTag("enrichedOnStop", "yes"); }; } }) .AddInMemoryExporter(exportedItems) @@ -132,7 +133,8 @@ void ConfigureTestServices(IServiceCollection services) if (shouldEnrich) { - Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enriched" && tag.Value == "yes")); + Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enrichedOnStart" && tag.Value == "yes")); + Assert.NotEmpty(activity.Tags.Where(tag => tag.Key == "enrichedOnStop" && tag.Value == "yes")); } ValidateAspNetCoreActivity(activity, "/api/values"); @@ -519,7 +521,8 @@ void ConfigureTestServices(IServiceCollection services) public async Task FilterAndEnrichAreOnlyCalledWhenSampled(SamplingDecision samplingDecision, bool shouldFilterBeCalled, bool shouldEnrichBeCalled) { bool filterCalled = false; - bool enrichCalled = false; + bool enrichOnStartCalled = false; + bool enrichOnStopCalled = false; void ConfigureTestServices(IServiceCollection services) { this.tracerProvider = Sdk.CreateTracerProviderBuilder() @@ -531,9 +534,13 @@ void ConfigureTestServices(IServiceCollection services) filterCalled = true; return true; }; - options.Enrich = (activity, methodName, request) => + options.EnrichOnStart = (activity, request) => { - enrichCalled = true; + enrichOnStartCalled = true; + }; + options.EnrichOnStop = (activity, request) => + { + enrichOnStopCalled = true; }; }) .Build(); @@ -550,7 +557,8 @@ void ConfigureTestServices(IServiceCollection services) // Assert Assert.Equal(shouldFilterBeCalled, filterCalled); - Assert.Equal(shouldEnrichBeCalled, enrichCalled); + Assert.Equal(shouldEnrichBeCalled, enrichOnStartCalled); + Assert.Equal(shouldEnrichBeCalled, enrichOnStopCalled); } [Fact] diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index e011eead53c..0d865157778 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -264,17 +264,9 @@ public void GrpcPropagatesContextWithSuppressInstrumentationOptionSetToTrue() .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(options => { - options.Enrich = (activity, eventName, obj) => + options.EnrichOnStart = (activity, request) => { - switch (eventName) - { - case "OnStartActivity": - var request = (HttpRequest)obj; - activity.SetCustomProperty("customField", request.Headers["customField"].ToString()); - break; - default: - break; - } + activity.SetCustomProperty("customField", request.Headers["customField"].ToString()); }; }) // Instrumenting the server side as well .AddProcessor(processor.Object) From f36eaf58901f5c0a622e011dbc7475fe3d614131 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 10 Oct 2022 11:21:11 -0700 Subject: [PATCH 04/13] update changelog --- src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 1308cce0313..4d241ba77a3 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* [Breaking] `Enrich` callback is split in to three different callbacks based on + `OnStart`, `OnStop` and `OnException` event. + ([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749)) + ## 1.0.0-rc9.7 Released 2022-Sep-29 From d8a1859edda7349fc0ec828107e6c26f5ac5ed1a Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 10 Oct 2022 11:29:32 -0700 Subject: [PATCH 05/13] update desc --- .../AspNetCoreInstrumentationOptions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 2f22055250e..2a26166b6e3 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -34,7 +34,7 @@ public class AspNetCoreInstrumentationOptions public Func Filter { get; set; } /// - /// Gets or sets an action to enrich an Activity. + /// Gets or sets an action to enrich an Activity during start event. /// /// /// : the activity being enriched. @@ -43,7 +43,7 @@ public class AspNetCoreInstrumentationOptions public Action EnrichOnStart { get; set; } /// - /// Gets or sets an action to enrich an Activity. + /// Gets or sets an action to enrich an Activity during stop event. /// /// /// : the activity being enriched. @@ -52,7 +52,7 @@ public class AspNetCoreInstrumentationOptions public Action EnrichOnStop { get; set; } /// - /// Gets or sets an action to enrich an Activity. + /// Gets or sets an action to enrich an Activity during exception event. /// /// /// : the activity being enriched. From f28e4351bdb6cf0d2983a8235f4a618c8d8e402c Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 10 Oct 2022 13:28:56 -0700 Subject: [PATCH 06/13] clarify parameters --- .../AspNetCoreInstrumentationOptions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 2a26166b6e3..81920b8cbc6 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -38,7 +38,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the HttpRequest object from which additional information can be extracted to enrich the activity during start event. + /// : the HttpRequest object from which additional information can be extracted to enrich the activity during request start event. /// public Action EnrichOnStart { get; set; } @@ -47,7 +47,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the HttpResponse object from which additional information can be extracted to enrich the activity during stop event. + /// : the HttpResponse object from which additional information can be extracted to enrich the activity during request stop event. /// public Action EnrichOnStop { get; set; } @@ -56,7 +56,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the Exception object from which additional information can be extracted to enrich the activity during exception event. + /// : the Exception object from which additional information can be extracted to enrich the activity on exception during request. /// public Action EnrichOnException { get; set; } From f5a26c4b5fce7f1059761b83c683c8b6c1743a4f Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Oct 2022 14:45:57 -0700 Subject: [PATCH 07/13] resolve PR comments --- .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 12 +++++------ .../.publicApi/net7.0/PublicAPI.Unshipped.txt | 12 +++++------ .../AspNetCoreInstrumentationOptions.cs | 6 +++--- .../CHANGELOG.md | 5 +++++ .../Implementation/HttpInListener.cs | 6 +++--- .../BasicTests.cs | 20 +++++++++---------- .../GrpcTests.client.cs | 2 +- 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt index 2695441ab98..b3b24c45be9 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -2,12 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt index 2695441ab98..b3b24c45be9 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/net7.0/PublicAPI.Unshipped.txt @@ -2,12 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnException.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStart.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichOnStop.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 81920b8cbc6..cf0698820d1 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -40,7 +40,7 @@ public class AspNetCoreInstrumentationOptions /// : the activity being enriched. /// : the HttpRequest object from which additional information can be extracted to enrich the activity during request start event. /// - public Action EnrichOnStart { get; set; } + public Action EnrichWithHttpRequest { get; set; } /// /// Gets or sets an action to enrich an Activity during stop event. @@ -49,7 +49,7 @@ public class AspNetCoreInstrumentationOptions /// : the activity being enriched. /// : the HttpResponse object from which additional information can be extracted to enrich the activity during request stop event. /// - public Action EnrichOnStop { get; set; } + public Action EnrichWithHttpResponse { get; set; } /// /// Gets or sets an action to enrich an Activity during exception event. @@ -58,7 +58,7 @@ public class AspNetCoreInstrumentationOptions /// : the activity being enriched. /// : the Exception object from which additional information can be extracted to enrich the activity on exception during request. /// - public Action EnrichOnException { get; set; } + public Action EnrichWithException { get; set; } /// /// Gets or sets a value indicating whether the exception will be recorded as ActivityEvent or not. diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index c25cff48f0e..0719ace1a54 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* `Enrich` callback is now split into 3 different callbacks based on the object +that is passed in to enrich activity. The new callbacks are +`EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException`. +([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749)) + ## 1.0.0-rc9.8 Released 2022-Oct-17 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 7cfff4903ed..b550a06b329 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -211,7 +211,7 @@ public void OnStartActivity(Activity activity, object payload) try { - this.options.EnrichOnStart?.Invoke(activity, request); + this.options.EnrichWithHttpRequest?.Invoke(activity, request); } catch (Exception ex) { @@ -246,7 +246,7 @@ public void OnStopActivity(Activity activity, object payload) try { - this.options.EnrichOnStop?.Invoke(activity, response); + this.options.EnrichWithHttpResponse?.Invoke(activity, response); } catch (Exception ex) { @@ -345,7 +345,7 @@ public void OnException(Activity activity, object payload) try { - this.options.EnrichOnException?.Invoke(activity, exc); + this.options.EnrichWithException?.Invoke(activity, exc); } catch (Exception ex) { diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 0132ed5400f..fe623375a6a 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -105,8 +105,8 @@ void ConfigureTestServices(IServiceCollection services) { if (shouldEnrich) { - options.EnrichOnStart = (activity, request) => { activity.SetTag("enrichedOnStart", "yes"); }; - options.EnrichOnStop = (activity, response) => { activity.SetTag("enrichedOnStop", "yes"); }; + options.EnrichWithHttpRequest = (activity, request) => { activity.SetTag("enrichedOnStart", "yes"); }; + options.EnrichWithHttpResponse = (activity, response) => { activity.SetTag("enrichedOnStop", "yes"); }; } }) .AddInMemoryExporter(exportedItems) @@ -521,8 +521,8 @@ void ConfigureTestServices(IServiceCollection services) public async Task FilterAndEnrichAreOnlyCalledWhenSampled(SamplingDecision samplingDecision, bool shouldFilterBeCalled, bool shouldEnrichBeCalled) { bool filterCalled = false; - bool enrichOnStartCalled = false; - bool enrichOnStopCalled = false; + bool enrichWithHttpRequestCalled = false; + bool enrichWithHttpResponseCalled = false; void ConfigureTestServices(IServiceCollection services) { this.tracerProvider = Sdk.CreateTracerProviderBuilder() @@ -534,13 +534,13 @@ void ConfigureTestServices(IServiceCollection services) filterCalled = true; return true; }; - options.EnrichOnStart = (activity, request) => + options.EnrichWithHttpRequest = (activity, request) => { - enrichOnStartCalled = true; + enrichWithHttpRequestCalled = true; }; - options.EnrichOnStop = (activity, request) => + options.EnrichWithHttpResponse = (activity, request) => { - enrichOnStopCalled = true; + enrichWithHttpResponseCalled = true; }; }) .Build(); @@ -557,8 +557,8 @@ void ConfigureTestServices(IServiceCollection services) // Assert Assert.Equal(shouldFilterBeCalled, filterCalled); - Assert.Equal(shouldEnrichBeCalled, enrichOnStartCalled); - Assert.Equal(shouldEnrichBeCalled, enrichOnStopCalled); + Assert.Equal(shouldEnrichBeCalled, enrichWithHttpRequestCalled); + Assert.Equal(shouldEnrichBeCalled, enrichWithHttpResponseCalled); } [Fact] diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 0d865157778..044f9739f4c 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -264,7 +264,7 @@ public void GrpcPropagatesContextWithSuppressInstrumentationOptionSetToTrue() .AddHttpClientInstrumentation() .AddAspNetCoreInstrumentation(options => { - options.EnrichOnStart = (activity, request) => + options.EnrichWithHttpRequest = (activity, request) => { activity.SetCustomProperty("customField", request.Headers["customField"].ToString()); }; From 14d64171a89b111c58a89b42ebcf9e528e98ab51 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Oct 2022 16:35:06 -0700 Subject: [PATCH 08/13] add breaking comment --- src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 7f3885282a8..6b9612f72ae 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,8 +2,8 @@ ## Unreleased -* `Enrich` callback is now split into 3 different callbacks based on the object -that is passed in to enrich activity. The new callbacks are +* **[Breaking]** `Enrich` callback is now split into 3 different callbacks based +on the object that is passed in to enrich activity. The new callbacks are `EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException`. ([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749)) From b8b13cb70cd0af04f5b03954a7f0c3d088591b71 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Oct 2022 16:49:57 -0700 Subject: [PATCH 09/13] update public api --- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 8 ++++++-- .../.publicApi/netstandard2.1/PublicAPI.Unshipped.txt | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 07f50fb6963..6033fda11cc 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,7 +1,11 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt index a85b8064674..b3b24c45be9 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt @@ -2,8 +2,12 @@ OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.AspNetCoreInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.get -> bool OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnableGrpcAspNetCoreSupport.set -> void -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.get -> System.Action -OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Enrich.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithException.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpRequest.set -> void +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.get -> System.Action +OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.EnrichWithHttpResponse.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.get -> System.Func OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.Filter.set -> void OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions.RecordException.get -> bool From 06753cee6da06cb492e00ed6d0be9c0aac381719 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Oct 2022 22:10:36 -0700 Subject: [PATCH 10/13] update readme --- .../README.md | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md index 7df6a2adb09..9e4f704e0a0 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md @@ -120,39 +120,36 @@ and the `Filter` option does the filtering *after* the Sampler is invoked. ### Enrich -This option allows one to enrich the activity with additional information -from the raw `HttpRequest`, `HttpResponse` objects. The `Enrich` action is -called only when `activity.IsAllDataRequested` is `true`. It contains the -activity itself (which can be enriched), the name of the event, and the -actual raw object. -For event name "OnStartActivity", the actual object will be `HttpRequest`. -For event name "OnStopActivity", the actual object will be `HttpResponse` +This instrumentation library provides `EnrichWithHttpRequest`, +`EnrichWithHttpResponse` and `EnrichWithException` options that can be used to +enrich the activity with additional information from the raw `HttpRequest`, +`HttpResponse` and `Exception` objects respectively. These actions are called +only when `activity.IsAllDataRequested` is `true`. It contains the activity +itself (which can be enriched) and the actual raw object. -The following code snippet shows how to add additional tags using `Enrich`. +The following code snippet shows how to enrich the activity using all 3 +different options. ```csharp services.AddOpenTelemetryTracing((builder) => { - builder.AddAspNetCoreInstrumentation((options) => options.Enrich - = (activity, eventName, rawObject) => + builder.AddAspNetCoreInstrumentation(o => { - if (eventName.Equals("OnStartActivity")) + o.EnrichWithHttpRequest = (activity, httpRequest) => { - if (rawObject is HttpRequest httpRequest) - { - activity.SetTag("requestProtocol", httpRequest.Protocol); - } - } - else if (eventName.Equals("OnStopActivity")) + activity.SetTag("requestProtocol", httpRequest.Protocol); + }; + o.EnrichWithHttpResponse = (activity, httpResponse) => { - if (rawObject is HttpResponse httpResponse) - { - activity.SetTag("responseLength", httpResponse.ContentLength); - } - } + activity.SetTag("responseLength", httpResponse.ContentLength); + }; + o.EnrichWithException = (activity, exception) => + { + activity.RecordException(exception); + }; }) }); -``` + [Processor](../../docs/trace/extending-the-sdk/README.md#processor), is the general extensibility point to add additional properties to any activity. From fdafb9c6c48375518b40192506f7159c815a666b Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Oct 2022 22:13:16 -0700 Subject: [PATCH 11/13] fix comment --- .../AspNetCoreInstrumentationOptions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index cf0698820d1..77a4dc84ea8 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -38,7 +38,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the HttpRequest object from which additional information can be extracted to enrich the activity during request start event. + /// : the HttpRequest object from which additional information can be extracted to enrich the activity. /// public Action EnrichWithHttpRequest { get; set; } @@ -47,7 +47,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the HttpResponse object from which additional information can be extracted to enrich the activity during request stop event. + /// : the HttpResponse object from which additional information can be extracted to enrich the activity. /// public Action EnrichWithHttpResponse { get; set; } @@ -56,7 +56,7 @@ public class AspNetCoreInstrumentationOptions /// /// /// : the activity being enriched. - /// : the Exception object from which additional information can be extracted to enrich the activity on exception during request. + /// : the Exception object from which additional information can be extracted to enrich the activity. /// public Action EnrichWithException { get; set; } From a4c579d31a783ef5f6243d1ba7ef4ef059977732 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 19 Oct 2022 11:40:25 -0700 Subject: [PATCH 12/13] update readme --- .../AspNetCoreInstrumentationOptions.cs | 6 +++--- src/OpenTelemetry.Instrumentation.AspNetCore/README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 77a4dc84ea8..9c51fb5eb25 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -34,7 +34,7 @@ public class AspNetCoreInstrumentationOptions public Func Filter { get; set; } /// - /// Gets or sets an action to enrich an Activity during start event. + /// Gets or sets an action to enrich an Activity. /// /// /// : the activity being enriched. @@ -43,7 +43,7 @@ public class AspNetCoreInstrumentationOptions public Action EnrichWithHttpRequest { get; set; } /// - /// Gets or sets an action to enrich an Activity during stop event. + /// Gets or sets an action to enrich an Activity. /// /// /// : the activity being enriched. @@ -52,7 +52,7 @@ public class AspNetCoreInstrumentationOptions public Action EnrichWithHttpResponse { get; set; } /// - /// Gets or sets an action to enrich an Activity during exception event. + /// Gets or sets an action to enrich an Activity. /// /// /// : the activity being enriched. diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md index 9e4f704e0a0..5345f69d0f7 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md @@ -145,7 +145,7 @@ services.AddOpenTelemetryTracing((builder) => }; o.EnrichWithException = (activity, exception) => { - activity.RecordException(exception); + activity.SetTag("exceptionType", exception.GetType().ToString()); }; }) }); From 71e2eae6cd04ec64c5a9527fb612373d70312afc Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 20 Oct 2022 19:26:29 -0700 Subject: [PATCH 13/13] Update src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com> --- .../CHANGELOG.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 6b9612f72ae..5b3b1e04bf1 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,10 +2,16 @@ ## Unreleased -* **[Breaking]** `Enrich` callback is now split into 3 different callbacks based -on the object that is passed in to enrich activity. The new callbacks are -`EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException`. -([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749)) +* **Breaking change** The `Enrich` callback option has been removed. + For better usability, it has been replaced by three separate options: + `EnrichWithHttpRequest`, `EnrichWithHttpResponse` and `EnrichWithException`. + Previously, the single `Enrich` callback required the consumer to detect + which event triggered the callback to be invoked (e.g., request start, + response end, or an exception) and then cast the object received to the + appropriate type: `HttpRequest`, `HttpResponse`, or `Exception`. The separate + callbacks make it clear what event triggers them and there is no longer the + need to cast the argument to the expected type. + ([#3749](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3749)) * Added back `netstandard2.0` and `netstandard2.1` targets. ([#3755](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3755))