Application Insights Telemetry failing to initialize
I'm trying to add the Application Insights Telemetry to our 2.0 app and im getting the following exception
System.InvalidOperationException: Unable to resolve service for type 'System.String' while attempting to activate 'Orleans.TelemetryConsumers.AI.AITelemetryConsumer'.
Looking at the code it looks like the only constructor on the AITelemetryConsumer takes a string, causing the exception. Simply adding a DI compatible constructor should fix the issue. I'll submit a PR if this makes sense.
yeah that seems like a bug in our side. AITelemetryConsumer isn't using its own options ApplicationInsightsTelemetryConsumerOptions. So that user can configure the options to give a instrumentationKey,
To work around this, there's two options
- inject a string singleton to DI as instrumentalKey, so when AITelemetryConsumer is constructed through
ActivatorUtilities.CreateInstance(serviceProvider, consumerType);, ActivatorUtility would locate that string singleton and create AITelemetryConsumer. But this is risky since it assumes you can only have one string singleton in DI. so I'm not recommending this one. - create another AITelemetryConsumer based on the original one, something like
public class AITelemetryConsumer2 : AITelemetryConsumer
{
public AITelemetryConsumer2(IOptions<ApplicationInsightsTelemetryConsumerOptions> options)
:base(options.Value.InstrumentionKey)
{
}
}
And then you can configure it through IOptions.
new SiloHostBuilder.Configure<ApplicationInsightsTelemetryConsumerOptions>(configureOptions)
.Configure<TelemetryOptions>(options=>options.AddConsumer<AITelemetryConsumer2>)
- write your own TelemetryConsumer for AI
At the mean time, I will submit a pr to fix the bug, but the fix will be included in our next release. So if you don't want to wait, you can do either of the workaround.
submitted a PR #4392 to fix this
@xiazen Thanks! I actually ended up using option #2 until the fix is released. Thanks again for the help.
I see this is merged, but there is no new Microsoft.Orleans.OrleansTelemetryConsumers.AI package out with the updated bits (still 2.0.0 there)? Is that an oversight or pending for another reason?
Looks like we simply missed it. I guess we can relatively easily release a 2.0.3 version of these packages. I'll check.
I opened #4687 for that.
These packages have been published.