Skip to content

feat: Add Write-SentryLog cmdlet for structured logs - #131

Merged
jamescrosswell merged 2 commits into
mainfrom
feat/write-sentrylog
May 25, 2026
Merged

jamescrosswell merged 2 commits into
mainfrom
feat/write-sentrylog

Conversation

@vaind

@vaind vaind commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds Write-SentryLog, a native PowerShell cmdlet for sending structured logs (Sentry Logs, currently Experimental.EnableLogs).

Without it, users have to call the underlying .NET API directly — e.g. [Sentry.SentrySdk]::Logger.LogInfo('User {0} ran {1}', [object[]]@($user, $script)) — because PowerShell doesn't auto-expand params object[]. The cmdlet hides that ceremony behind familiar PowerShell ergonomics.

# simple
Write-SentryLog 'service started'

# different level
Write-SentryLog -Level Warning 'disk usage at 85%'

# templated, with structured params
Write-SentryLog -Level Info -Message 'User {0} ran {1}' -Parameters $user, $script

# structured attributes
Write-SentryLog -Level Error -Message 'sync failed' -Attributes @{ region = 'us-east-1'; retries = 3 }

# pipeline
'service started' | Write-SentryLog

The cmdlet:

  • defaults -Level to Info
  • accepts -Message from the pipeline (position 0)
  • dispatches dynamically to the matching Logger.Log<Level>(...) overload
  • attaches structured attributes via the Action<SentryLog> overload using SetAttribute
  • is a no-op (with debug log) when Sentry isn't started, matching Out-Sentry's behavior

Tests use Experimental.SetBeforeSendLog(...) to capture log records and assert on level, template, message substitution, parameter array, and attributes.

Addresses #122 (comment) — the sample in #122 should be updated to use this cmdlet once this lands (follow-up).

Test plan

  • Invoke-Pester ./tests/write-sentrylog.tests.ps1 — 7/7 pass
  • Full suite (Invoke-Pester ./tests) — 72 passed, 3 skipped (pre-existing)
  • CI green on supported PowerShell versions

🤖 Generated with Claude Code

Wraps SentrySdk.Logger with a PowerShell-native API so users don't have
to call params object[] overloads with [object[]] coercion. Supports
all six log levels, message templates with positional parameters, and
structured attributes via a hashtable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 7818d05

Comment thread modules/Sentry/public/Write-SentryLog.ps1 Dismissed
Comment thread tests/write-sentrylog.tests.ps1 Dismissed
Comment thread tests/write-sentrylog.tests.ps1 Dismissed
Mirrors the sample from PR #122 but uses the new cmdlet, including the
-Parameters and -Attributes flags. Also fixes the changelog entry to
include the PR number so Danger picks it up.

Co-Authored-By: Claude Opus 4.7 (1M context) <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.

Cool, thanks @vaind - this was a good one to read to get my head around PS modules... relatively simple for a PS expert like yourself but plenty of new concepts for a noob like me.

LGTM (FWIW) 👍🏻

@jamescrosswell
jamescrosswell merged commit 4355d10 into main May 25, 2026
20 checks passed
@jamescrosswell
jamescrosswell deleted the feat/write-sentrylog branch May 25, 2026 04:37
vaind added a commit that referenced this pull request Sep 7, 2026
Write-SentryLog (#131) and the move of its options off Experimental
(#133) both land in this same unreleased cycle, so no released version
ever exposed $_.Experimental.SetBeforeSendLog through the module. There
is nothing for a user upgrading from 0.4.0 to migrate.

Reaching past the module into the bundled SDK's options object was the
only way to touch it from 0.4.0, and the Dependencies entry for the
5.16.1 -> 6.10.0 bump already covers that surface.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
vaind added a commit that referenced this pull request Sep 7, 2026
* chore: update dependencies/Sentry.properties to 6.10.0

* docs: Drop the Logs opt-in from the send-logs sample

sentry-dotnet 6.10.0 removed the EnableLogs gate on SentrySdk.Logger,
which is what Write-SentryLog calls. Setting $_.EnableLogs = $true no
longer has any bearing on whether Write-SentryLog emits, so the sample's
"opt in to Logs" guidance now teaches something untrue.

Verified against the bundled 6.10.0 assembly: a log envelope item reaches
the transport with EnableLogs both set and unset, where 6.5.0 emitted
only when it was set. No test covers the disabled path, which is why the
change was invisible to CI.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Configure Sentry client with DSN and debug mode

* docs: Fold the Logs opt-in note into the Write-SentryLog entry

Write-SentryLog and the SDK bump that removed the EnableLogs gate both
land in the same unreleased cycle, so describing the removal as its own
entry documents a change no released version ever exposed. Readers of the
next release only need to know the cmdlet exists, so reference #137 from
the entry that introduced it instead.

Drop the EnableLogs half of the breaking-changes entry for the same
reason: it directed readers to set $_.EnableLogs, which is no longer
required for Write-SentryLog to emit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs: Drop the Experimental breaking-change entry

Write-SentryLog (#131) and the move of its options off Experimental
(#133) both land in this same unreleased cycle, so no released version
ever exposed $_.Experimental.SetBeforeSendLog through the module. There
is nothing for a user upgrading from 0.4.0 to migrate.

Reaching past the module into the bundled SDK's options object was the
only way to touch it from 0.4.0, and the Dependencies entry for the
5.16.1 -> 6.10.0 bump already covers that surface.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs: Credit #133 on the Write-SentryLog entry

#133 moved the Logs options off Experimental and updated the sample and
tests accordingly, so it shaped the logging surface users see. Its
attribution lived in the breaking-change entry that was just removed;
fold it into the feature entry rather than losing it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: GitHub <noreply@github.com>
Co-authored-by: Ivan Dlugos <dlugos.ivan@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Ivan Dlugos <6349682+vaind@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants