Add Add-SentryEventProcessor cmdlet and migrate internal processors#130
Draft
jamescrosswell wants to merge 3 commits into
Draft
Add Add-SentryEventProcessor cmdlet and migrate internal processors#130jamescrosswell wants to merge 3 commits into
jamescrosswell wants to merge 3 commits into
Conversation
Public cmdlet that registers a global event processor backed by a PowerShell script block. The block receives the event via the automatic $_ variable (matching Edit-SentryScope), returns the event to send it, or $null to drop it. Internally the block is wrapped by a new C# ScriptBlockEventProcessor that implements ISentryEventProcessor directly. Implementing the interface in C# (rather than via a PowerShell class deriving from it) sidesteps PowerShell's parse-time base-type resolution, which is the root cause of the noisy 'Unable to find type [SentryEventProcessor]' errors on module import. Subsequent commits migrate the internal EventUpdater and StackTraceProcessor onto this same mechanism so the PowerShell class files can be removed entirely. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace the PowerShell class-based EventUpdater with an equivalent script block registered through ScriptBlockEventProcessor. Behavior is unchanged: the event Platform is set to 'powershell' and a bogus pwsh-versioned Release set by the .NET SDK is cleared. This eliminates one of the three PowerShell class-based event processors. StackTraceProcessor follows in the next commit; the parse-time errors won't disappear until that one is migrated too. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace the PowerShell class-based StackTraceProcessor with a factory function New-StackTraceEventProcessor that captures per-event state via closure and returns a ScriptBlockEventProcessor. Behavior is intended to match the previous class exactly; all helper methods are defined inline inside the returned script block. Out-Sentry is updated to gather state into local variables and call the factory immediately before CaptureEvent, replacing the previous mutate-the-processor-instance pattern. With this commit the module no longer defines any PowerShell `class : SentryEventProcessor` subclasses, so the C# base SentryEventProcessor_ (which existed only to host the Process_ / DoProcess workaround) is also removed. The 'Unable to find type [SentryEventProcessor]' parse errors on module import should be gone. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- Add Add-SentryEventProcessor cmdlet and migrate internal processors ([#130](https://github.com/getsentry/sentry-powershell/pull/130))If none of the above apply, you can opt out of this check by adding |
| # Behavior is intended to match the previous class exactly; the per-event state | ||
| # that used to live on instance fields is now captured by closure inside the | ||
| # returned ScriptBlockEventProcessor. | ||
| function New-StackTraceEventProcessor { |
| SetContextLinesFromArray $sentryFrame $lines | ||
| } catch { | ||
| Write-Warning "Failed to read context lines for $($sentryFrame.AbsolutePath): $_" | ||
| if ($global:SentryPowershellRethrowErrors -eq $true) { throw } |
| SetContextLinesFromArray $sentryFrame $lines | ||
| } catch { | ||
| Write-Warning "Failed to read context lines for frame with function '$($sentryFrame.Function)': $_" | ||
| if ($global:SentryPowershellRethrowErrors -eq $true) { throw } |
| @@ -0,0 +1,54 @@ | |||
| BeforeAll { | |||
| . "$PSScriptRoot/utils.ps1" | |||
| $global:SentryPowershellRethrowErrors = $true | |||
| } | ||
|
|
||
| AfterAll { | ||
| $global:SentryPowershellRethrowErrors = $false |
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.
Closes #124.
Replaces the PowerShell
class : SentryEventProcessorpattern (which fails parse-time base-type resolution on module import) with a single C# wrapper class plus a script-block-based public cmdlet. The same mechanism is then used internally for the two existing built-in processors, so the PowerShell class files can be deleted entirely.Three commits, reviewable separately or together:
1. Add
Add-SentryEventProcessorcmdletUser-facing cmdlet that registers a global event processor. The script block receives the event via
$_(matchingEdit-SentryScope), returns the event to send it, or$nullto drop it.Under the hood, a new C#
ScriptBlockEventProcessorimplementsISentryEventProcessordirectly. Doing the interface implementation in C# (instead of via a PowerShellclassderiving from it) sidesteps PowerShell's parse-time base-type resolution. Includes a test suite.2. Migrate
EventUpdatertoScriptBlockEventProcessorReplaces the
class EventUpdater : SentryEventProcessordefinition with an inline script block registered through the sameScriptBlockEventProcessor. Behavior is unchanged (setsPlatform = 'powershell', clears the bogus pwsh-versionedReleaseset by the .NET SDK). DeletesEventUpdater.ps1.3. Migrate
StackTraceProcessortoScriptBlockEventProcessorThe big one. ~250-line
class StackTraceProcessorbecomesNew-StackTraceEventProcessor, a factory function that captures the per-event state (SentryException, StackTraceFrames, StackTraceString, InvocationInfo, ModulePaths, PwshModules, Logger) via closure and returns aScriptBlockEventProcessor. All the previous instance methods are defined as inline functions inside the returned script block.Out-Sentryis updated to gather state into local variables and call the factory immediately beforeCaptureEvent, replacing the previous mutate-the-processor-instance pattern.With no remaining PS
class : SentryEventProcessorsubclasses, the C# baseSentryEventProcessor_(which only existed to host theProcess_/DoProcessworkaround for theProcesskeyword conflict) is also removed.Devil in the details
A few things to verify carefully in review and CI:
.GetNewClosure(), then the returned script block defines all helpers as inlinefunctiondeclarations at its top. Helpers reference$s(alias for$state) which is captured via closure. I believe this works, but PS class semantics are a more familiar pattern — first CI run will tell us if anything misbehaves.stacktrace-processor.tests.ps1now calls\$sut.Process(\$event_)(capital P, the C# method) rather than\$sut.process(\$event_).System.Runtimeversion mismatch turns into a fatal Add-Type failure, which means I can't run the test suite end-to-end locally. CI uses older pwsh where CS1701 stays a warning and Add-Type succeeds. Tests therefore need a green CI run before I'd consider this PR truly verified.Out-Sentrybody was restructured so state is gathered into locals (\$sentryException,\$stackTraceString,\$invocationInfo,\$stackTraceFrames) and the processor is constructed at the end. Functionally equivalent but the diff is non-trivial.