Skip to content

Commit 4682fcc

Browse files
Merge pull request #242266 from toddfoust/patch-24
clarifying connection string usage
2 parents c7443b6 + 97fc50e commit 4682fcc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

articles/azure-monitor/app/sdk-connection-string.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,45 @@ Connection string: `APPLICATIONINSIGHTS_CONNECTION_STRING`
163163

164164
# [.NET 5.0+](#tab/dotnet5)
165165

166-
1. Set the instrumentation key in the `appsettings.json` file:
166+
1. Set the connection string in the `appsettings.json` file:
167167

168168
```json
169169
{
170170
"ApplicationInsights": {
171-
"InstrumentationKey" : "InstrumentationKey=00000000-0000-0000-0000-000000000000;"
171+
"ConnectionString" : "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/"
172172
}
173173
}
174174
```
175175

176-
2. Retrieve the instrumentation key in `Program.cs` when registering the `ApplicationInsightsTelemetry` service:
176+
2. Retrieve the connection string in `Program.cs` when registering the `ApplicationInsightsTelemetry` service:
177177

178178
```csharp
179-
var options = new ApplicationInsightsServiceOptions { ConnectionString = app.Configuration["ApplicationInsights:InstrumentationKey"] };
179+
var options = new ApplicationInsightsServiceOptions { ConnectionString = app.Configuration["ApplicationInsights:ConnectionString"] };
180180
builder.Services.AddApplicationInsightsTelemetry(options: options);
181181
```
182182

183183
> [!NOTE]
184-
> When deploying applications to Azure in production scenarios, consider placing instrumentation keys or other configuration secrets in secure locations such as App Service configuration settings or Azure Key Vault. Avoid including secrets in your application code or checking them into source control where they might be exposed or misused. The preceding code example will also work if the instrumentation key is stored in App Service configuration settings. Learn more about [configuring App Service settings](/azure/app-service/configure-common).
184+
> When deploying applications to Azure in production scenarios, consider placing connection strings or other configuration secrets in secure locations such as App Service configuration settings or Azure Key Vault. Avoid including secrets in your application code or checking them into source control where they might be exposed or misused. The preceding code example will also work if the connection string is stored in App Service configuration settings. Learn more about [configuring App Service settings](/azure/app-service/configure-common).
185185

186186
# [.NET Framework](#tab/dotnet-framework)
187187

188188
Set the property [TelemetryConfiguration.ConnectionString](https://github.com/microsoft/ApplicationInsights-dotnet/blob/add45ceed35a817dc7202ec07d3df1672d1f610d/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs#L271-L274) or [ApplicationInsightsServiceOptions.ConnectionString](https://github.com/microsoft/ApplicationInsights-dotnet/blob/81288f26921df1e8e713d31e7e9c2187ac9e6590/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs#L66-L69).
189189

190-
Explicitly set the instrumentation key in code:
190+
Explicitly set the connection string in code:
191191

192192
```csharp
193193
var configuration = new TelemetryConfiguration
194194
{
195-
ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;"
195+
ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/"
196196
};
197197
```
198198

199-
Set the instrumentation key using a configuration file:
199+
Set the connection string using a configuration file:
200200

201201
```xml
202202
<?xml version="1.0" encoding="utf-8"?>
203203
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
204-
<ConnectionString>InstrumentationKey=00000000-0000-0000-0000-000000000000</ConnectionString>
204+
<ConnectionString>InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/</ConnectionString>
205205
</ApplicationInsights>
206206
```
207207

@@ -211,7 +211,7 @@ You can set the connection string in the `applicationinsights.json` configuratio
211211

212212
```json
213213
{
214-
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000"
214+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/"
215215
}
216216
```
217217

@@ -238,7 +238,7 @@ JavaScript doesn't support the use of environment variables. You have two option
238238

239239
```javascript
240240
const appInsights = require("applicationinsights");
241-
appInsights.setup("InstrumentationKey=00000000-0000-0000-0000-000000000000;");
241+
appInsights.setup("InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/");
242242
appInsights.start();
243243
```
244244

@@ -253,7 +253,7 @@ from opencensus.ext.azure.trace_exporter import AzureExporter
253253
from opencensus.trace.samplers import ProbabilitySampler
254254
from opencensus.trace.tracer import Tracer
255255

256-
tracer = Tracer(exporter=AzureExporter(connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000'), sampler=ProbabilitySampler(1.0))
256+
tracer = Tracer(exporter=AzureExporter(connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/'), sampler=ProbabilitySampler(1.0))
257257
```
258258

259259
---

0 commit comments

Comments
 (0)