From 3d5738f5016c3bc18f96075f8455fbd7eb3e1d6a Mon Sep 17 00:00:00 2001 From: "calvin@codingwithcalvin.net" Date: Tue, 23 Dec 2025 10:47:27 -0500 Subject: [PATCH] fix: remove DI extensions (unnecessary with static API) --- CLAUDE.md | 1 - README.md | 21 ---- .../Extensions/ServiceCollectionExtensions.cs | 115 ------------------ 3 files changed, 137 deletions(-) delete mode 100644 src/CodingWithCalvin.Otel4Vsix/Extensions/ServiceCollectionExtensions.cs diff --git a/CLAUDE.md b/CLAUDE.md index 8c9a368..21f4a0a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -69,7 +69,6 @@ The library follows a static facade pattern for ease of use: - **Metrics/MetricsProvider.cs** - Manages `Meter` for counters, histograms, gauges - **Logging/LoggerProvider.cs** - Wraps `ILoggerFactory` for OpenTelemetry-integrated logging - **Exceptions/ExceptionTracker.cs** - Captures exceptions manually and via global handlers -- **Extensions/ServiceCollectionExtensions.cs** - DI integration via `AddOtel4Vsix()` ## Key Implementation Details diff --git a/README.md b/README.md index ff28fe0..75060be 100644 --- a/README.md +++ b/README.md @@ -276,27 +276,6 @@ VsixTelemetry.Initialize(config); --- -## Dependency Injection - -If your extension uses dependency injection: - -```csharp -using Otel4Vsix.Extensions; - -public void ConfigureServices(IServiceCollection services) -{ - services.AddOtel4Vsix(config => - { - config.ServiceName = "MyExtension"; - config.OtlpEndpoint = "http://localhost:4317"; - }); - - // Now ILogger is available via DI -} -``` - ---- - ## Supported Backends Otel4Vsix exports telemetry via OTLP, which is supported by: diff --git a/src/CodingWithCalvin.Otel4Vsix/Extensions/ServiceCollectionExtensions.cs b/src/CodingWithCalvin.Otel4Vsix/Extensions/ServiceCollectionExtensions.cs deleted file mode 100644 index 3c92098..0000000 --- a/src/CodingWithCalvin.Otel4Vsix/Extensions/ServiceCollectionExtensions.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Otel4Vsix.Extensions -{ - /// - /// Extension methods for configuring OpenTelemetry with Microsoft.Extensions.DependencyInjection. - /// - public static class ServiceCollectionExtensions - { - /// - /// Adds Otel4Vsix telemetry services to the service collection. - /// - /// The service collection. - /// Action to configure telemetry options. - /// The service collection for chaining. - /// Thrown when services is null. - public static IServiceCollection AddOtel4Vsix( - this IServiceCollection services, - Action configure) - { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - - var configuration = new TelemetryConfiguration(); - configure?.Invoke(configuration); - - // Initialize the static VsixTelemetry if not already done - if (!VsixTelemetry.IsInitialized) - { - VsixTelemetry.Initialize(configuration); - } - - // Register services for DI - services.AddSingleton(configuration); - services.AddSingleton(_ => VsixTelemetry.LoggerFactory); - services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); - - return services; - } - - /// - /// Adds Otel4Vsix telemetry services to the service collection with a pre-built configuration. - /// - /// The service collection. - /// The telemetry configuration. - /// The service collection for chaining. - /// Thrown when services or configuration is null. - public static IServiceCollection AddOtel4Vsix( - this IServiceCollection services, - TelemetryConfiguration configuration) - { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - // Initialize the static VsixTelemetry if not already done - if (!VsixTelemetry.IsInitialized) - { - VsixTelemetry.Initialize(configuration); - } - - // Register services for DI - services.AddSingleton(configuration); - services.AddSingleton(_ => VsixTelemetry.LoggerFactory); - services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); - - return services; - } - } - - /// - /// Generic logger implementation that wraps the VsixTelemetry logger factory. - /// - /// The type to use as the logger category. - internal sealed class Logger : ILogger - { - private readonly ILogger _innerLogger; - - /// - /// Initializes a new instance of the class. - /// - public Logger() - { - _innerLogger = VsixTelemetry.CreateLogger() ?? - Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance; - } - - /// - public IDisposable BeginScope(TState state) => _innerLogger.BeginScope(state); - - /// - public bool IsEnabled(LogLevel logLevel) => _innerLogger.IsEnabled(logLevel); - - /// - public void Log( - LogLevel logLevel, - EventId eventId, - TState state, - Exception exception, - Func formatter) - { - _innerLogger.Log(logLevel, eventId, state, exception, formatter); - } - } -}