Allows debugging Python code in Visual Studio, when using Aspire.
Uses the C3D.Extensions.Aspire.VisualStudioDebug package from CZEMacLeod/C3D.Extensions.Aspire.
All functionality is encapsuled in the PythonDebuggerExtensions.cs file, which is included in the main AppHost project here.
I may move this to a separate project under C3D.Extensions.Aspire in the future.
Warning
I am not a python developer, so please forgive any mistakes in the code. I am happy to receive feedback and suggestions for improvement.
The OTLP/Open Telemetry integration for Python works, but I could not get the logging part to behave.
There are 2 projects included, one Flask web server, and one console application. They both work.
I've included an overload for AddPythonApp which uses a project reference to the Python project, so you don't have to pass the path.
The only other call needed is WithDebugger on a PythonAppResource resource builder.
#pragma warning disable ASPIREHOSTINGPYTHON001
builder.AddPythonApp<Projects.PythonConsoleProject>("console", "main.py")
.WithNoConsoleTelemetry()
.WithDebugger();
builder.AddPythonApp< Projects.PythonWebProject>("web", "main.py")
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints()
.WithNoConsoleTelemetry()
.WithDebugger();
#pragma warning restore ASPIREHOSTINGPYTHON001The WithNoConsoleTelemetry call adjusts the default log exporter to only output to otlp, and not to the console.
It replaces the command line argument --logs_exporter console,otlp with --logs_exporter otlp.