-
Notifications
You must be signed in to change notification settings - Fork 862
[SqlClient] Add support for Filter expression #3743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,37 @@ using var tracerProvider = Sdk.CreateTracerProviderBuilder() | |
| .Build(); | ||
| ``` | ||
|
|
||
| ## Filter | ||
|
|
||
| This option allows to filter out activities based on the properties of the | ||
| `SqlCommand` object being instrumented using a `Func<object, bool>`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.AspNetCore#filter the wording here is slightly better. Not blocking. There are plans to change the return type from bool to more easy-to-use Enums like DropActivity, ReportActivity etc, soon. |
||
| The function receives an instance of the raw `SqlCommand` and should return | ||
| `true` if the telemetry is to be collected, and `false` if it should not. | ||
| The parameter of the Func delegate is of type `object` and needs to | ||
| be cast to the appropriate type of `SqlCommand`, either | ||
| `Microsoft.Data.SqlClient.SqlCommand` or `System.Data.SqlClient.SqlCommand`. | ||
| The example below filters out all commands that are not stored procedures. | ||
|
|
||
Driedas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ```csharp | ||
| using var traceProvider = Sdk.CreateTracerProviderBuilder() | ||
| .AddSqlClientInstrumentation( | ||
| opt => | ||
| { | ||
| opt.Filter = cmd => | ||
| { | ||
| if (cmd is SqlCommand command) | ||
| { | ||
| return command.CommandType == CommandType.StoredProcedure; | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
| }) | ||
| .AddConsoleExporter() | ||
| .Build(); | ||
| { | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| * [OpenTelemetry Project](https://opentelemetry.io/) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.