Created
February 4, 2022 08:18
-
-
Save dcagnetta/a7d324f373544d5ec8b8bc321320c46e to your computer and use it in GitHub Desktop.
C# Configuration Extensions example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace OpenTelemetry.Trace | |
{ | |
/// <summary> | |
/// Extension methods to simplify registering of dependency instrumentation. | |
/// </summary> | |
public static class TracerProviderBuilderExtensions | |
{ | |
/// <summary> | |
/// Enables Microsoft.EntityFrameworkCore instrumentation. | |
/// </summary> | |
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param> | |
/// <param name="configureOptions">EntityFrameworkCore configuration options.</param> | |
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns> | |
public static TracerProviderBuilder AddEntityFrameworkCoreInstrumentation( | |
this TracerProviderBuilder builder, | |
Action<EntityFrameworkInstrumentationOptions> configureOptions = null) | |
{ | |
if (builder == null) | |
{ | |
throw new ArgumentNullException(nameof(builder)); | |
} | |
var options = new EntityFrameworkInstrumentationOptions(); | |
configureOptions?.Invoke(options); | |
builder.AddInstrumentation(() => new EntityFrameworkInstrumentation(options)); | |
builder.AddSource(EntityFrameworkDiagnosticListener.ActivitySourceName); | |
return builder; | |
} | |
} | |
} |
Author
dcagnetta
commented
Feb 4, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment