Add Add-SentryAttachment cmdlet with extension-based content-type defaults#134
Merged
Conversation
…aults Wraps Scope.AddAttachment and, when -ContentType is not supplied, infers a content type from the file extension. PowerShell-specific extensions (.ps1, .psm1, .psd1, .ps1xml, .pssc, .psrc) and common text/structured formats (.txt, .log, .json, .xml, .csv, .yaml, ...) get a useful default so the Sentry UI can preview them instead of falling back to application/octet-stream. Closes #32 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Demonstrates the new Add-SentryAttachment cmdlet covering all three common paths: file by path, raw bytes with a filename hint, and an explicit content-type override. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9dba662. Configure here.
PowerShell's $PWD and [Environment]::CurrentDirectory can diverge after Set-Location. The Sentry SDK reads attachment files lazily at send time via .NET I/O, which resolves relative paths against [Environment]::CurrentDirectory — so a relative path that looks correct from the caller's perspective could fail or attach the wrong file. Resolve eagerly with GetUnresolvedProviderPathFromPSPath before passing the path on. Caught by Cursor Bugbot on #134. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The Sentry SDK may keep an attachment file handle open until Stop-Sentry runs in AfterEach. On Windows this races with the in-test `finally` cleanup of the temp dir, which doesn't allow concurrent access. The temp dir is harmless to leave behind, so swallow the cleanup error rather than fail the test. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
vaind
approved these changes
May 28, 2026
The Path parameter already accepts pipeline input by value; add an example (cmdlet help + sample) and a regression test for `$path | Add-SentryAttachment`. Byte input stays a named parameter since piping a byte[] unrolls it into individual bytes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add ValueFromPipeline to -Bytes so advanced callers can pipe a byte array (wrapped with the unary comma operator to avoid the pipeline unrolling it). Not demonstrated in the sample since it requires understanding the comma-operator idiom; documented in the parameter help and covered by a test. Co-Authored-By: Claude Opus 4.7 <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 an
Add-SentryAttachmentcmdlet that wrapsScope.AddAttachment. When no-ContentTypeis supplied this is infered from the file extension so that the file preview in Sentry works for common 'text' files.Mirrors
sentry-python's pattern of delegating to a default mapping when the caller doesn't specify one — adds a small explicit table for some entries not in the OS MIME database (like the PowerShell extensions).Usage
The existing
$_.AddAttachment(...)path is untouched — this is purely additive.Example
This is what we see in Sentry after running the new sample:

Notes
getsentry/sentry; this PR just covers the SDK-side.Closes #32