Skip to content

Gracefully handle missing ConnectionString in v3 #3110

@ArturDorochowicz

Description

@ArturDorochowicz

Is your feature request related to a problem?
In versions before 3.0, the library gracefully handled missing ConnectionString (or InstrumentationKey earlier).
This does not work anymore in v3 and causes an exception at startup from Azure Monitor Exporter.

In earlier versions you could not supply the connection string, e.g. in development or test environments, and things just worked (I think). You could normally resolve and use TelemetryConfiguration or TelemetryClient.

It's not clear how to resolve this. One could run AddApplicationInsightsTelemetry conditionally depending on the connection string presence. Aspire templates suggest something like this (though against Azure Monitor distro direcly). But this is problematic. For one, there's more than one way to supply the connection string (APPLICATIONINSIGHTS_CONNECTION_STRING, ApplicationInsights:ConnectionString, possibly others). And then of course we still wouldn't have TelemetryClient, TelemetryConfiguration in the DI and would need to work around that if the app uses those.

https://github.com/dotnet/aspire/blob/6e0fa878c605034669c864ff56c9d084af4a560f/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs#L90-L95

Describe the solution you'd like.

I'd like for this to work like in earlier versions, which I believe was for the library to gracefully handle a missing connection string, i.e. I can resolve a TelemetryClient, it just doesn't do anything.

Describe alternatives you've considered.
Which alternative solutions or features have you considered?

Additional context.
Add any other context about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions