public void FindDsn_NoDsnInAsm_ReturnsNull() { var asm = AssemblyCreationHelper.CreateAssembly(); var actual = DsnLocator.FindDsn(asm); Assert.Null(actual); }
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)); }
public void FindDsn_NullDsnInAsm_ReturnsNull() { const string expected = null; var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(expected); var actual = DsnLocator.FindDsn(asm); Assert.Equal(expected, actual); }
public void FindDsn_ValidDsnInAsm_FindsTheDsnString() { const string expected = DsnSamples.ValidDsnWithoutSecret; var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(expected); var actual = DsnLocator.FindDsn(asm); Assert.Equal(expected, actual); }
public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, null, () => { Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable()); }); }
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); }
public void FindDsnOrDisable_DsnOnEnvironmentVariable_ReturnsTheDsn() { const string expected = DsnSamples.ValidDsnWithoutSecret; EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, expected, () => { Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable()); }); }
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)); }); }
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)); }
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)); }
/// <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());
/// <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());