dotnet / dotnet/docs

Code issue on article about OpenTelemetry and Application Insights

Open
#42,467 0 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc in-pr
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

### Type of issue

Code doesn't work

### Description

There is a small issue in the article which prevents the sample code from working.
In step two the following code is added:
```csharp
if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
{
otel.UseAzureMonitor();
}
```
In step three it's recommended to add the following json to `appsettings.json`:
```json
"AzureMonitor": {
"ConnectionString": "InstrumentationKey=12345678-abcd-abcd-abcd-12345678..."
}
```

Because of this `otel.UseAzureMonitor();` is never called.
An easy fix would be to update code in step 2 as so:
```csharp
if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] ?? builder.Configuration["AzureMonitor:ConnectionString"]))
{
otel.UseAzureMonitor();
}
```
or something similar.

Thank you!

### Page URL

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/observability-applicationinsights

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/diagnostics/observability-applicationinsights.md

### Document Version Independent Id

e14803f7-d5c7-657a-763c-680cf4197365

### Article author

@tommcdon

### Metadata

* ID: 45cce027-ad78-e3d1-7144-6091a9b5f023
* Service: **dotnet-fundamentals**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.