Enrich the telemetry data for .NET applications running inside containers that are managed by Kubernetes.
Перейти к файлу
Jacob Bovee 3d2bd0827f
Add initial StringUtils benchmark (#373)
2024-10-24 15:22:43 -07:00
.github Update issue templates 2023-04-04 11:12:32 -07:00
build Dev/saars/split service collection (#151) 2018-11-19 11:01:28 -08:00
dev Clean up lifetime of registered services (#309) 2022-09-08 16:08:19 -07:00
docs Support telemetry enhancement without cluster role (#305) 2022-09-02 10:13:09 -07:00
examples Update Readme.md 2024-07-16 15:13:32 -07:00
src Add initial StringUtils benchmark (#373) 2024-10-24 15:22:43 -07:00
tests Add initial StringUtils benchmark (#373) 2024-10-24 15:22:43 -07:00
troubleshooting Dev/saars/compliance docker registry (#263) 2022-05-23 11:23:28 -07:00
.editorconfig Dev/saars/container id fallback (#247) 2022-03-18 14:12:25 -07:00
.gitignore Add initial StringUtils benchmark (#373) 2024-10-24 15:22:43 -07:00
ApplicationInsights.Kubernetes.sln Dev/saars/container id fallback (#247) 2022-03-18 14:12:25 -07:00
LICENSE Update LICENSE 2017-05-05 15:53:56 -07:00
NuGet.config Clean up nuget feeds (#227) 2021-04-01 17:25:48 -07:00
README.md Update README.md 2024-07-19 10:27:49 -07:00
SECURITY.md Microsoft mandatory file (#254) (#256) 2022-05-19 08:42:47 -07:00
solution.code-workspace Dev/saars/improve svc collector (#224) 2021-04-01 16:37:59 -07:00

README.md

Microsoft Application Insights for Kubernetes

Nuget Downloads

Application Insights for Kubernetes enhances telemetries with K8s properties, works for .NET Core/.NET 6 applications in Kubernetes clusters.

Screenshot for Application Insights for Kubernetes enhanced telemetry

⚠️ Microsoft Application Insights for Kubernetes (this library) is designed to improve the functionality of Microsoft Application Insights. While it is possible to run Application Insights on a Kubernetes cluster without this library, it allows for Kubernetes-specific properties such as Pod-Name and Deployment to be included in all telemetry entries. Additionally, the library ensures that appropriate values are assigned, enabling advanced features like the Application Map to display multiple microservices or roles on a single Application Insights map.

Continuous Integration Status

Rolling Build Nightly Build
Rolling-Build Status Nightly-Build Status

Get Started

This is a quick guide for ASP.NET Core projects. If you want to run it in a worker, see the instructions in the Walk-through section.

Prerequisite

⚠️ For RBAC-enabled Kubernetes, make sure permissions are configured.

Instrument an ASP.NET Core application

  1. Add references to Application Insights SDK and Application Insights for Kubernetes by running:

    dotnet add package Microsoft.ApplicationInsights.AspNetCore
    dotnet add package Microsoft.ApplicationInsights.Kubernetes
    
  2. Enable Application Insights and Application Insights for Kubernetes Enricher in Startup.cs / Program.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddApplicationInsightsTelemetry("----Your Application Insights Instrumentation Key ----");
        services.AddApplicationInsightsKubernetesEnricher();
        ...
    }
    
  3. 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

Customize Configurations

Customize configurations are supported. There are several ways to customize the settings. For example:

  1. Using code:

    services.AddApplicationInsightsKubernetesEnricher(option=> {
        option.InitializationTimeout = TimeSpan.FromSeconds(15);
    });
    
  2. Using appsettings.json:

    {
        "Logging": {
            // ...
        },
        // Adding the following section to set the timeout to 15 seconds
        "AppInsightsForKubernetes": {
            "InitializationTimeout": "00:00:15"
        }
    }
    
  3. 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 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

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.