question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable Sentry on certain environments

See original GitHub issue

I want to log to Sentry only when the environment is set to production, but with this code all exceptions are logged to Sentry in any environment… What am I missing?

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseSentry(options =>
                {
                    var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

                    if (env == "Production")
                    {
                        options.Dsn = "DNS Key Here";
                        options.Environment = env;
                        options.IncludeRequestPayload = true;
                        options.IncludeActivityData = true;
                    }
                })
                .UseStartup<Startup>();

Exception

        public virtual Task<List<TEntity>> GetAllAsync()
        {
            throw new InvalidOperationException();
            return this.context.Set<TEntity>().ToListAsync();
        }

And it was logged… I tried to implement something similar with a middleware in Configure method on Startup class but with no success.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
bruno-garciacommented, Dec 7, 2018

Not setting the DSN means the SDK cannot initialize itself. Even if you did call Init or AddSentry. For ASP.NET Core and the other integration, such configuration flag exist: InitializeSdk. If you set it to false, even if the DSN is available, the integration will not attempt to initialize the SDK.

So unless you call SentrySdk.Init yourself, the SDK will be disabled.

2reactions
alesdvorakczcommented, Dec 7, 2018

Wouldn’t be good to have a configuration option, something like “Enabled”: true/false? Or is not setting DSN proper way how to disable sentry in appsettings?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environments | Sentry Documentation
Sentry automatically creates environments when it receives an event with the environment tag. Environments are case sensitive. You can also create an ...
Read more >
Environments for Browser JavaScript
Sentry automatically creates an environment when it receives an event with the environment parameter set. Environments are case sensitive. The environment name ...
Read more >
Environment | Sentry Developer Documentation
This guide steps you through configuring a local development environment for the Sentry server on macOS and Linux. If you're using another operating...
Read more >
Using Sentry.io for Local Development | Firefox Ecosystem ...
To enable sentry for local development, simply set these environment variables in your root-level .env file (that you may need to create) to...
Read more >
Configuration - Sentry Developer Documentation
This document describes configuration available to the Sentry server itself. First Install During a new install, Sentry prompts first for a walkthrough of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found