Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Commented Out Code for Azure Native Monitoring #464

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mattmccleary
Copy link

No description provided.

Copy link
Member

@samsp-msft samsp-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have this option in the app. Thoughts on how to make it cleaner?

@@ -18,9 +18,14 @@

var launchProfileName = ShouldUseHttpForEndpoints() ? "http" : "https";

// To configure Azure Monitor Application Insights, add the following:
// var insights = builder.AddConnectionString("myInsightsResource", "APPLICATIONINSIGHTS_CONNECTION_STRING");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced with a conditional such as

var appInsights = (builder.Configuration.GetConnectionString("myAppInsightsResource") is not null)? 
    builder.AddConnectionString(
        "myAppInsightsResource",
        "APPLICATIONINSIGHTS_CONNECTION_STRING")
    : null;

// Services
var identityApi = builder.AddProject<Projects.Identity_API>("identity-api", launchProfileName)
.WithExternalHttpEndpoints()
// .WithReference(insights) // Sample reference to Azure Monitor Application Insights. Copy/paste for each service.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to add an overload to have a conditional reference, but it already seems to be there, so the following could be added to each app and not need to be commented out. It should silently ignore it if the resource is null.

    .WithReference(appInsights,null,true);

@mitchdenny - It turns out this doesn't work as the resource parameter isn't nullable. Is there a cleaner workaround?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the .WithReference doesn't like that appInsights could be null.
image

Copy link
Member

@mitchdenny mitchdenny Jul 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use a conditional? I'm not sure we want to invent a new API for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchdenny conditionals don't fit nicely into the chained builder pattern, unless there is something I don't know?

src/eShop.AppHost/appsettings.json Outdated Show resolved Hide resolved
@mattmccleary
Copy link
Author

@dotnet-policy-service agree company="Microsoft"

@mattmccleary
Copy link
Author

@samsp-msft Thoughts on my latest push? I added conditionals to each service reference.

@samsp-msft
Copy link
Member

@samsp-msft Thoughts on my latest push? I added conditionals to each service reference.

If necessary, we can do that, but I really would prefer an ability to do a conditional cleanly in the apphost as its going to be a pretty common scenario.

@mitchdenny - How can we make conditionals clean in the apphost file?

@samsp-msft
Copy link
Member

We met and discussed the options - nothing is available right now that makes this cleaner. we should go in with the commented out blocks, and @mitchdenny will file an issue for adding a conditional in the builder pattern.

@mitchdenny
Copy link
Member

Issue: dotnet/aspire#5192

@BrennanConroy
Copy link
Member

Azure specific components are included in eShopOnAzure.

AppInsights (Azure Monitoring) is already included in eShopOnAzure: https://github.com/Azure-Samples/eShopOnAzure/blob/9da1eccec3454b19cd11a9b44001cd0323deb749/src/eShop.AppHost/Program.cs#L10

@mattmccleary
Copy link
Author

mattmccleary commented Sep 26, 2024

Great to see this on eShopOnAzure!!

I tested it and got it to run...but ran into a few issues along the way.

  1. Needed to update Aspire.Hosting.AppHost and Grpc.Tools packages to eliminate errors.
  2. Needed to update Azure.Monitor.OpenTelemetry.AspNetCore for Live Metrics, a key feature
  3. Several Projects basket-api, catalog-api, order-processor, ordering-api, payment-processor, and webapp, webhooks-api ran for a short amount of time then shows State "Finished" on the Aspire Viewer. All other Projects, Containers, and Databases showed as "Running".

Also, I needed to add a Connection String to appsettings.json. Should we document that somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants