Skip to content

An example of how to get Python debugging in VisualStudio to work with Aspire

License

Notifications You must be signed in to change notification settings

CZEMacLeod/AspirePythonDebugging

Repository files navigation

Aspire Python Debugging in Visual Studio

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.

Examples

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 ASPIREHOSTINGPYTHON001

The 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.

About

An example of how to get Python debugging in VisualStudio to work with Aspire

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published