Skip to content

Commit

Permalink
Doc update - adding Enrich e.g. in AspNet Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vishweshbankwar committed Nov 4, 2020
1 parent 7c9bee3 commit c260d3d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c260d3d

Please sign in to comment.