From c260d3d93720551f5f6f4773a828d193ba97baa7 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 4 Nov 2020 12:02:24 -0800 Subject: [PATCH] Doc update - adding Enrich e.g. in AspNet Readme --- .../README.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/README.md b/src/OpenTelemetry.Instrumentation.AspNet/README.md index 1ad20d0af43..6164950ca49 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/README.md @@ -102,6 +102,41 @@ instrumentation. OpenTelemetry has a concept of [Sampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling), and the `Filter` option does the filtering *before* 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` + +The following code snippet shows how to add additional tags using `Enrich`. + +```csharp +this.tracerProvider = Sdk.CreateTracerProviderBuilder() + .AddAspNetInstrumentation(opt => opt.Enrich + = (activity, eventName, rawObject) => + { + if (eventName.Equals("OnStartActivity")) + { + if (rawObject is HttpRequest httpRequest) + { + activity.SetTag("physicalPath", httpRequest.PhysicalPath); + } + } + else if (eventName.Equals("OnStopActivity")) + { + if (rawObject is HttpResponse httpResponse) + { + activity.SetTag("responseType", httpResponse.ContentType); + } + } + }) + .Build(); +``` + ### Special topic - Enriching automatically collected telemetry ASP.NET instrumentation stores the `HttpRequest`, `HttpResponse` objects in the