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
| public class RequestsMeter | |
| { | |
| private static readonly Meter s_meter = new Meter("MyCompany.MyApp.Requests", "1.0.0"); | |
| private static readonly Counter<long> s_requestCounter = | |
| s_meter.CreateCounter<long>("request-count", description: "Total number of requests"); | |
| private static readonly ObservableGauge<int> s_queueLengthGauge = | |
| s_meter.CreateObservableGauge("queue-length", | |
| () => GetQueueLength(), |
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
| using Microsoft.Extensions.DependencyInjection; | |
| using Microsoft.Extensions.Hosting; | |
| using OpenTelemetry.Metrics; | |
| var builder= Host.CreateDefaultBuilder(args); | |
| builder.ConfigureServices(s => | |
| { | |
| s.AddOpenTelemetry() | |
| .WithMetrics(metrics => |
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
| public class RequestsMeter | |
| { | |
| private static readonly Meter _meter = new Meter("MyCompany.MyApp", "1.0.0"); | |
| private static readonly Counter<long> _requestCounter = | |
| s_meter.CreateCounter<long>("request-count", description: "Total number of requests"); | |
| private static readonly ObservableGauge<int> _queueLengthGauge = | |
| s_meter.CreateObservableGauge("queue-length", | |
| () => GetQueueLength(), |
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
| // Before: EventSource | |
| [EventSource(Name = "MyCompany.MyApp.Requests")] | |
| public sealed class RequestEventSource : EventSource | |
| { | |
| // ... | |
| } | |
| // After: Meter | |
| private static readonly Meter _meter = new ( | |
| "MyCompany.MyApp.Requests", |
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
| [EventSource(Name = "MyCompany.MyApp")] | |
| public sealed class MyEventSource : EventSource | |
| { | |
| public static readonly MyEventSource Log = new MyEventSource(); | |
| private EventCounter _requestCounter; | |
| private PollingCounter _queueLengthCounter; | |
| private MyEventSource() | |
| { |
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
| <ItemGroup> | |
| <!-- Explicitly reference the fixed version --> | |
| <PackageReference Include="VulnerablePackage" Version="2.0.0" /> | |
| </ItemGroup> |
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
| <!-- Only audit direct dependencies --> | |
| <PropertyGroup> | |
| <NuGetAuditMode>direct</NuGetAuditMode> | |
| </PropertyGroup> | |
| <!-- Disable auditing entirely (not recommended) --> | |
| <PropertyGroup> | |
| <NuGetAudit>false</NuGetAudit> | |
| </PropertyGroup> |
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
| private readonly Lock _lock = new(); | |
| public override void Initialize(IServiceCollection services) | |
| { | |
| foreach (var database in _configuration.DatabaseConfigurations) | |
| { | |
| lock (_lock) | |
| ConfigurationMappings.DbContextTypes[database.Key] = _configuration.DbContextTypes[database.Key]; | |
| } | |
| } |
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
| foreach (var database in _configuration.DatabaseConfigurations) | |
| { | |
| database.Value(services); | |
| // Register a mapping from the database key to the DbContext type | |
| ConfigurationMappings.DbContextTypes[database.Key]= _configuration.DbContextTypes[database.Key]; | |
| } |
NewerOlder