Skip to content

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

Open
vaind wants to merge 2 commits into
mainfrom
feat/write-sentrylog
Open

feat: Add Write-SentryLog cmdlet for structured logs#131
vaind wants to merge 2 commits into
mainfrom
feat/write-sentrylog

Conversation

@vaind
Copy link
Copy Markdown
Collaborator

@vaind vaind commented May 22, 2026

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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

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>
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.

2 participants