Skip to content
23 changes: 19 additions & 4 deletions docs/platforms/dotnet/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,32 @@ Sets the distribution of the application. Distributions are used to disambiguate

Sets the release. The SDK will try to automatically configure a release out of the box but it's a better idea to manually set it to guarantee that the release is in sync with your deploy integrations or source map uploads. Release names are strings, but some formats are detected by Sentry and might be rendered differently. Learn more about how to send release data so Sentry can tell you about regressions between releases and identify the potential source in [the releases documentation](/product/releases/) or the <SandboxLink scenario="releases">sandbox</SandboxLink>.

By default the SDK will try to read this value from the `SENTRY_RELEASE` environment variable (in the browser SDK, this will be read off of the `window.SENTRY_RELEASE.id` if available).
If you don't set it, the SDK reads the `SENTRY_RELEASE` environment variable. If that isn't set either, the SDK uses the app package's version on Android, iOS and Mac Catalyst, and the entry assembly's version on other platforms. <PlatformLink to="/configuration/releases/#setting-a-release">Setting a Release</PlatformLink> describes the format.

<Alert title="Changed in Version 7.0.0">

In earlier versions, the release from the app package took precedence over `SENTRY_RELEASE`.

</Alert>

</SdkOption>

<SdkOption name="Environment" type="string" defaultValue="production" envVar="SENTRY_ENVIRONMENT">
<SdkOption name="Environment" type="string" envVar="SENTRY_ENVIRONMENT">

Sets the environment. This string is freeform and set by default. A release can be associated with more than one environment to separate them in the UI (think `staging` vs `prod` or similar).

By default, the SDK reports `debug` when the debugger is attached. Otherwise, the default environment is `production`.
If you don't set it in code or configuration, the SDK reads the `SENTRY_ENVIRONMENT` environment variable. If that isn't set either:

- ASP.NET Core, Blazor WebAssembly, Google Cloud Functions and .NET Generic Host apps (such as worker services) use the .NET host environment. The SDK lowercases `Production`, `Staging` and `Development` (for consistency with other Sentry SDKs), and keeps other names as they are. Set `AdjustStandardEnvironmentNameCasing` to `false` to keep the original casing.
- Other apps, such as console, MAUI and desktop apps, report `debug` when a debugger is attached, and `production` otherwise. So do ASP.NET Core and Generic Host apps that start Sentry with `SentrySdk.Init` instead of `UseSentry`.

Additionally, if you are running with the ASP.NET Core integration, you will also see the environment named as `staging`, if running in staging, or `development`, if running in development mode.
Setting `Scope.Environment` overrides the environment for everything captured with that scope: events, transactions, logs, metrics, sessions, check-ins and trace propagation. Set it to `null` to go back to the default. Sessions and traces use the environment from when they start, so changes to `Scope.Environment` don't affect a session or trace that's already running.

<Alert title="Changed in Version 7.0.0">

In earlier versions, `Scope.Environment` applied only to events and transactions.

</Alert>

</SdkOption>

Expand Down
20 changes: 20 additions & 0 deletions platform-includes/set-environment/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ options.Environment = "production";
// Add this to the SDK initialization callback
options.Environment <- "production"
```

If you don't set it, the SDK uses `SENTRY_ENVIRONMENT`, the .NET host environment or a default. The <PlatformLink to="/configuration/options/#Environment">Environment option</PlatformLink> describes the order.

To change the environment at runtime, set it on the scope:

```csharp
SentrySdk.ConfigureScope(scope => scope.Environment = "staging");
```

```fsharp
SentrySdk.ConfigureScope(fun scope -> scope.Environment <- "staging")
```

Everything captured with that scope uses this environment, including logs, metrics, sessions, check-ins and trace propagation. Sessions and traces use the environment from when they start, so changes to `Scope.Environment` don't affect a session or trace that's already running.

<Alert title="Changed in Version 7.0.0">

In earlier versions, `Scope.Environment` applied only to events and transactions.

</Alert>
2 changes: 2 additions & 0 deletions platform-includes/set-environment/dotnet.nlog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ options.Environment = "production";
// Add this to the SDK initialization callback
options.Environment <- "production"
```

If you don't set it, the SDK uses `SENTRY_ENVIRONMENT`, the .NET host environment or a default. The <PlatformLink to="/configuration/options/#Environment">Environment option</PlatformLink> describes the order.
12 changes: 11 additions & 1 deletion platform-includes/set-release/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ The SDK attempts to locate the release to attach to events sent to Sentry.

The SDK will first check if there's a version set on the environment via `SENTRY_RELEASE` and use it as-is.

If no version is found, the SDK will look at the [entry assembly's](<https://msdn.microsoft.com/en-us/library/system.reflection.assembly.getentryassembly(v=vs.110).aspx>) `AssemblyInformationalVersionAttribute`, which accepts a string value and is often used to set a GIT commit hash. If that returns null, then the SDK will look at the default `AssemblyVersionAttribute`, which accepts the numeric version number. The resulting release will be in the format `<assembly-name>@<version-number>`.
On Android, iOS and Mac Catalyst, if no version is found, the SDK uses the app package's ID, version and build number, in the format `<package-id>@<version>+<build>`.

On Android, these values are the package name, `versionName` and `versionCode`. On iOS and Mac Catalyst, they're `CFBundleIdentifier`, `CFBundleShortVersionString` and `CFBundleVersion`. The `ApplicationId`, `ApplicationDisplayVersion` and `ApplicationVersion` properties in your project file set them.

<Alert title="Changed in Version 7.0.0">

In earlier versions, the release from the app package took precedence over `SENTRY_RELEASE`.

</Alert>

On other platforms, if no version is found, the SDK will look at the [entry assembly's](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly) `AssemblyInformationalVersionAttribute`, which accepts a string value and is often used to set a GIT commit hash. If that returns null, then the SDK will look at the default `AssemblyVersionAttribute`, which accepts the numeric version number. The resulting release will be in the format `<assembly-name>@<version-number>`.

<Alert>
An `AssemblyInformationalVersionAttribute` is included automatically in SDK-style projects with a default value of `"1.0.0.0"`. You can set the `Version` property in your project file to override this value or [disable it entirely](https://learn.microsoft.com/en-us/dotnet/standard/assembly/set-attributes-project-file#use-package-properties-as-assembly-attributes) by setting the `GenerateAssemblyInformationalVersionAttribute` property to `false`.
Expand Down
7 changes: 1 addition & 6 deletions platform-includes/set-release/dotnet.nlog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,4 @@ options.Release = "my-project-name@2.3.12";
options.Release <- "my-project-name@2.3.12"
```

The SDK attempts to locate the release to add to events sent to Sentry.

The SDK will first look at the [entry assembly's](<https://msdn.microsoft.com/en-us/library/system.reflection.assembly.getentryassembly(v=vs.110).aspx>) `AssemblyInformationalVersionAttribute`, which accepts a string as
value and is often used to set a GIT commit hash.

If that returns null, it'll look at the default `AssemblyVersionAttribute` which accepts the numeric version number.
If you don't set it, the SDK uses `SENTRY_RELEASE`, the app package's version or the entry assembly's version. The <PlatformLink to="/configuration/options/#Release">Release option</PlatformLink> describes the order.
Loading