Skip to content

fix: populate sentry.sdk.name and sentry.sdk.version for console apps - #5483

Merged
jamescrosswell merged 3 commits into
getsentry:mainfrom
zkasuran:fix/sdkversion-empty-for-console
Aug 19, 2026
Merged

fix: populate sentry.sdk.name and sentry.sdk.version for console apps#5483
jamescrosswell merged 3 commits into
getsentry:mainfrom
zkasuran:fix/sdkversion-empty-for-console

Conversation

@zkasuran

Copy link
Copy Markdown
Contributor

Closes #5352

What changed and why

Structured logs and trace metrics from a plain console app were going out with no
sentry.sdk.name and no sentry.sdk.version attribute. The same code under
ASP.NET Core was fine. These attributes identify the SDK that produced the data, so
a whole class of apps was shipping logs and metrics that could not be attributed to
the .NET SDK.

Root cause: SentryAttributes.SetDefaultAttributes reads the SDK fields off the
SdkVersion it is handed:

if (sdk.Name is { } name)       { SetAttribute("sentry.sdk.name", name); }
if (sdk.Version is { } version) { SetAttribute("sentry.sdk.version", version); }

On the logs path (SentryLog.cs:153) and the metrics path
(SentryMetric.Factory.cs:23) the value passed in is scope.Sdk. Both sites try to
fall back with ?? SdkVersion.Instance, but that fallback is dead: Scope.Sdk is a
non-null auto-initialized property (Scope.cs:277, public SdkVersion Sdk { get; } = new();),
so scope?.Sdk ?? SdkVersion.Instance always resolves to scope.Sdk. In a console
app nothing populates that object, so Name and Version stay null and both guards
above are false. Framework integrations do not hit this: ASP.NET Core fills
scope.Sdk in SentryMiddleware.cs:257-258, so its logs carry the attributes.

The fix falls back per field to the populated SdkVersion.Instance at the one place
both paths share:

if ((sdk.Name ?? SdkVersion.Instance.Name) is { } name)
{
    SetAttribute("sentry.sdk.name", name);
}
if ((sdk.Version ?? SdkVersion.Instance.Version) is { } version)
{
    SetAttribute("sentry.sdk.version", version);
}

When an integration has already set scope.Sdk.Name, that value is non-null so the
?? short circuits and the integration still wins. The fallback only supplies a
value where the field would otherwise be null. SdkVersion.Instance is the same
object the envelope header uses, so logs and metrics now agree with the envelope.

Tests

  • New: SentryLogTests.SetDefaultAttributes_EmptyScopeSdk_UsesSdkInstance builds a
    log with a fresh new Scope(options) (the console case) and asserts
    sentry.sdk.name == "sentry.dotnet" with a non-empty sentry.sdk.version.
  • New: SentryMetricTests.SetDefaultAttributes_EmptySdk_UsesSdkInstance does the
    same for a metric built with new SdkVersion().
  • Updated: SentryLogTests.WriteTo_Envelope_MinimalSerializedSentryLog and
    SentryMetricTests.WriteTo_Envelope_MinimalSerializedSentryMetric were pinning the
    old payload with no SDK attributes. They now include the SDK name and version,
    which is the correct serialized form after the fix.

The existing Protocol_Default_VerifyAttributes tests never caught this because they
pre-populate the Sdk before calling SetDefaultAttributes.

Verification

Verified locally in Docker (mcr.microsoft.com/dotnet/sdk:10.0.302, the exact SDK
pinned by global.json, host runs net10.0):

dotnet test test/Sentry.Tests/Sentry.Tests.csproj -f net10.0
  • With the fix: Failed: 0, Passed: 2533, Skipped: 5, Total: 2538.
  • Reverting only SentryAttributes.cs while keeping the tests: Failed: 4, Passed: 2529.
    The four failures are the two new tests plus the two corrected serialization tests,
    which reproduces the bug.
  • dotnet format --verify-no-changes on the changed files: no changes.

Changelog

