Exemplo n.º 1
0
        public void ResolveFromEnvironment_WithEnvironmentVariable_VersionOfEnvironmentVariable()
        {
            const string expectedVersion = "the version";

            EnvironmentVariableGuard.WithVariable(
                Sentry.Internal.Constants.ReleaseEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, ReleaseLocator.LocateFromEnvironment());
            });
        }
Exemplo n.º 2
0
        public void GetCurrent_WithEnvironmentVariable_VersionOfEnvironmentVariable()
        {
            const string expectedVersion = "the version";

            EnvironmentVariableGuard.WithVariable(
                Constants.ReleaseEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, ReleaseLocator.GetCurrent());
            });
        }
Exemplo n.º 3
0
        public void ConfigureLogging_SentryAspNetCoreOptions_ReleaseOptionsSet()
        {
            var sut   = new SentryStartup();
            var scope = new Scope(null);

            Environment.SetEnvironmentVariable("K_REVISION", "1");
            sut.ConfigureLogging(WebHostBuilderContext, LoggingBuilder);

            var provider = LoggingBuilder.Services.BuildServiceProvider();
            var option   = provider.GetRequiredService <IOptions <SentryAspNetCoreOptions> >();

            Assert.Null(option.Value.Release);
            Assert.Equal("[email protected]+1", ReleaseLocator.Resolve(option.Value));
        }
Exemplo n.º 4
0
    public void ConfigureLogging_ModifiesReleaseLocatorAndReadsKRevisionEnvVar_AppendsToRelease()
    {
        var sut = new SentryStartup();

        EnvironmentVariableGuard.WithVariable("K_REVISION", "9", () =>
        {
            sut.ConfigureLogging(WebHostBuilderContext, LoggingBuilder);

            var provider = LoggingBuilder.Services.BuildServiceProvider();
            var option   = provider.GetRequiredService <IOptions <SentryAspNetCoreOptions> >();

            Assert.Null(option.Value.Release);
            Assert.EndsWith("+9", ReleaseLocator.Resolve(option.Value));
        });
    }
Exemplo n.º 5
0
        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()
                    );
            });
Exemplo n.º 6
0
    /// <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();
    }
 public static string?GetCurrent() => GetCurrent(ReleaseLocator.GetCurrent());
Exemplo n.º 8
0
 public void GetCurrent_WithoutEnvironmentVariable_VersionOfEntryAssembly()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(Assembly.GetEntryAssembly()?.GetNameAndVersion().Version, ReleaseLocator.GetCurrent());
     });
 }