-
Notifications
You must be signed in to change notification settings - Fork 57
How to Customize Telemetry Property Names
Saar Shen edited this page Jan 25, 2021
·
2 revisions
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"
...
}
}
- 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}""";