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