Skip to content

Commit 691d4e5

Browse files
author
Timothy Mothra
authored
update connection string options
1 parent d298c24 commit 691d4e5

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

articles/azure-monitor/app/opentelemetry-configuration.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,43 @@ A connection string in Application Insights defines the target location for send
2020

2121
### [.NET](#tab/net)
2222

23-
Add `UseAzureMonitor()` to your application startup. Depending on your version of .NET, this will be in either your `startup.cs` or `program.cs` class.
23+
Use one of the following three ways to configure the connection string:
2424

25-
```csharp
26-
using Azure.Monitor.OpenTelemetry.AspNetCore;
27-
using Microsoft.AspNetCore.Builder;
28-
using Microsoft.Extensions.DependencyInjection;
25+
- Add `UseAzureMonitor()` to your application startup. Depending on your version of .NET, this will be in either your `startup.cs` or `program.cs` class.
26+
```csharp
27+
using Azure.Monitor.OpenTelemetry.AspNetCore;
28+
using Microsoft.AspNetCore.Builder;
29+
using Microsoft.Extensions.DependencyInjection;
2930

30-
var builder = WebApplication.CreateBuilder(args);
31+
var builder = WebApplication.CreateBuilder(args);
3132

32-
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
33-
//Uncomment the line below when setting the Application Insights Connection String via code
34-
//options.ConnectionString = "<Your Connection String>";
35-
});
33+
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
34+
//Uncomment the line below when setting the Application Insights Connection String via code
35+
//options.ConnectionString = "<Your Connection String>";
36+
});
3637

37-
var app = builder.Build();
38+
var app = builder.Build();
3839

39-
app.Run();
40-
```
40+
app.Run();
41+
```
42+
- Set an environment variable:
43+
```console
44+
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
45+
```
46+
- Add the following section to your `appsettings.json` config file:
47+
```json
48+
{
49+
"AzureMonitor": {
50+
"ConnectionString": "<Your Connection String>"
51+
}
52+
}
53+
```
54+
55+
> [!NOTE]
56+
> If you set the connection string in more than one place, we adhere to the following precendence:
57+
> 1. Code
58+
> 2. Environment Variable
59+
> 3. Configuration File
4160

4261
### [Java](#tab/java)
4362

0 commit comments

Comments
 (0)