feat: Add Write-SentryLog cmdlet for structured logs#131
Open
vaind wants to merge 2 commits into
Open
Conversation
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>
Contributor
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Write-SentryLog, a native PowerShell cmdlet for sending structured logs (Sentry Logs, currentlyExperimental.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-expandparams object[]. The cmdlet hides that ceremony behind familiar PowerShell ergonomics.The cmdlet:
-LeveltoInfo-Messagefrom the pipeline (position 0)Logger.Log<Level>(...)overloadAction<SentryLog>overload usingSetAttributeOut-Sentry's behaviorTests 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 passInvoke-Pester ./tests) — 72 passed, 3 skipped (pre-existing)🤖 Generated with Claude Code