Hide instrumentationKey from the client #231
-
|
Ivan provided a beautiful explanation on how to set up "Application Insights for Blazor web applications". I was wondering if there was a way to set up Applications Insights but hide the Instrumentation Key to users in the browser ? I will leave here the current set up I have for Application Insights in Blazor : {
...
"Telemetry": {
...
"InstrumentationKey": "..."
}
...
}wwwroot\index.html <!DOCTYPE html>
<html lang="en">
<head>
...
<script>
...
cfg: {
instrumentationKey: "", // leave this blank
disableFetchTracking: false,
enableCorsCorrelation: true,
enableRequestHeaderTracking: true,
enableResponseHeaderTracking: true
}
...
</script>
</head>
<body>
</body>
</html>Program.cs using BlazorApplicationInsights;
using BlazorApplicationInsights.Sample;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
public class Program
{
public static async Task Main(string[] args)
{
...
builder.Services.AddBlazorApplicationInsights(async applicationInsights =>
{
var instrumentationKey = builder.Configuration.GetSection("Telemetry").GetValue<string>("InstrumentationKey");
await applicationInsights.SetInstrumentationKey(
instrumentationKey ?? "..."
);
});
...
}
}Note :
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
There is no way to hide the instrumentation key from the client, it is exposed in a number of places like JavaScript and every http request to AppInsights. |
Beta Was this translation helpful? Give feedback.

There is no way to hide the instrumentation key from the client, it is exposed in a number of places like JavaScript and every http request to AppInsights.