The commit and this PR lead with fix:, so craft categorizes it under Fixes at
release time. Per CONTRIBUTING.md I have not edited CHANGELOG.md by hand. Let me
know if you want a custom ### Changelog Entry with more detail than the title.

AI disclosure

AI assistance (Claude, Anthropic) was used to trace the root cause, write the fix and
the tests, then run the suite. I own the change, reviewed it and verified it locally
before submitting. Verified: the full Sentry.Tests suite on net10.0 (2533 passing,
0 failing); the bug reproduced by reverting only the source file (4 failing);
dotnet format --verify-no-changes clean on the changed files.

Co-Authored-By: Claude (Anthropic) <noreply@anthropic.com>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Aug 13, 2026
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.75%. Comparing base (3fe027d) to head (9e08135).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5483      +/-   ##
==========================================
+ Coverage   74.73%   74.75%   +0.01%     
==========================================
  Files         513      513              
  Lines       18744    18749       +5     
  Branches     3666     3667       +1     
==========================================
+ Hits        14009    14015       +6     
+ Misses       3863     3862       -1     
  Partials      872      872              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zkasuran - generally this looks good. I've made a couple of minor suggestions... just for housekeeping.

Comment thread src/Sentry/Protocol/SentryAttributes.cs
Comment thread test/Sentry.Tests/SentryLogTests.cs Outdated
Comment thread test/Sentry.Tests/SentryMetricTests.cs Outdated
Address review feedback on getsentry#5483: move sentry.sdk.name and
sentry.sdk.version as a unit so they never come from different sources
(matching Enricher and Scope) and assert Constants.SdkName in the
regression tests.

Co-Authored-By: Claude (Anthropic) <noreply@anthropic.com>
@zkasuran

Copy link
Copy Markdown
Contributor Author

Thanks for the review @jamescrosswell. Both points are addressed in 8bba369. SetDefaultAttributes now moves the SDK name and version together (the scope's pair when set, otherwise Constants.SdkName with SdkVersion.Instance.Version) so they follow the same both-or-neither pattern as Enricher and Scope. The two regression tests now assert Constants.SdkName for the name.

Verified locally in Docker (mcr.microsoft.com/dotnet/sdk:10.0.302): dotnet test test/Sentry.Tests/Sentry.Tests.csproj -f net10.0 passes (0 failed, 2533 passed, 5 skipped) and dotnet format --verify-no-changes is clean on the changed files.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8bba369. Configure here.

Comment thread src/Sentry/Protocol/SentryAttributes.cs Outdated
Address the review feedback and Bugbot finding on getsentry#5483. The previous
else-if fired whenever either Name or Version was null, so an integration
that sets Name but leaves Version null (its GetVersion() can return null)
had its name relabelled to the default SDK name. The default now applies
only when both fields are unset, matching the both-or-neither intent.
Name and version are set independently after that. Adds a regression test
on the log and metric paths for the name-only case.

Co-Authored-By: Claude (Anthropic) <noreply@anthropic.com>

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - thanks for the contribution @zkasuran ! 🙏🏻

@jamescrosswell
jamescrosswell merged commit 4831f0e into getsentry:main Aug 19, 2026
46 checks passed
plz12345 added a commit to Whisparr/Whisparr-Eros that referenced this pull request Sep 4, 2026
Updated
[Selenium.WebDriver.ChromeDriver](https://github.com/jsakamoto/nupkg-selenium-webdriver-chromedriver/)
from 152.0.7977.7500 to 152.0.7977.8200.

<details>
<summary>Release notes</summary>

_Sourced from [Selenium.WebDriver.ChromeDriver's
releases](https://github.com/jsakamoto/nupkg-selenium-webdriver-chromedriver//releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/jsakamoto/nupkg-selenium-webdriver-chromedriver//commits).
</details>

Updated [Sentry](https://github.com/getsentry/sentry-dotnet) from 6.9.0
to 6.10.0.

<details>
<summary>Release notes</summary>

_Sourced from [Sentry's
releases](https://github.com/getsentry/sentry-dotnet/releases)._

## 6.10.0

### Features ✨

- feat: Logs sent via `SentrySdk.Logger` no longer require `EnableLogs`
by @​jamescrosswell in
[#​5512](getsentry/sentry-dotnet#5512)
- feat: `SentryOptions.EnableMetrics` is obsolete and ignored by
@​jamescrosswell in
[#​5509](getsentry/sentry-dotnet#5509)

### Fixes 🐛

- fix: Prevent managed exceptions from leaking as NSExceptions,
resulting in duplicate exception capture on iOS by @​jpnurmi in
[#​5525](getsentry/sentry-dotnet#5525)
- fix(profiling): release the EventPipe session when the SDK shuts down
by @​jamescrosswell in
[#​5470](getsentry/sentry-dotnet#5470)
- fix: Memory leak in Sentry.Profiling due to EventLog interning tables
growing indefinitely by @​jamescrosswell in
[#​5503](getsentry/sentry-dotnet#5503)
- fix: Attachments not being sent properly when Spotlight is enabled by
@​XAN9xXx in
[#​5511](getsentry/sentry-dotnet#5511)
- fix: Heap dump files are now deleted from disk once they have been
sent to Sentry by @​XAN9xXx in
[#​5481](getsentry/sentry-dotnet#5481)
- fix: populate sentry.sdk.name and sentry.sdk.version for console apps
by @​zkasuran in
[#​5483](getsentry/sentry-dotnet#5483)

### Dependencies ⬆️

#### Deps

- chore(deps): update Java SDK to v8.54.0 by @​github-actions in
[#​5517](getsentry/sentry-dotnet#5517)
- chore(deps): update Cocoa SDK to v9.26.1 by @​github-actions in
[#​5516](getsentry/sentry-dotnet#5516)
- chore(deps): update CLI to v3.7.0 by @​github-actions in
[#​5520](getsentry/sentry-dotnet#5520)
- chore(deps): update Native SDK to v0.16.4 by @​github-actions in
[#​5508](getsentry/sentry-dotnet#5508)
- chore(deps): update Java SDK to v8.53.0 by @​github-actions in
[#​5484](getsentry/sentry-dotnet#5484)

### Other

- deps: update perfview (removes the .il suffix from profile module
names) by @​jamescrosswell in
[#​5502](getsentry/sentry-dotnet#5502)

Commits viewable in [compare
view](getsentry/sentry-dotnet@6.9.0...6.10.0).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>
This was referenced Sep 7, 2026
gunndabad pushed a commit to DFE-Digital/teaching-record-system that referenced this pull request Sep 9, 2026
Pinned [Sentry.AspNetCore](https://github.com/getsentry/sentry-dotnet)
at 6.10.0.

<details>
<summary>Release notes</summary>

_Sourced from [Sentry.AspNetCore's
releases](https://github.com/getsentry/sentry-dotnet/releases)._

## 6.10.0

### Features ✨

- feat: Logs sent via `SentrySdk.Logger` no longer require `EnableLogs`
by @​jamescrosswell in
[#​5512](getsentry/sentry-dotnet#5512)
- feat: `SentryOptions.EnableMetrics` is obsolete and ignored by
@​jamescrosswell in
[#​5509](getsentry/sentry-dotnet#5509)

### Fixes 🐛

- fix: Prevent managed exceptions from leaking as NSExceptions,
resulting in duplicate exception capture on iOS by @​jpnurmi in
[#​5525](getsentry/sentry-dotnet#5525)
- fix(profiling): release the EventPipe session when the SDK shuts down
by @​jamescrosswell in
[#​5470](getsentry/sentry-dotnet#5470)
- fix: Memory leak in Sentry.Profiling due to EventLog interning tables
growing indefinitely by @​jamescrosswell in
[#​5503](getsentry/sentry-dotnet#5503)
- fix: Attachments not being sent properly when Spotlight is enabled by
@​XAN9xXx in
[#​5511](getsentry/sentry-dotnet#5511)
- fix: Heap dump files are now deleted from disk once they have been
sent to Sentry by @​XAN9xXx in
[#​5481](getsentry/sentry-dotnet#5481)
- fix: populate sentry.sdk.name and sentry.sdk.version for console apps
by @​zkasuran in
[#​5483](getsentry/sentry-dotnet#5483)

### Dependencies ⬆️

#### Deps

- chore(deps): update Java SDK to v8.54.0 by @​github-actions in
[#​5517](getsentry/sentry-dotnet#5517)
- chore(deps): update Cocoa SDK to v9.26.1 by @​github-actions in
[#​5516](getsentry/sentry-dotnet#5516)
- chore(deps): update CLI to v3.7.0 by @​github-actions in
[#​5520](getsentry/sentry-dotnet#5520)
- chore(deps): update Native SDK to v0.16.4 by @​github-actions in
[#​5508](getsentry/sentry-dotnet#5508)
- chore(deps): update Java SDK to v8.53.0 by @​github-actions in
[#​5484](getsentry/sentry-dotnet#5484)

### Other

- deps: update perfview (removes the .il suffix from profile module
names) by @​jamescrosswell in
[#​5502](getsentry/sentry-dotnet#5502)

Commits viewable in [compare
view](getsentry/sentry-dotnet@6.9.0...6.10.0).
</details>

Updated
[Sentry.Extensions.Logging](https://github.com/getsentry/sentry-dotnet)
from 6.9.0 to 6.10.0.

<details>
<summary>Release notes</summary>

_Sourced from [Sentry.Extensions.Logging's
releases](https://github.com/getsentry/sentry-dotnet/releases)._

## 6.10.0

### Features ✨

- feat: Logs sent via `SentrySdk.Logger` no longer require `EnableLogs`
by @​jamescrosswell in
[#​5512](getsentry/sentry-dotnet#5512)
- feat: `SentryOptions.EnableMetrics` is obsolete and ignored by
@​jamescrosswell in
[#​5509](getsentry/sentry-dotnet#5509)

### Fixes 🐛

- fix: Prevent managed exceptions from leaking as NSExceptions,
resulting in duplicate exception capture on iOS by @​jpnurmi in
[#​5525](getsentry/sentry-dotnet#5525)
- fix(profiling): release the EventPipe session when the SDK shuts down
by @​jamescrosswell in
[#​5470](getsentry/sentry-dotnet#5470)
- fix: Memory leak in Sentry.Profiling due to EventLog interning tables
growing indefinitely by @​jamescrosswell in
[#​5503](getsentry/sentry-dotnet#5503)
- fix: Attachments not being sent properly when Spotlight is enabled by
@​XAN9xXx in
[#​5511](getsentry/sentry-dotnet#5511)
- fix: Heap dump files are now deleted from disk once they have been
sent to Sentry by @​XAN9xXx in
[#​5481](getsentry/sentry-dotnet#5481)
- fix: populate sentry.sdk.name and sentry.sdk.version for console apps
by @​zkasuran in
[#​5483](getsentry/sentry-dotnet#5483)

### Dependencies ⬆️

#### Deps

- chore(deps): update Java SDK to v8.54.0 by @​github-actions in
[#​5517](getsentry/sentry-dotnet#5517)
- chore(deps): update Cocoa SDK to v9.26.1 by @​github-actions in
[#​5516](getsentry/sentry-dotnet#5516)
- chore(deps): update CLI to v3.7.0 by @​github-actions in
[#​5520](getsentry/sentry-dotnet#5520)
- chore(deps): update Native SDK to v0.16.4 by @​github-actions in
[#​5508](getsentry/sentry-dotnet#5508)
- chore(deps): update Java SDK to v8.53.0 by @​github-actions in
[#​5484](getsentry/sentry-dotnet#5484)

### Other

- deps: update perfview (removes the .il suffix from profile module
names) by @​jamescrosswell in
[#​5502](getsentry/sentry-dotnet#5502)

Commits viewable in [compare
view](getsentry/sentry-dotnet@6.9.0...6.10.0).
</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SdkVersion.Name and SdkVersion.Version are empty for Console-Apps

2 participants