c1368b7695
* Adding missed spot of hosting startup. * Add dependency between release and debug * Update CI * Simplify and parallel ci builds |
||
---|---|---|
.github/workflows | ||
build | ||
dev | ||
docs | ||
examples | ||
src | ||
tests | ||
troubleshooting | ||
.editorconfig | ||
.gitignore | ||
ApplicationInsights.Kubernetes.sln | ||
LICENSE | ||
NuGet.config | ||
README.md | ||
SECURITY.md | ||
solution.code-workspace |
README.md
Microsoft Application Insights for Kubernetes
Application Insights for Kubernetes enhances telemetries with K8s properties, works for .NET Core/.NET 6 applications in Kubernetes clusters.
⚠️
Microsoft Application Insights for Kubernetes
(this library) is an enhancement to the Microsoft Application Insights. You can choose to run Application Insights without this library in a Kubernetes cluster. However, withMicrosoft Application Insights for Kubernetes
, you will see Kubernetes-related properties like Pod-Name, Deployment ... on all your telemetry entries. Proper values will also be set to make use of the rich features like enabling the Application Map to show the multiple microservices/roles on the same application insights map.
Continuous Integration Status
Rolling Build | Nightly Build |
---|---|
Get Started
This is a quick guide for ASP.NET Core projects.
Prerequisite
⚠️ For RBAC-enabled Kubernetes, make sure permissions are configured.
Instrument an ASP.NET Core application
⚠️ This is for ASP.NET Core application. See instructions for workers in the Walk-through section below.
-
Add references to Application Insights SDK and Application Insights for Kubernetes:
dotnet add package Microsoft.ApplicationInsights.AspNetCore dotnet add package Microsoft.ApplicationInsights.Kubernetes
-
Enable Application Insights and Application Insights for Kubernetes Enricher in
Startup.cs
:public void ConfigureServices(IServiceCollection services) { ... services.AddApplicationInsightsTelemetry("----Your Application Insights Instrumentation Key ----"); services.AddApplicationInsightsKubernetesEnricher(); services.AddMvc(); ... }
-
Build the application in containers, then deploy the container with Kubernetes.
Notes: Those steps are not considered the best practice to set the instrumentation key for application insights. Refer to Enable Application Insights server-side telemetry for various options. Also, consider deploying Kubernetes Secrets to secure it. Refer to Deploy the application in Kubernetes for an example.
Walk-through with example code
- Enable Application Insights for Kubernetes on WebAPI (Controller based or Minimal API).
- Enable Application Insights Kubernetes in worker project.
Customize Configurations
Customize configurations are supported. There are several ways to customize the settings. For example:
-
Using code:
services.AddApplicationInsightsKubernetesEnricher(option=> { option.InitializationTimeout = TimeSpan.FromSeconds(15); });
-
Using
appsettings.json
:{ "Logging": { // ... }, // Adding the following section to set the timeout to 15 seconds "AppInsightsForKubernetes": { "InitializationTimeout": "00:00:15" } }
-
Using environment variables:
AppInsightsForKubernetes__InitializationTimeout=3.1:12:15.34
All the related configurations have to be put in a section named
AppInsightsForKubernetes
. The supported keys/values are listed below:Key Value/Types Default Value Description InitializationTimeout TimeSpan 00:02:00 Maximum time to wait for spinning up the container. Accepted format: [d.]hh:mm:ss[.fffffff]. ClusterInfoRefreshInterval TimeSpan 00:10:00 For 3.x only. Get or sets how frequent to refresh the Kubernetes cluster properties. DisablePerformanceCounters Boolean false Deprecated. Sets to true to avoid adding performance counter telemetry initializer.
Tips: Refer to AppInsightsForKubernetesOptions.cs for the latest customization supported.
The configuration uses the ASP.NET Core conventions. Refer to Configuration in ASP.NET Core for more information.
Verify the cluster configuration (Linux Container only)
Use the troubleshooting image to verify the cluster is properly configured.
Learn more
- To build a container for Kubernetes that have Application Insights baked in for the existing applications, please refer to the example of Zero Code light up.
- To enable diagnostic logs when Application Insights for Kubernetes doesn't work as expected, reference How to enable self diagnostics for ApplicationInsights.Kubernetes.
- Still want more? Read the Wikis.
Next step
Profile your application for performance improvement using Application Insights Profiler for Linux.
Contributing
Report issues
Please file bug, discussion or any other interesting topics in issues on GitHub.
Troubleshooting
Read the FAQ for common issues. When Microsoft.ApplicationInsights.Kubernetes doesn't work properly, you can turn on self-diagnostics to see the traces in Kubernetes' logs. Refer to How to enable self diagnostics for ApplicationInsights.Kubernetes for instructions.
Developing
Please refer the Develop Guide.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.