Страница:
How to Customize Telemetry Property Names
Страницы
3.x or 6.x, which version to use?
Design for ContainerIdProviders
Design: Container id is optional while pod name required
Development Guide
FAQ
Getting Started for .NET Core Applications
Getting Started for ASP.NET Core Applications
Home
Hosting startup for ApplicationInsights.Kubernetes
How to Customize Telemetry Property Names
How to provide container name for telemetry
[Advanced] How to enable self diagnostics for ApplicationInsights.Kubernetes
[Azure Function Support] Using Application Insights for Kubernetes in Azure Functions hosted in K8s cluster
2
How to Customize Telemetry Property Names
Saar Shen редактировал(а) эту страницу 2021-01-25 11:46:32 -08:00
Содержание
Description
By default, ApplicationInsights-Kubernetes
enriches all telemetry entries with Kubernetes info like the container name and so on. The format of the telemetry property names look like this:
{
"customDimensions":
{
// Leading with "Kubernetes", then resource of "Container", then property of "Name".
// The default separator is dot(".").
"Kubernetes.Container.Name": "ai-k8s-basic-container"
...
}
}
It works well for most cases, except we have a report that this format is conflicting with other systems, that doesn't work well when dot(.
) is used as a separator. Refer to #222 for details.
Since there's no way for us to come up with a rule to deal with all constraints by other systems, in version 1.1.4 (or higher), there is a way to customize the telemetry keys used for Application Insights Kubernetes
.
Here's the usage:
services.AddApplicationInsightsKubernetesEnricher(options =>
{
// options.TelemetryKeyProcessor accepts a Func<string, string>. It takes in the originalkey, and returns the processed key.
// Here we replace '.' with '_' but it could actually be any custom logic.
options.TelemetryKeyProcessor = (key) => key.Replace('.', '_');
});
The telemetry will look like:
{
"customDimensions":
{
// Kubernetes.Container.Name becomes Kubernetes_Container_Name
"Kubernetes_Container_Name": "ai-k8s-basic-container"
...
}
}
Examples:
- Remove the separator:
// Kubernetes.Container.Name becomes KubernetesContainerName
options.TelemetryKeyProcessor = (key) => key.Replace(".", "");
- Add quotes to the key:
// Kubernetes.Container.Name becomes "Kubernetes.Container.Name"
options.TelemetryKeyProcessor = (key) => $@"""{key}""";