Skip to content

Code issue on article about OpenTelemetry and Application Insights #42467

Open
@drilko

Description

@drilko

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:

if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
{
    otel.UseAzureMonitor();
}

In step three it's recommended to add the following json to appsettings.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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions