sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

feat(logs): apply default attributes from Scope

Open Flash0ver opened this issue 1 month ago • 2 comments

fixes #4493 closes #4733

  • #4493
  • #4733

See docs: https://develop.sentry.dev/sdk/telemetry/logs/#default-attributes


Changes

  • Adds missing "default attributes" as per Sentry Developer Documentation.
  • Applying the values - if available - from the current Scope.
    • Changed the internal APIs for that

However, it seems that we're missing a lot of the Contexts on the Scope, where we currently mostly apply them to Events.

TODO

  • Enrich the Scope with the data needed
    • or set the data directly for the time being
  • add CHANGELOG.md entry

Flash0ver avatar Dec 02 '25 13:12 Flash0ver

Fails
:no_entry_sign: Please consider adding a changelog entry for the next release.
Messages
:book: Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- apply default attributes from Scope ([#4784](https://github.com/getsentry/sentry-dotnet/pull/4784))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by :no_entry_sign: dangerJS against 0e25afd649192abff1603f5f13f01f5813916f60

github-actions[bot] avatar Dec 02 '25 13:12 github-actions[bot]

Codecov Report

:x: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 73.96%. Comparing base (8df9302) to head (0e25afd).

Files with missing lines Patch % Lines
src/Sentry/SentryLog.cs 93.93% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4784      +/-   ##
==========================================
+ Coverage   73.91%   73.96%   +0.05%     
==========================================
  Files         485      485              
  Lines       17682    17717      +35     
  Branches     3494     3510      +16     
==========================================
+ Hits        13069    13104      +35     
  Misses       3755     3755              
  Partials      858      858              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Dec 02 '25 14:12 codecov[bot]

@Flash0ver Do we have an ETA on when this will be released? We have another customer who is looking to add user scope context to logs.

InterstellarStella avatar Dec 23 '25 07:12 InterstellarStella

@InterstellarStella TL;DR: January 2026 ... Scope-Attributes a bit afterwards

We are lacking some info on the Scope, a fix we could neatly combine with Scope-Attributes. But we'll probably do a little temporary workaround ourselves to close this issue very soon in the New Year.

Similarly, as an intermediate workaround, user code could attach this/any information via SetBeforeSendLog:

options.SetBeforeSendLog(static (SentryLog log) =>
{
  log.SetAttribute("attribute-name", "attribute-value");
  return log;
});

Once we ship this changeset and apply these in-box, it will be (ever so slightly) more efficient, but functionally equivalent. After fixing these Default Attributes, we will look into Scope-Attributes.

Flash0ver avatar Dec 23 '25 10:12 Flash0ver