Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments: remove .NET prefix and hardcode streamlit ex…
…ecutable

Co-authored-by: tommasodotNET <12819039+tommasodotNET@users.noreply.github.com>
  • Loading branch information
Copilot and tommasodotNET committed Nov 6, 2025
commit 31c6448ba41f4213eea7b42b2a3434f6607664e0
2 changes: 1 addition & 1 deletion examples/python/streamlit-api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Streamlit API Example

This is a simple Streamlit application that demonstrates how to run Streamlit apps in .NET Aspire using the Python Extensions.
This is a simple Streamlit application that demonstrates how to run Streamlit apps in Aspire using the Python Extensions.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion examples/python/streamlit-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

st.title("Hello, Aspire!")

st.write("This is a simple Streamlit app running in .NET Aspire.")
st.write("This is a simple Streamlit app running in Aspire.")

port = os.environ.get("PORT", "8501")
st.write(f"Running on port: {port}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Python;
using CommunityToolkit.Aspire.Utils;

namespace Aspire.Hosting;
Expand Down Expand Up @@ -46,17 +45,9 @@ private static IResourceBuilder<StreamlitAppResource> AddStreamlitApp(

projectDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, wd));

var virtualEnvironment = new VirtualEnvironment(Path.IsPathRooted(virtualEnvironmentPath)
? virtualEnvironmentPath
: Path.Join(projectDirectory, virtualEnvironmentPath));
var projectResource = new StreamlitAppResource(name, projectDirectory);

var instrumentationExecutable = virtualEnvironment.GetExecutable("opentelemetry-instrument");
var streamlitExecutable = virtualEnvironment.GetExecutable("streamlit") ?? "streamlit";
var projectExecutable = instrumentationExecutable ?? streamlitExecutable;

var projectResource = new StreamlitAppResource(name, projectExecutable, projectDirectory);

var resourceBuilder = builder.AddResource(projectResource)
return builder.AddResource(projectResource)
.WithEnvironment(context =>
{
// Streamlit uses STREAMLIT_SERVER_PORT instead of PORT, so map PORT to STREAMLIT_SERVER_PORT
Expand All @@ -67,28 +58,8 @@ private static IResourceBuilder<StreamlitAppResource> AddStreamlitApp(
})
.WithArgs(context =>
{
// If the project is to be automatically instrumented, add the instrumentation executable arguments first.
if (!string.IsNullOrEmpty(instrumentationExecutable))
{
AddOpenTelemetryArguments(context);

// Add the streamlit executable as the next argument so we can run the project.
context.Args.Add("streamlit");
}

AddProjectArguments(scriptPath, args, context);
});

if (!string.IsNullOrEmpty(instrumentationExecutable))
{
resourceBuilder.WithOtlpExporter();

// Make sure to attach the logging instrumentation setting, so we can capture logs.
// Without this you'll need to configure logging yourself. Which is kind of a pain.
resourceBuilder.WithEnvironment("OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED", "true");
}

return resourceBuilder;
}

private static void AddProjectArguments(string scriptPath, string[] scriptArgs, CommandLineArgsCallbackContext context)
Expand All @@ -105,16 +76,4 @@ private static void AddProjectArguments(string scriptPath, string[] scriptArgs,
context.Args.Add(arg);
}
}

private static void AddOpenTelemetryArguments(CommandLineArgsCallbackContext context)
{
context.Args.Add("--traces_exporter");
context.Args.Add("otlp");

context.Args.Add("--logs_exporter");
context.Args.Add("console,otlp");

context.Args.Add("--metrics_exporter");
context.Args.Add("otlp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Aspire.Hosting.ApplicationModel;
/// Represents a Streamlit application.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="executablePath">The path to the executable used to run the python app.</param>
/// <param name="workingDirectory">The working directory for streamlit.</param>
public class StreamlitAppResource(string name, string executablePath, string workingDirectory)
: PythonAppResource(name, executablePath, workingDirectory), IResourceWithServiceDiscovery;
public class StreamlitAppResource(string name, string workingDirectory)
: PythonAppResource(name, "streamlit", workingDirectory), IResourceWithServiceDiscovery;