Ejemplo n.º 1
0
        public Hub(SentryOptions options)
        {
            Debug.Assert(options != null);
            _options = options;

            if (options.Dsn == null)
            {
                if (!Dsn.TryParse(DsnLocator.FindDsnStringOrDisable(), out var dsn))
                {
                    const string msg = "Attempt to instantiate a Hub without a DSN.";
                    options.DiagnosticLogger?.LogFatal(msg);
                    throw new InvalidOperationException(msg);
                }
                options.Dsn = dsn;
            }

            options.DiagnosticLogger?.LogDebug("Initializing Hub for Dsn: '{0}'.", options.Dsn);

            _ownedClient = new SentryClient(options);
            ScopeManager = new SentryScopeManager(options, _ownedClient);

            _integrations = options.Integrations;

            if (_integrations?.Length > 0)
            {
                foreach (var integration in _integrations)
                {
                    options.DiagnosticLogger?.LogDebug("Registering integration: '{0}'.", integration.GetType().Name);
                    integration.Register(this, options);
                }
            }

            // Push the first scope so the async local starts from here
            _rootScope = PushScope();
        }
Ejemplo n.º 2
0
        public static IHub FromOptions(SentryOptions options)
        {
            options.SetupLogging();

            var dsn = options.Dsn ?? DsnLocator.FindDsnStringOrDisable();

            if (Dsn.IsDisabled(dsn))
            {
                options.DiagnosticLogger?.LogWarning("Init was called but no DSN was provided nor located. Sentry SDK will be disabled.");
                return(DisabledHub.Instance);
            }

            return(new Hub(options));
        }
        public OptionalHub(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.");
                    _hub = DisabledHub.Instance;
                    return;
                }
                options.Dsn = dsn;
            }

            _hub = new Hub(options);
        }