From 27b57ea058dc75cae44d68a832b68ced10de0b83 Mon Sep 17 00:00:00 2001 From: kevinmckinley Date: Fri, 27 Nov 2020 19:26:59 -0800 Subject: [PATCH] Filter() description and code snippet clarity and consistency (#1628) * Update code snippet description and code formatting consistency * code snippet param names and tab spacing * Filter description and snippet changed for clarity * Filter description and snippet changed for clarity Co-authored-by: Cijo Thomas --- .../README.md | 27 +++++++-------- .../README.md | 34 +++++++++---------- .../README.md | 21 ++++++------ 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNet/README.md b/src/OpenTelemetry.Instrumentation.AspNet/README.md index 215c15b67a0..4448f1c78db 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/README.md @@ -76,29 +76,28 @@ This instrumentation can be configured to change the default behavior by using ### Filter This instrumentation by default collects all the incoming http requests. It allows -filtering of requests by using `Filter` function in `AspNetInstrumentationOptions`. -This can be used to filter out any requests based on some condition. The Filter -receives the `HttpContext` of the incoming request, and filters out the request -if the Filter returns false or throws exception. +filtering of requests by using the `Filter` function in `AspNetInstrumentationOptions`. +This defines the condition for allowable requests. The Filter +receives the `HttpContext` of the incoming request, and does not collect telemetry + about the request if the Filter returns false or throws exception. -The following shows an example of `Filter` being used to filter out all POST requests. +The following code snippet shows how to use `Filter` to only allow GET +requests. ```csharp this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAspNetInstrumentation( - (options) => - { - options.Filter = (httpContext) => + (options) => options.Filter = + (httpContext) => { - // filter out all HTTP POST requests. - return !httpContext.Request.HttpMethod.Equals("POST"); - }; - }) + // only collect telemetry about HTTP GET requests + return httpContext.Request.HttpMethod.Equals("GET"); + }) .Build(); ``` It is important to note that this `Filter` option is specific to this -instrumentation. OpenTelemetry has a concept of +instrumentation. OpenTelemetry has a concept of a [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. @@ -116,7 +115,7 @@ The following code snippet shows how to add additional tags using `Enrich`. ```csharp this.tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddAspNetInstrumentation(opt => opt.Enrich + .AddAspNetInstrumentation((options) => options.Enrich = (activity, eventName, rawObject) => { if (eventName.Equals("OnStartActivity")) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md index 51fdba53c58..2eb9f743db3 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/README.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/README.md @@ -45,9 +45,9 @@ public void ConfigureServices(IServiceCollection services) { services.AddOpenTelemetryTracing( (builder) => builder - .AddAspNetCoreInstrumentation() - .AddJaegerExporter() - ); + .AddAspNetCoreInstrumentation() + .AddJaegerExporter() + ); } ``` @@ -60,31 +60,31 @@ This instrumentation can be configured to change the default behavior by using ### Filter This instrumentation by default collects all the incoming http requests. It -allows filtering of requests by using `Filter` function in +allows filtering of requests by using the `Filter` function in `AspNetCoreInstrumentationOptions`. This defines the condition for allowable requests. The Filter receives the `HttpContext` of the incoming request, and does not collect telemetry about the request if the Filter returns false or throws exception. -The following code snippet shows how to use `Filter` to filter out all POST +The following code snippet shows how to use `Filter` to only allow GET requests. ```csharp services.AddOpenTelemetryTracing( - (builder) => builder - .AddAspNetCoreInstrumentation( - opt => opt.Filter = - (httpContext) => - { - // only collect telemetry about HTTP GET requests - return httpContext.Request.Method.Equals("GET"); - }) - .AddJaegerExporter() - ); + (builder) => builder + .AddAspNetCoreInstrumentation( + (options) => options.Filter = + (httpContext) => + { + // only collect telemetry about HTTP GET requests + return httpContext.Request.Method.Equals("GET"); + }) + .AddJaegerExporter() + ); ``` It is important to note that this `Filter` option is specific to this -instrumentation. OpenTelemetry has a concept of +instrumentation. OpenTelemetry has a concept of a [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. @@ -104,7 +104,7 @@ The following code snippet shows how to add additional tags using `Enrich`. services.AddOpenTelemetryTracing((builder) => { builder - .AddAspNetCoreInstrumentation(opt => opt.Enrich + .AddAspNetCoreInstrumentation((options) => options.Enrich = (activity, eventName, rawObject) => { if (eventName.Equals("OnStartActivity")) diff --git a/src/OpenTelemetry.Instrumentation.Http/README.md b/src/OpenTelemetry.Instrumentation.Http/README.md index c18c576e0d0..f8ca15da1ec 100644 --- a/src/OpenTelemetry.Instrumentation.Http/README.md +++ b/src/OpenTelemetry.Instrumentation.Http/README.md @@ -72,7 +72,7 @@ The following example shows how to use `SetHttpFlavor`. ```csharp using Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation( - options => options.SetHttpFlavor = true) + (options) => options.SetHttpFlavor = true) .AddConsoleExporter() .Build(); ``` @@ -81,22 +81,23 @@ using Sdk.CreateTracerProviderBuilder() This instrumentation by default collects all the outgoing HTTP requests. It allows filtering of requests by using the `Filter` function option. -This can be used to filter out any requests based on some condition. The Filter +This defines the condition for allowable requests. The Filter receives the request object - `HttpRequestMessage` for .NET Core and -`HttpWebRequest` for .NET Framework - of the outgoing request and filters out -the request if the Filter returns false or throws an exception. +`HttpWebRequest` for .NET Framework - of the outgoing request and does not +collect telemetry about the request if the Filter returns false or throws +exception. -The following shows an example of `Filter` being used to filter out all POST +The following code snippet shows how to use `Filter` to only allow GET requests. ```csharp using Sdk.CreateTracerProviderBuilder() .AddHttpClientInstrumentation( - options => options.Filter = - httpRequestMessage => + (options) => options.Filter = + (httpRequestMessage) => { - // filter out all HTTP POST requests. - return httpRequestMessage.Method != HttpMethod.Post; + // only collect telemetry about HTTP GET requests + return httpRequestMessage.Method.Equals(HttpMethod.Get); }) .AddConsoleExporter() .Build(); @@ -143,7 +144,7 @@ The following code snippet shows how to add additional tags using `Enrich`. services.AddOpenTelemetryTracing((builder) => { builder - .AddHttpClientInstrumentation(opt => opt.Enrich + .AddHttpClientInstrumentation((options) => options.Enrich = (activity, eventName, rawObject) => { if (eventName.Equals("OnStartActivity"))