Closed bruno-garcia closed 7 months ago
Would be nice if we could also import the module globally (for the user)
Windows PowerShell is written for .NET Framework while PowerShell Core is written for .NET Core. Portable modules are modules that work in both Windows PowerShell and PowerShell Core. While .NET Framework and .NET Core are highly compatible, there are differences in the available APIs between the two. There are also differences in the APIs available in Windows PowerShell and PowerShell Core. Modules intended to be used in both environments need to be aware of these differences.
CLRVersion
property of $PSVersionTable
. e.g. the following from my computer indicates net462:
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.22621.2506
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.2506
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
publishing: https://www.powershellgallery.com/
The following works out of the box in Powershell 7.4.1:
dotnet feat/pwsh *$ $ import-module C:\dev\dotnet\src\Sentry\bin\Debug\net6.0\Sentry.dll
dotnet feat/pwsh *$ $ $options = new-object Sentry.SentryOptions
dotnet feat/pwsh *$ $ $options.Debug = $true
dotnet feat/pwsh *$ $ $options.Dsn = 'https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537'
dotnet feat/pwsh *$ $ $sentry = [Sentry.SentrySdk]::init($options)
Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
Debug: Initializing Hub for Dsn: 'https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537'.
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
Debug: This looks like a standard JIT/AOT application build.
Debug: Starting BackgroundWorker.
Debug: BackgroundWorker Started.
Debug: New scope pushed.
Debug: Registering integration: 'AutoSessionTrackingIntegration'.
Debug: Registering integration: 'AppDomainUnhandledExceptionIntegration'.
Debug: Registering integration: 'AppDomainProcessExitIntegration'.
Debug: Registering integration: 'UnobservedTaskExceptionIntegration'.
Debug: Registering integration: 'SentryDiagnosticListenerIntegration'.
Info: DiagnosticSource Integration is disabled because tracing is disabled.
Debug: Registering integration: 'WinUIUnhandledExceptionIntegration'.
dotnet feat/pwsh *$ $ throw "hello from pwsh"
Exception: hello from pwsh
dotnet feat/pwsh *$ $ [Sentry.SentrySdk]::CaptureMessage('Hello from pwsh')
Debug: Creating the Dynamic Sampling Context from the Propagation Context
Info: Capturing event.
Debug: Running main event processor on: Event fbe8faa0feec4bdcbedfe8a04a1d63ee
Debug: Creating SentryStackTrace. isCurrentStackTrace: True.
Debug: Skipping initial stack frame 'Sentry.Extensibility.SentryStackTraceFactory, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.Internal.MainSentryEventProcessor, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.Extensibility.ISentryEventProcessorExtensions, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.SentryClient, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.SentryClient, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.Internal.Hub, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.SentryClientExtensions, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping initial stack frame 'Sentry.SentrySdk, Sentry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'
Debug: Skipping debug image for module '<In Memory Module>' because assembly wasn't found: '<In Memory Module>'
Debug: Got debug image for 'System.Linq.Expressions.dll' having Debug ID: e6b30899-79dd-41cf-1786-998ca8e1fc89-4eb5f61c
Debug: Got debug image for 'System.Management.Automation.dll' having Debug ID: 30b1cfa3-ab4b-40d6-9bbe-0fa5d6c17442-c8630267
Debug: Got debug image for 'System.Private.CoreLib.dll' having Debug ID: 844e9600-08a6-8b0b-4be3-8422f1ea6e8c-432266a4
Debug: Created DebugStackTrace with 15 frames.
Debug: Merging 3 debug images from stacktrace.
Debug: Event not sampled.
Debug: Enqueuing envelope fbe8faa0feec4bdcbedfe8a04a1d63ee
Info: Envelope queued up: 'fbe8faa0feec4bdcbedfe8a04a1d63ee'
fbe8faa0feec4bdcbedfe8a04a1d63ee
Debug: Using 'GzipBufferedRequestBodyHandler' body compression strategy with level Optimal.
Debug: Envelope handed off to transport (event ID: 'fbe8faa0feec4bdcbedfe8a04a1d63ee'). 1 items in queue.
dotnet feat/pwsh *$ $ Debug: HttpTransport: Envelope 'fbe8faa0feec4bdcbedfe8a04a1d63ee' successfully sent. Content: {"sdk":{"name":"sentry.dotnet","version":"4.0.1"},"event_id":"fbe8faa0feec4bdcbedfe8a04a1d63ee","trace":{"trace_id":"2dc7a0586a45490798675268a6fa5460","public_key":"eb18e953812b41c3aeb042e666fd3b5c","release":"pwsh@7.4.1 SHA: 6a98b28414948626f1b29a5e8b062e73b7ff165a\u002B6a98b28414948626f1b29a5e8b062e73b7ff165a","environment":"production"},"sent_at":"2024-02-06T18:33:41.5131578+00:00"} {"type":"event","length":10713} {"modules":{"System.Private.CoreLib":"8.0.0.0","pwsh":"7.4.1.500","System.Runtime":"8.0.0.0","Microsoft.PowerShell.ConsoleHost":"7.4.1.500","System.Management.Automation":"7.4.1.500","System.Threading.Thread":"8.0.0.0","System.Runtime.InteropServices":"8.0.0.0","System.Threading":"8.0.0.0","System.Collections":"8.0.0.0","System.Linq.Expressions":"8.0.0.0","System.Diagnostics.Process":"8.0.0.0","System.Runtime.Numerics":"8.0.0.0","System.Xml.ReaderWriter":"8.0.0.0","System.Private.Xml":"8.0.0.0","Microsoft.PowerShell.CoreCLR.Eventing":"7.4.1.500","Microsoft.Win32.Primitives":"8.0.0.0","System.Text.Encoding.Extensions":"8.0.0.0","System.Collections.Concurrent":"8.0.0.0","System.Text.RegularExpressions":"8.0.0.0","System.Collections.Specialized":"8.0.0.0","System.DirectoryServices":"8.0.0.0","System.ComponentModel.Primitives":"8.0.0.0","System.Private.Uri":"8.0.0.0","System.Management":"8.0.0.0","Microsoft.Win32.Registry":"8.0.0.0","Newtonsoft.Json":"13.0.0.0","System.Linq":"8.0.0.0","System.ComponentModel.TypeConverter":"8.0.0.0","System.Net.NetworkInformation":"8.0.0.0","System.ObjectModel":"8.0.0.0","Microsoft.Management.Infrastructure":"1.0.0.0","System.Security.Cryptography":"8.0.0.0","System.Net.Mail":"8.0.0.0","System.Net.Primitives":"8.0.0.0","System.Security.AccessControl":"8.0.0.0","System.Runtime.Serialization.Formatters":"8.0.0.0","System.Diagnostics.TraceSource":"8.0.0.0","System.Runtime.Serialization.Primitives":"8.0.0.0","System.Data.Common":"8.0.0.0","System.ComponentModel":"8.0.0.0","System.Reflection.Emit.Lightweight":"8.0.0.0","System.Reflection.Emit.ILGeneration":"8.0.0.0","System.Reflection.Primitives":"8.0.0.0","System.Memory":"8.0.0.0","System.Console":"8.0.0.0","System.Security.Principal.Windows":"8.0.0.0","System.Security.Claims":"8.0.0.0","Microsoft.ApplicationInsights":"2.21.0.429","netstandard":"2.1.0.0","System.Diagnostics.DiagnosticSource":"8.0.0.0","System.Diagnostics.Tracing":"8.0.0.0","System.IO.MemoryMappedFiles":"8.0.0.0","System.Private.Xml.Linq":"8.0.0.0","System.IO.Pipes":"8.0.0.0","System.Text.Encoding.CodePages":"8.0.0.0","System.Xml.XDocument":"8.0.0.0","System.Threading.Tasks.Parallel":"8.0.0.0","System.Threading.Overlapped":"8.0.0.0","System.IO.FileSystem.AccessControl":"8.0.0.0","System.IO.FileSystem.DriveInfo":"8.0.0.0","getfilesiginforedistwrapper":"10.0.0.0","System.Security.Permissions":"8.0.0.0","System.Threading.ThreadPool":"8.0.0.0","System.Runtime.Loader":"8.0.0.0","Microsoft.PowerShell.PSReadLine2":"2.3.4.0","mscorlib":"4.0.0.0","Microsoft.PowerShell.Commands.Management":"7.4.1.500","Microsoft.PowerShell.Commands.Utility":"7.4.1.500","Microsoft.PowerShell.MarkdownRender":"7.2.1.0","System.Net.Http":"8.0.0.0","System.Diagnostics.StackTrace":"8.0.0.0","System.Reflection.Metadata":"8.0.0.0","System.Collections.Immutable":"8.0.0.0","System.ServiceProcess.ServiceController":"8.0.0.0","System.Diagnostics.FileVersionInfo":"8.0.0.0","System.Core":"4.0.0.0","System":"4.0.0.0","Microsoft.PowerShell.PSReadLine.Polyfiller":"1.0.0.0","System.Runtime.InteropServices.RuntimeInformation":"8.0.0.0","System.Runtime.Intrinsics":"8.0.0.0","Sentry":"4.0.1.0","System.IO.Compression":"8.0.0.0","System.Text.Json":"8.0.0.0","System.Net.Security":"8.0.0.0","System.Net.Sockets":"8.0.0.0","System.Net.NameResolution":"8.0.0.0","System.Collections.NonGeneric":"8.0.0.0","System.Threading.Tasks":"8.0.0.0","Microsoft.Management.Infrastructure.Native":"1.0.0.0","Microsoft.CodeAnalysis":"4.8.0.0","System.Security.Cryptography.Primitives":"8.0.0.0","System.Runtime.CompilerServices.Unsafe":"8.0.0.0"},"event_id":"fbe8faa0feec4bdcbedfe8a04a1d63ee","timestamp":"2024-02-06T18:33:40.1054309+00:00","logentry":{"message":"Hello from pwsh"},"platform":"csharp","release":"pwsh@7.4.1 SHA: 6a98b28414948626f1b29a5e8b062e73b7ff165a\u002B6a98b28414948626f1b29a5e8b062e73b7ff165a","threads":{"values":[{"id":21,"name":"Pipeline Execution Thread","crashed":false,"current":true,"stacktrace":{"frames":[{"function":"void ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)","in_app":false,"package":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","instruction_addr":"0x40","addr_mode":"rel:2","function_id":"0x380f"},{"function":"void PipelineThread.WorkerProc()","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x16","addr_mode":"rel:1","function_id":"0x42b1"},{"function":"void LocalPipeline.InvokeThreadProc()","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x9b","addr_mode":"rel:1","function_id":"0x429a"},{"function":"FlowControlException LocalPipeline.InvokeHelper()","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x2c1","addr_mode":"rel:1","function_id":"0x4298"},{"function":"Array PipelineProcessor.SynchronousExecuteEnumerate(object input)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x8d","addr_mode":"rel:1","function_id":"0x5618"},{"function":"void PipelineProcessor.DoCompleteCore(CommandProcessorBase commandRequestingUpstreamCommandsToStop)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x3b","addr_mode":"rel:1","function_id":"0x561b"},{"function":"void CommandProcessorBase.DoComplete()","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x55","addr_mode":"rel:1","function_id":"0x106b"},{"function":"void DlrScriptCommandProcessor.Complete()","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x94","addr_mode":"rel:1","function_id":"0x285d"},{"function":"void DlrScriptCommandProcessor.RunClause(Action\u003CFunctionContext\u003E clause, object dollarUnderbar, object inputToProcess)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x240","addr_mode":"rel:1","function_id":"0x2860"},{"function":"void LightLambda.RunVoid1\u003CT0\u003E(T0 arg0)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x3e","addr_mode":"rel:1","function_id":"0x3e94"},{"function":"void Interpreter.Run(InterpretedFrame frame)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x15","addr_mode":"rel:1","function_id":"0x3dfa"},{"function":"int EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) x 2","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x43","addr_mode":"rel:1","function_id":"0x3c87"},{"function":"int DynamicInstruction\u003CT0, T1, TRet\u003E.Run(InterpretedFrame frame)","in_app":false,"package":"System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35","instruction_addr":"0x0","addr_mode":"rel:1","function_id":"0x3cd1"},{"function":"TRet UpdateDelegates.UpdateAndExecute2\u003CT0, T1, TRet\u003E(CallSite site, T0 arg0, T1 arg1)","in_app":false,"package":"System.Linq.Expressions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","instruction_addr":"0x11d","addr_mode":"rel:0","function_id":"0x106b"},{"function":"object CallSite.Target(Closure, CallSite, Type, string)","in_app":false}]}}]},"level":"info","request":{},"contexts":{"Current Culture":{"name":"en-US","display_name":"English (United States)","calendar":"GregorianCalendar"},"Dynamic Code":{"Compiled":true,"Supported":true},"Memory Info":{"allocated_bytes":98984240,"fragmented_bytes":328288,"heap_size_bytes":17361936,"high_memory_load_threshold_bytes":61641252864,"total_available_memory_bytes":68490280960,"memory_load_bytes":30135723622,"total_committed_bytes":35643392,"promoted_bytes":285504,"pause_time_percentage":0.03,"index":8,"finalization_pending_count":126,"compacted":true,"concurrent":false,"pause_durations":[1.471,0]},"ThreadPool Info":{"min_worker_threads":20,"min_completion_port_threads":1,"max_worker_threads":32767,"max_completion_port_threads":1000,"available_worker_threads":32767,"available_completion_port_threads":1000},"app":{"type":"app","app_start_time":"2024-02-06T18:30:17.1675024+00:00","in_foreground":false},"device":{"type":"device","timezone":"Central Europe Standard Time","timezone_display_name":"(UTC\u002B01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague","boot_time":"2024-02-02T07:15:30.0635219+00:00"},"os":{"type":"os","raw_description":"Microsoft Windows 10.0.22621"},"runtime":{"type":"runtime","name":".NET","version":"8.0.1","raw_description":".NET 8.0.1","identifier":"win-x64"},"trace":{"type":"trace","span_id":"02db862dae275625","trace_id":"2dc7a0586a45490798675268a6fa5460"}},"user":{"ip_address":"{{auto}}"},"environment":"production","sdk":{"packages":[{"name":"nuget:sentry.dotnet","version":"4.0.1"}],"name":"sentry.dotnet","version":"4.0.1"},"debug_meta":{"images":[{"type":"pe_dotnet","debug_id":"e6b30899-79dd-41cf-1786-998ca8e1fc89-4eb5f61c","debug_checksum":"SHA256:9908b3e6dd79cf411786998ca8e1fc891cf6b54e894f8e110f378ef2b599ead2","debug_file":"D:\\a\\_work\\1\\s\\artifacts\\obj\\System.Linq.Expressions\\Release\\net8.0\\System.Linq.Expressions.pdb","code_id":"B535A32F37f000","code_file":"C:\\Program Files\\PowerShell\\7\\System.Linq.Expressions.dll"},{"type":"pe_dotnet","debug_id":"30b1cfa3-ab4b-40d6-9bbe-0fa5d6c17442-c8630267","debug_checksum":"SHA256:a3cfb1304babd6001bbe0fa5d6c17442670263484ebb100c0ad76bd608b5794f","debug_file":"C:\\PowerShell\\src\\System.Management.Automation\\obj\\Release\\net8.0\\System.Management.Automation.pdb","code_id":"D499C0321301000","code_file":"C:\\Program Files\\PowerShell\\7\\System.Management.Automation.dll"},{"type":"pe_dotnet","debug_id":"844e9600-08a6-8b0b-4be3-8422f1ea6e8c-432266a4","debug_checksum":"SHA256:00964e84a6080b8b4be38422f1ea6e8ca466224372832a591cf5e74d7094cfb5","debug_file":"D:\\a\\_work\\1\\s\\artifacts\\obj\\coreclr\\System.Private.CoreLib\\x64\\Release\\System.Private.CoreLib.pdb","code_id":"E66F2FD4c8d000","code_file":"C:\\Program Files\\PowerShell\\7\\System.Private.CoreLib.dll"}]}}
Debug: De-queueing event fbe8faa0feec4bdcbedfe8a04a1d63ee
https://sentry-sdks.sentry.io/issues/4950791929/events/fbe8faa0feec4bdcbedfe8a04a1d63ee/
Windows PowerShell 5.1 doesn't work for me (net462 nor netstandard 2.0):
$ import-module 'C:\dev\dotnet\src\Sentry\bin\Debug\net462\Sentry.dll'
import-module : Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
At line:1 char:1
+ import-module 'C:\dev\dotnet\src\Sentry\bin\Debug\net462\Sentry.dll'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
Windows PowerShell 5.1 doesn't work for me (net462 nor netstandard 2.0):
$ import-module 'C:\dev\dotnet\src\Sentry\bin\Debug\net462\Sentry.dll' import-module : Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. At line:1 char:1 + import-module 'C:\dev\dotnet\src\Sentry\bin\Debug\net462\Sentry.dll' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
did u load the extra DLLs needed? https://www.nuget.org/packages/Sentry#dependencies-body-tab
System.Reflection.Metadata (>= 5.0.0) System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0) System.Text.Json (>= 6.0.8)
And all their dependencies, recursevely?
did u load the extra DLLs needed?
No, it's just a single line of code you see in the snippet (import-module
). I did not load any other libraries manually, not even sure that's a thing with powershell. Maybe the old powershell needs some custom module code to make work: https://github.com/PowerShell/PowerShell/issues/12004#issuecomment-594776477
Some resources:
I'm thinking we should have a separate repository for powershell instead of keeping it inside sentry-dotnet repo.
Let me start with the facts:
I've figured out Windows Powershell too, with manually loading Sentry.dll using [Reflection.Assembly]::LoadFrom
Created: https://github.com/getsentry/sentry-powershell (perms coming through https://github.com/getsentry/security-as-code/pull/608 )
Icon will be added to platformicons
so we can use on docs and wizard: https://github.com/getsentry/platformicons/pull/142
"pwsh@7.4.1 SHA: 6a98b28414948626f1b29a5e8b062e73b7ff165a+6a98b28414948626f1b29a5e8b062e73b7ff165a"
- do we want to leave that or is there a better value we can come up with automatically?~
I'd leave as is for nowMainExceptionProcessor
~ - we may need this for c# exceptionshttps://www.powershellgallery.com/packages/Sentry/
followups should be in new issues, or in a generic one like #27 if it's a one-liner
We can prob wrap
Sentry.dll
in a PS ModuleFrom the docs
We to be able to list versions we support. On Windows, it's tied to OS, so we might need to list OS versions. Or PS versions, as PS 5.1 for examples is built on .NET Framework 4.5.1 which we don't support.
We have several PowerShell scripts in the .NET/Unity repos. We can dogfood it there.