Skip to content

Commit

Permalink
PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
PureKrome committed Oct 19, 2020
1 parent 18e825a commit 40ad2f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/Sentry.AspNetCore/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@ internal static class Constants
{
// See: https://github.com/getsentry/sentry-release-registry
public const string SdkName = "sentry.dotnet.aspnetcore";

public static string ASPNETCoreProductionEnvironmentName =>
#if NETSTANDARD2_0
"Production";
#else
Microsoft.Extensions.Hosting.Environments.Production;
#endif

public static string ASPNETCoreDevelopmentEnvironmentName =>
#if NETSTANDARD2_0
"Development";
#else
Microsoft.Extensions.Hosting.Environments.Development;
#endif
}
}
21 changes: 6 additions & 15 deletions src/Sentry.AspNetCore/SentryAspNetCoreOptionsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Options;
using Sentry.Extensions.Logging;
using Sentry.Internal;
using Microsoft.Extensions.Hosting;
#if NETSTANDARD2_0
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#else
Expand Down Expand Up @@ -45,25 +46,15 @@ public override void Configure(SentryAspNetCoreOptions options)
// Alternatively, developers might set this to a CUSTOM value, which we
// need to respect (especially the case-sensitivity).
// REF: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments
#if NETSTANDARD2_0
if (_hostingEnvironment.EnvironmentName.Equals("Production"))
{
options.Environment = Internal.Constants.DefaultEnvironmentSetting;
}
else if (_hostingEnvironment.EnvironmentName.Equals("Development"))
{
options.Environment = "development";
}
#else
if (_hostingEnvironment.EnvironmentName.Equals(Microsoft.Extensions.Hosting.Environments.Production))

if (_hostingEnvironment.EnvironmentName.Equals(Constants.ASPNETCoreProductionEnvironmentName))
{
options.Environment = Internal.Constants.DefaultEnvironmentSetting;
options.Environment = Internal.Constants.ProductionEnvironmentSetting;
}
else if (_hostingEnvironment.EnvironmentName.Equals(Microsoft.Extensions.Hosting.Environments.Development))
else if (_hostingEnvironment.EnvironmentName.Equals(Constants.ASPNETCoreDevelopmentEnvironmentName))
{
options.Environment = Microsoft.Extensions.Hosting.Environments.Development.ToLowerInvariant();
options.Environment = Internal.Constants.DevelopmentEnvironmentSetting;
}
#endif
else
{
// Use the value set by the developer.
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry/Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ internal static class Constants
/// Default Sentry environment setting.
/// </summary>
/// <remarks>Best Sentry practice is to always try and have a value for this setting.</remarks>
public const string DefaultEnvironmentSetting = "production";
public const string ProductionEnvironmentSetting = "production";

public const string DevelopmentEnvironmentSetting = "development";

// See: https://github.com/getsentry/sentry-release-registry
public const string SdkName = "sentry.dotnet";
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Internal/MainSentryEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public SentryEvent Process(SentryEvent @event)
var foundEnvironment = EnvironmentLocator.Locate();
@event.Environment = string.IsNullOrWhiteSpace(foundEnvironment)
? string.IsNullOrWhiteSpace(_options.Environment)
? Constants.DefaultEnvironmentSetting
? Constants.ProductionEnvironmentSetting
: _options.Environment
: foundEnvironment;
}
Expand Down

0 comments on commit 40ad2f5

Please sign in to comment.