sovan
sovan

Reputation: 479

Microsoft.ApplicationInsights Error: InstrumentationKey cannot be empty

I was trying to use Microsoft.ApplicationInsights, and I installed the same through nuget. but when I am trying to use

_telemetryClient.TrackException(ex, new Dictionary<string, string>
                                    {
                                         {"Id", id.ToString()}
                                    }, null);

I am getting an error saying: InstrumentationKey cannot be empty.

I have already gone through the URL but I can't see any Update menu available for the config file in my VS(Note: I am using VS 2012 Pro).

I have also tried updating the config file with the instrumentation key

<ComponentID>{Instrumentation Key}</ComponentID>

But, that didn't work too.

Thanks.

Upvotes: 5

Views: 10973

Answers (5)

wmioduszewski
wmioduszewski

Reputation: 146

In my case I just needed to add my IP to the Azure Database firewall - the InstrumentationKey fails before we get explanatory error about the firewall so it may be confusing.

Upvotes: 0

Rousonur Jaman
Rousonur Jaman

Reputation: 1271

Use this below code in your Configuration method.

Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = key;

Upvotes: 0

Anna Galaeva - MS
Anna Galaeva - MS

Reputation: 21

Did you download nuget manually or did you get it via UI by adding AppInsights to the project? We have seen this issue when users try to add individual nugget manually.

The easiest way to recover is to add full AppInsights support by right click on the project and choosing Update Application Insights - it will ask you to create new AI resource or point to existing AI resource and it will create instrumentation key for you.

But you'd need to use VS 2013 in order to have VS integration for Application Insights.

Upvotes: 2

vladjoanovic
vladjoanovic

Reputation: 581

i'm assuming you have added the .11 or later Application Insights SDK. if so add the instrumenation key to your applicationinsights.config file after adding the Application Insights SDK to your project like this:

</TelemetryInitializers>
<InstrumentationKey>your-guid-goes-ere</InstrumentationKey>
</ApplicationInsights>

Upvotes: 1

sovan
sovan

Reputation: 479

I still haven't found any solution in configuration level. However, We can provide the Instrumentation Key while initializing the TelemetryClient object:

var telemetryClient = new TelemetryClient(new TelemetryConfiguration()
                            {
                                InstrumentationKey = "Key"
                            });

Please don't hesitate to post an answer how can we provide the Instrumentation key through config.

Thanks.

Upvotes: 1

Related Questions