From 154ddab4397fe035cb1bad13903b16436cf8be1d Mon Sep 17 00:00:00 2001 From: Mathias Kallmert Date: Mon, 13 Feb 2023 14:29:09 +0100 Subject: [PATCH 1/4] Make compatible with sentry v.7 --- RavenPowerShell.psm1 | 60 ++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/RavenPowerShell.psm1 b/RavenPowerShell.psm1 index 45e078c..ea6a5ec 100644 --- a/RavenPowerShell.psm1 +++ b/RavenPowerShell.psm1 @@ -1,32 +1,20 @@ -function CurrentUnixTimestamp () { - return [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds -} - - Class RavenClient { - - [string]$sentryDsn - [string]$storeUri - [string]$sentryKey - [string]$sentrySecret - [int]$projectId - [string]$sentryAuth - [string]$userAgent + hidden [string]$sentryDsn + hidden [string]$storeUri + hidden [string]$sentryAuth # https://github.com/PowerShell/vscode-powershell/issues/66 hidden [bool]$_getFrameVariablesIsFixed - RavenClient([string]$sentryDsn) { $uri = [System.Uri]::New($sentryDsn) $this.sentryDsn = $sentryDsn - $this.sentryKey = $uri.UserInfo.Split(':')[0] - $this.sentrySecret = $uri.UserInfo.Split(':')[1] - $this.projectId = $uri.Segments[1] - $this.storeUri = "$($uri.Scheme)://$($uri.Host):$($uri.Port)/api/$($this.projectId)/store/" + $sentryKey = $uri.UserInfo.Split('@')[0] + $userAgent = 'PowerShellRaven/1.1' + $this.sentryAuth = "Sentry sentry_version=7,sentry_key=$($sentryKey),sentry_client=$userAgent" - $this.userAgent = 'PowerShellRaven/1.0' - $this.sentryAuth = "Sentry sentry_version=5,sentry_key=$($this.sentryKey),sentry_secret=$($this.sentrySecret)" + $projectId = $uri.Segments[1] + $this.storeUri = "$($uri.Scheme)://$($uri.Host):$($uri.Port)/api/$($projectId)/store/" $this._getFrameVariablesIsFixed = $false } @@ -44,7 +32,7 @@ Class RavenClient { $body['platform'] = 'other' $body['sdk'] = @{ 'name' = 'PowerShellRaven' - 'version' = '1.0' + 'version' = '1.1' } $body['server_name'] = [System.Net.Dns]::GetHostName() $body['message'] = $message @@ -52,15 +40,15 @@ Class RavenClient { return $body } - [void]StoreEvent([hashtable]$body) { + [string]StoreEvent([hashtable]$body) { $headers = @{} - $headers.Add('X-Sentry-Auth', $this.sentryAuth + ",sentry_timestamp=" + $(CurrentUnixTimestamp)) - $headers.Add('User-Agent', $this.userAgent) - + $headers.Add('X-Sentry-Auth', $this.sentryAuth) + $jsonBody = ConvertTo-Json $body -Depth 6 - Invoke-RestMethod -Uri $this.storeUri -Method Post -Body $jsonBody -ContentType 'application/json' -Headers $headers + $result = Invoke-RestMethod -Uri $this.storeUri -Method Post -Body $jsonBody -ContentType 'application/json' -Headers $headers + return $result.Id } [hashtable]ParsePSCallstack([System.Management.Automation.CallStackFrame[]]$callstackFrames, [hashtable[]]$frameVariables) { @@ -115,13 +103,13 @@ Class RavenClient { $this.StoreEvent($body) } - [void]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord) { + [string]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord) { # skip ourselves - $this.CaptureException($errorRecord, 1) + return $this.CaptureException($errorRecord, 1) } - [void]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord, [int]$skipFrames) { + [string]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord, [int]$skipFrames) { # skip ourselves $callstackSkip = 1 + $skipFrames @@ -143,14 +131,14 @@ Class RavenClient { } } - $this.CaptureException($errorRecord, $callstackFrames, $frameVariables) + return $this.CaptureException($errorRecord, $callstackFrames, $frameVariables) } - [void]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord, + [string]CaptureException([System.Management.Automation.ErrorRecord]$errorRecord, [System.Management.Automation.CallStackFrame[]]$callstackFrames=@(), [hashtable[]]$frameVariables) { $exceptionMessage = $errorRecord.Exception.Message - if ($errorRecord.ErrorDetails.Message -ne $null) { + if ($errorRecord.ErrorDetails.Message) { $exceptionMessage = $errorRecord.ErrorDetails.Message } $exceptionName = $errorRecord.Exception.GetType().Name @@ -170,19 +158,19 @@ Class RavenClient { $body['stacktrace'] = $this.ParsePSCallstack($callstackFrames, $frameVariables) - $this.StoreEvent($body) + return $this.StoreEvent($body) } } -function New-RavenClient { +function New-Sentry { param( # Sentry DSN [Parameter(Mandatory=$true)] [string] $SentryDsn ) - return [RavenClient]::New($SentryDsn) + return [Sentry]::New($SentryDsn) } -Export-ModuleMember -Function New-RavenClient \ No newline at end of file +Export-ModuleMember -Function New-Sentry \ No newline at end of file From c02d4d7844749a48dfb5f22a64fb8529e46d2adb Mon Sep 17 00:00:00 2001 From: Mathias Kallmert Date: Mon, 13 Feb 2023 14:38:38 +0100 Subject: [PATCH 2/4] Remove all associations to Raven --- README.md | 16 ++++++++-------- RavenPowerShell.psd1 => SentryPowershell.psd1 | Bin 8218 -> 8212 bytes RavenPowerShell.psm1 => SentryPowershell.psm1 | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) rename RavenPowerShell.psd1 => SentryPowershell.psd1 (90%) rename RavenPowerShell.psm1 => SentryPowershell.psm1 (97%) diff --git a/README.md b/README.md index 1e42a51..07c2a20 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,39 @@ Overview -------- -RavenPowerShell is a PowerShell client for [sentry.io](https://sentry.io/welcome/) +SentryPowershell is a PowerShell client for [sentry.io](https://sentry.io/welcome/) Installation ----- ```powershell -Install-Module RavenPowerShell +Install-Module SentryPowershell ``` Usage ----- ```powershell -Import-Module RavenPowerShell +Import-Module SentryPowershell -$ravenClient = New-RavenClient -SentryDsn 'https://mysentrydsn' +$sentry = New-Sentry -SentryDsn 'https://mysentrydsn' try { $null[5] = 0 } catch { - $ravenClient.CaptureException($_) + $sentry.CaptureException($_) } ``` AND/OR ```powershell -Import-Module RavenPowerShell +Import-Module SentryPowershell -$ravenClient = New-RavenClient -SentryDsn 'https://mysentrydsn' +$client = New-Sentry -SentryDsn 'https://mysentrydsn' trap { - $ravenClient.CaptureException($_) + $client.CaptureException($_) break } diff --git a/RavenPowerShell.psd1 b/SentryPowershell.psd1 similarity index 90% rename from RavenPowerShell.psd1 rename to SentryPowershell.psd1 index 976b65800abe6eaa8ca2dbff70f7b1771166b150..0b11beeaf55c7a8c19f9b8fd85f2306102cfa2d3 100644 GIT binary patch delta 387 zcmbQ`FvVfRB1Z9GhE#?;h7yJ%hDwG2hJ1!{Ais#Ac=L9~L`HWLAjg~`jlmd58Uvv& zgCRo-gDH^IWiVkd1Ii`=S(ZRn3Ruhx$TDI`1gbV*NCv7m0E$~MBu$QI4ixogC;-AV zhD@M!c|bKqAd4rTWiAxW$0`%Z(v4lu=ASIZyxd6c-rOjp&5Fw-lMjkZQ2X<5_ delta 263 zcmbQ@Fw0@XBF2d>Dw|I*1~Iy)FeEXUFjz9A0AVtar3<8u87vsgfh-dsodkrsKzR$G zcp{Kx0alv?mN5Y8FbAtLoSeuUC>zF5$xy_Q&ydHUz!1Vv%#aCWr2};p0deu<