getsentry / sentry-dotnet

@@ -3,6 +3,7 @@
Loading
3 3
using Microsoft.Extensions.Options;
4 4
using Sentry.Extensions.Logging;
5 5
using Sentry.Internal;
6 +
using Microsoft.Extensions.Hosting;
6 7
#if NETSTANDARD2_0
7 8
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
8 9
#else
@@ -25,10 +26,42 @@
Loading
25 26
        {
26 27
            base.Configure(options);
27 28
28 -
            // Don't override user defined value
29 -
            options.Environment ??=
30 -
                EnvironmentLocator.Locate() // Sentry specific environment takes precedence #92
31 -
                ?? _hostingEnvironment.EnvironmentName;
29 +
            // Don't override user defined value.
30 +
            if (string.IsNullOrWhiteSpace(options.Environment))
31 +
            {
32 +
                var locatedEnvironment = EnvironmentLocator.Locate();
33 +
                if (!string.IsNullOrWhiteSpace(locatedEnvironment))
34 +
                {
35 +
                    // Sentry specific environment takes precedence #92.
36 +
                    options.Environment = locatedEnvironment;
37 +
                }
38 +
                else
39 +
                {
40 +
                    // NOTE: Sentry prefers to have it's environment setting to be all lower case.
41 +
                    //       .NET Core sets the ENV variable to 'Production' (upper case P) or
42 +
                    //       'Development' (upper case D) which conflicts with the Sentry recommendation.
43 +
                    //       As such, we'll be kind and override those values, here ... if applicable.
44 +
                    // Assumption: The Hosting Environment is always set.
45 +
                    //             If not set by a developer, then the framework will auto set it.
46 +
                    //             Alternatively, developers might set this to a CUSTOM value, which we
47 +
                    //             need to respect (especially the case-sensitivity).
48 +
                    //             REF: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments
49 +
50 +
                    if (_hostingEnvironment.EnvironmentName.Equals(Constants.ASPNETCoreProductionEnvironmentName))
51 +
                    {
52 +
                        options.Environment = Internal.Constants.ProductionEnvironmentSetting;
53 +
                    }
54 +
                    else if (_hostingEnvironment.EnvironmentName.Equals(Constants.ASPNETCoreDevelopmentEnvironmentName))
55 +
                    {
56 +
                        options.Environment = Internal.Constants.DevelopmentEnvironmentSetting;
57 +
                    }
58 +
                    else
59 +
                    {
60 +
                        // Use the value set by the developer.
61 +
                        options.Environment = _hostingEnvironment.EnvironmentName;
62 +
                    }
63 +
                }
64 +
            }
32 65
33 66
            options.AddLogEntryFilter((category, level, eventId, exception)
34 67
                // https://github.com/aspnet/KestrelHttpServer/blob/0aff4a0440c2f393c0b98e9046a8e66e30a56cb0/src/Kestrel.Core/Internal/Infrastructure/KestrelTrace.cs#L33

@@ -4,5 +4,19 @@
Loading
4 4
    {
5 5
        // See: https://github.com/getsentry/sentry-release-registry
6 6
        public const string SdkName = "sentry.dotnet.aspnetcore";
7 +
8 +
        public static string ASPNETCoreProductionEnvironmentName =>
9 +
#if NETSTANDARD2_0
10 +
             "Production";
11 +
#else
12 +
             Microsoft.Extensions.Hosting.Environments.Production;
13 +
#endif
14 +
15 +
        public static string ASPNETCoreDevelopmentEnvironmentName =>
16 +
#if NETSTANDARD2_0
17 +
             "Development";
18 +
#else
19 +
             Microsoft.Extensions.Hosting.Environments.Development;
20 +
#endif
7 21
    }
8 22
}

@@ -143,7 +143,7 @@
Loading
143 143
                var foundEnvironment = EnvironmentLocator.Locate();
144 144
                @event.Environment = string.IsNullOrWhiteSpace(foundEnvironment)
145 145
                    ? string.IsNullOrWhiteSpace(_options.Environment)
146 -
                        ? Constants.DefaultEnvironmentSetting
146 +
                        ? Constants.ProductionEnvironmentSetting
147 147
                        : _options.Environment
148 148
                    : foundEnvironment;
149 149
            }
Files Coverage
src 85.07%
test/Sentry.Testing 91.48%
Project Totals (138 files) 85.34%
1
coverage:
2
  status:
3
    patch: false
4
    changes: false
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading