зеркало из https://github.com/microsoft/Omex.git
Enabled options to disable Omex telemetry via config (#614)
* Enabled options to disable Omex telemetry via config. * Removed options from OmexLoggerProvider. * Fixed OmexLoggerProvider. * Fixed Logging. * Configure logging correctly. * Fixed spellings. * Fixed tests.
This commit is contained in:
Родитель
712c919c1c
Коммит
46d4affdfd
|
@ -12,6 +12,7 @@
|
|||
<PackageTags>Microsoft;Omex;Extensions;Activities</PackageTags>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" />
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Microsoft.Omex.Extensions.Activities
|
|||
/// <summary>
|
||||
/// Monitoring option
|
||||
/// </summary>
|
||||
public class ActivityOption
|
||||
internal class ActivityOption
|
||||
{
|
||||
/// <summary>
|
||||
/// Path to the setting
|
||||
|
|
|
@ -45,7 +45,8 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
serviceCollection
|
||||
.AddOptions<ActivityOption>()
|
||||
.BindConfiguration(ActivityOption.MonitoringPath)
|
||||
.ValidateDataAnnotations();
|
||||
.ValidateDataAnnotations()
|
||||
.ValidateOnStart();
|
||||
|
||||
serviceCollection.TryAddSingleton<IActivityListenerConfigurator, DefaultActivityListenerConfigurator>();
|
||||
serviceCollection.TryAddSingleton(p => new ActivitySource(ActivitySourceName, ActivitySourceVersion));
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services
|
|||
options.ValidateOnBuild = true;
|
||||
options.ValidateScopes = true;
|
||||
})
|
||||
.ConfigureLogging(builder => builder.AddOmexLogging())
|
||||
.Build();
|
||||
|
||||
InitializationLogger.LogInitializationSucceed(serviceNameForLogging);
|
||||
|
|
|
@ -8,6 +8,7 @@ using Microsoft.Omex.Extensions.Logging.Scrubbing;
|
|||
|
||||
namespace Microsoft.Omex.Extensions.Logging
|
||||
{
|
||||
[ProviderAlias("Omex")]
|
||||
internal class OmexLoggerProvider : ILoggerProvider, ISupportExternalScope
|
||||
{
|
||||
public OmexLoggerProvider(
|
||||
|
@ -18,8 +19,8 @@ namespace Microsoft.Omex.Extensions.Logging
|
|||
{
|
||||
m_logsEventSender = logsEventSender;
|
||||
m_defaultExternalScopeProvider = defaultExternalScopeProvider;
|
||||
m_replayer = replayer;
|
||||
m_textScrubbers = textScrubbers;
|
||||
m_replayer = replayer;
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName) =>
|
||||
|
@ -30,9 +31,10 @@ namespace Microsoft.Omex.Extensions.Logging
|
|||
public void SetScopeProvider(IExternalScopeProvider scopeProvider) => m_externalScopeProvider = scopeProvider;
|
||||
|
||||
private IExternalScopeProvider? m_externalScopeProvider;
|
||||
|
||||
private readonly ILogEventSender m_logsEventSender;
|
||||
private readonly IExternalScopeProvider m_defaultExternalScopeProvider;
|
||||
private readonly IEnumerable<ILogScrubbingRule> m_textScrubbers;
|
||||
private readonly ILogEventReplayer? m_replayer;
|
||||
private readonly ILogEventSender m_logsEventSender;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Microsoft.Omex.Extensions.Logging
|
|||
/// <summary>
|
||||
/// Options for Omex logger
|
||||
/// </summary>
|
||||
public class OmexLoggingOptions
|
||||
internal class OmexLoggingOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Should logs wrapped by the Activity be stored and replayed at a higher severity, in the event of an error.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Configuration;
|
||||
using Microsoft.Omex.Extensions.Abstractions.Activities.Processing;
|
||||
using Microsoft.Omex.Extensions.Abstractions.ExecutionContext;
|
||||
using Microsoft.Omex.Extensions.Logging.Replayable;
|
||||
|
@ -31,6 +32,7 @@ namespace Microsoft.Omex.Extensions.Logging
|
|||
/// <param name="builder">The extension method argument</param>
|
||||
public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder)
|
||||
{
|
||||
builder.AddConfiguration();
|
||||
builder.Services.AddOmexLogging();
|
||||
return builder;
|
||||
}
|
||||
|
|
|
@ -32,11 +32,10 @@ namespace Microsoft.Omex.Extensions.Activities.UnitTests
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddOmexActivitySource_HostedServicesRegiestered()
|
||||
public void AddOmexActivitySource_HostedServicesRegistered()
|
||||
{
|
||||
Type[] types = GetRegisteredServices<IHostedService>();
|
||||
|
||||
Assert.AreEqual(2, types.Length);
|
||||
CollectionAssert.Contains(types, typeof(ActivityListenerInitializerService));
|
||||
CollectionAssert.Contains(types, typeof(DiagnosticsObserversInitializer));
|
||||
}
|
||||
|
@ -47,7 +46,7 @@ namespace Microsoft.Omex.Extensions.Activities.UnitTests
|
|||
Task task = CreateHost().RunAsync();
|
||||
|
||||
Activity? activity = new ActivitySource("Source")
|
||||
.StartActivity(nameof(AddOmexActivitySource_HostedServicesRegiestered));
|
||||
.StartActivity(nameof(AddOmexActivitySource_HostedServicesRegistered));
|
||||
|
||||
NullableAssert.IsNotNull(activity, "Activity creation enabled after host started");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.UnitTests
|
|||
[DataRow(typeof(IExecutionContext), typeof(ServiceFabricExecutionContext))]
|
||||
[DataRow(typeof(ActivitySource), null)]
|
||||
[DataRow(typeof(ILogger<HostBuilderExtensionsTests>), null)]
|
||||
public void AddOmexServiceFabricDependencies_TypesRegistered(Type typeToResolver, Type? expectedImplementationType)
|
||||
public void AddOmexServiceFabricDependencies_TypesRegistered(Type typeToResolve, Type? expectedImplementationType)
|
||||
{
|
||||
void CheckTypeRegistration<TContext>() where TContext : ServiceContext
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.UnitTests
|
|||
.AddOmexServiceFabricDependencies<TContext>()
|
||||
.AddSingleton(new Mock<IHostEnvironment>().Object)
|
||||
.BuildServiceProvider()
|
||||
.GetService(typeToResolver);
|
||||
.GetService(typeToResolve);
|
||||
|
||||
Assert.IsNotNull(obj, "Failed to resolve for {0}", typeof(TContext));
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче