示例#1
0
        public void FindDsn_NoDsnInAsm_ReturnsNull()
        {
            var asm    = AssemblyCreationHelper.CreateAssembly();
            var actual = DsnLocator.FindDsn(asm);

            Assert.Null(actual);
        }
示例#2
0
        public static IDisposable Init(SentryOptions options)
        {
            options.SetupLogging();

            if (options.Dsn == null)
            {
                if (!Dsn.TryParse(DsnLocator.FindDsnStringOrDisable(), out var dsn))
                {
                    options.DiagnosticLogger?.LogWarning("Init was called but no DSN was provided nor located. Sentry SDK will be disabled.");
                    return(DisabledHub.Instance);
                }
                options.Dsn = dsn;
            }

            var hub = new Hub(options);

            // Push the first scope so the async local starts from here
            hub.PushScope();

            var oldHub = Interlocked.Exchange(ref _hub, hub);

            (oldHub as IDisposable)?.Dispose();

            return(new DisposeHandle(hub));
        }
示例#3
0
        public void FindDsn_NullDsnInAsm_ReturnsNull()
        {
            const string expected = null;

            var asm    = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(expected);
            var actual = DsnLocator.FindDsn(asm);

            Assert.Equal(expected, actual);
        }
示例#4
0
        public void FindDsn_ValidDsnInAsm_FindsTheDsnString()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            var asm    = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(expected);
            var actual = DsnLocator.FindDsn(asm);

            Assert.Equal(expected, actual);
        }
示例#5
0
 public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable());
     });
 }
示例#6
0
        public void FindDsn_InvalidDsnInAsm_ReturnsInvalidDsn()
        {
            const string expected = DsnSamples.InvalidDsn;

            var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(expected);

            // Not resposible to do validation, returns raw string
            var actual = DsnLocator.FindDsn(asm);

            Assert.Equal(expected, actual);
        }
示例#7
0
        public void FindDsnOrDisable_DsnOnEnvironmentVariable_ReturnsTheDsn()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable());
            });
        }
示例#8
0
        public void FindDsnOrDisable_DsnOnEnvironmentVariableAndAttribute_ReturnsTheDsnFromEnvironmentVariable()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(DsnSamples.ValidDsnWithSecret);
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable(asm));
            });
        }
示例#9
0
        public static IDisposable Init(SentryOptions options)
        {
            if (options.Dsn == null)
            {
                if (!Dsn.TryParse(DsnLocator.FindDsnStringOrDisable(), out var dsn))
                {
                    // TODO: Log that it continues disabled
                    return(DisabledHub.Instance);
                }
                options.Dsn = dsn;
            }

            var hub = new Hub(options);

            _hub = hub;
            return(new DisposeHandle(hub));
        }
示例#10
0
        public static IDisposable Init(SentryOptions options)
        {
            if (options.Dsn == null)
            {
                if (!Dsn.TryParse(DsnLocator.FindDsnStringOrDisable(), out var dsn))
                {
                    // TODO: Log that it continues disabled
                    return(DisabledHub.Instance);
                }
                options.Dsn = dsn;
            }

            var hub = new Hub(options);

            // Push the first scope so the async local starts from here
            hub.PushScope();

            var oldHub = Interlocked.Exchange(ref _hub, hub);

            (oldHub as IDisposable)?.Dispose();

            return(new DisposeHandle(hub));
        }
示例#11
0
 /// <summary>
 /// Initializes the SDK while attempting to locate the DSN
 /// </summary>
 /// <remarks>
 /// If the DSN is not found, the SDK will not change state.
 /// </remarks>
 public static IDisposable Init() => Init(DsnLocator.FindDsnStringOrDisable());
示例#12
0
 /// <summary>
 /// Initializes the SDK while attempting to locate the DSN
 /// </summary>
 /// <remarks>
 /// If the DSN is not found, the SDK will not change state.
 /// </remarks>
 public static void Init() => Init(DsnLocator.FindDsnStringOrDisable());