orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Application Insights Telemetry failing to initialize

Open dsarfati opened this issue 8 years ago • 7 comments

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.

dsarfati avatar Apr 03 '18 18:04 dsarfati

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.

xiazen avatar Apr 03 '18 21:04 xiazen

submitted a PR #4392 to fix this

xiazen avatar Apr 03 '18 22:04 xiazen

@xiazen Thanks! I actually ended up using option #2 until the fix is released. Thanks again for the help.

dsarfati avatar Apr 03 '18 22:04 dsarfati

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?

el2iot2 avatar Jun 12 '18 16:06 el2iot2

Looks like we simply missed it. I guess we can relatively easily release a 2.0.3 version of these packages. I'll check.

sergeybykov avatar Jun 13 '18 23:06 sergeybykov

I opened #4687 for that.

sergeybykov avatar Jun 13 '18 23:06 sergeybykov

These packages have been published.

sergeybykov avatar Jun 14 '18 00:06 sergeybykov