public void ResolveFromEnvironment_WithEnvironmentVariable_VersionOfEnvironmentVariable() { const string expectedVersion = "the version"; EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, expectedVersion, () => { Assert.Equal(expectedVersion, ReleaseLocator.LocateFromEnvironment()); }); }
public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly() { var ass = Assembly.GetEntryAssembly(); #if NET461 Skip.If(ass == null, "GetEntryAssembly can return null on net461. eg on Mono or in certain test runners."); #endif EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, null, () => { Assert.Equal( $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}", ReleaseLocator.LocateFromEnvironment()); });
public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly() { #if NET461 Skip.If(Runtime.Current.IsMono(), "GetEntryAssembly returning null on Mono."); #endif var ass = Assembly.GetEntryAssembly(); EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, null, () => { Assert.Equal( $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}", ReleaseLocator.LocateFromEnvironment() ); });
/// <summary> /// Configure Sentry logging. /// </summary> public override void ConfigureLogging(WebHostBuilderContext context, ILoggingBuilder logging) { base.ConfigureLogging(context, logging); logging.AddConfiguration(context.Configuration); logging.Services.AddSingleton <ISentryEventProcessor, SentryGoogleCloudFunctionEventProcessor>(); ReleaseLocator.FromEnvironmentLazy = new Lazy <string?>(() => { var environmentRelease = ReleaseLocator.LocateFromEnvironment(); if (environmentRelease != null && Environment.GetEnvironmentVariable("K_REVISION") is { } revision) { environmentRelease = $"{environmentRelease}+{revision}"; } return(environmentRelease); }); // TODO: refactor this with SentryWebHostBuilderExtensions var section = context.Configuration.GetSection("Sentry"); logging.Services.Configure <SentryAspNetCoreOptions>(section); logging.Services.Configure <SentryAspNetCoreOptions>(options => { // Make sure all events are flushed out options.FlushBeforeRequestCompleted = true; // K_SERVICE is where the name of the FAAS is stored. // It'll return null. if GCP Function is running locally. var serviceName = Environment.GetEnvironmentVariable("K_SERVICE"); options.TransactionNameProvider = _ => serviceName; }); logging.Services.AddSingleton <IConfigureOptions <SentryAspNetCoreOptions>, SentryAspNetCoreOptionsSetup>(); logging.Services.AddSingleton <ILoggerProvider, SentryAspNetCoreLoggerProvider>(); logging.AddFilter <SentryAspNetCoreLoggerProvider>( "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware", LogLevel.None); logging.Services.AddSentry(); }