admin管理员组

文章数量:1123766

I am currently using Springboot Java to POC Azure Application Insight. I am able to send REQUEST and TRACE to Azure App Insight but I cannot append custom properties to enrich the REQUEST details

What I did to ingest the records are the following:

  1. Add the JAR for app insights
  2. Added POM dependency from azure app insights

Now what I need is to enrich the existing REQUEST records, I can add new REQUEST records but it duplicates the automatically added ones

Auto

Custom

I tried using different approach like

  1. TelemetryInitializer
  2. Adding properties in TelemetryContext

To no avail, it does not add in the properties.

I am currently using Springboot Java to POC Azure Application Insight. I am able to send REQUEST and TRACE to Azure App Insight but I cannot append custom properties to enrich the REQUEST details

What I did to ingest the records are the following:

  1. Add the JAR for app insights
  2. Added POM dependency from azure app insights

Now what I need is to enrich the existing REQUEST records, I can add new REQUEST records but it duplicates the automatically added ones

Auto

Custom

I tried using different approach like

  1. TelemetryInitializer
  2. Adding properties in TelemetryContext

To no avail, it does not add in the properties.

Share Improve this question asked yesterday JustExploringStuffJustExploringStuff 1 New contributor JustExploringStuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • The automatic telemetry collection provided by the Application Insights Java agent often does not allow direct modification of the telemetry items it generates. – Suresh Chikkam Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

If you're not seeing properties in the automatically tracked telemetry, check the TelemetryInitializer targets RequestTelemetry.

RequestTelemetryInitializer,java:

import com.microsoft.applicationinsights.telemetry.RequestTelemetry;
import com.microsoft.applicationinsights.telemetry.Telemetry;
import com.microsoft.applicationinsights.extensibility.TelemetryInitializer;

public class RequestTelemetryInitializer implements TelemetryInitializer {
    @Override
    public void initialize(Telemetry telemetry) {
        if (telemetry instanceof RequestTelemetry) {
            RequestTelemetry requestTelemetry = (RequestTelemetry) telemetry;
            requestTelemetry.getProperties().put("CustomProperty1", "CustomValue1");
            requestTelemetry.getProperties().put("CustomProperty2", "CustomValue2");
        }
    }
}

TelemetryInitializer is registered with the telemetry configuration.

ApplicationInsightsConfig.java:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.microsoft.applicationinsights.TelemetryConfiguration;

@Configuration
public class ApplicationInsightsConfig {
    @Bean
    public TelemetryInitializer requestTelemetryInitializer() {
        return new RequestTelemetryInitializer();
    }

    @Bean
    public TelemetryConfiguration telemetryConfiguration(TelemetryInitializer initializer) {
        TelemetryConfiguration configuration = TelemetryConfiguration.getActive();
        configuration.getTelemetryInitializers().add(initializer);
        return configuration;
    }
}
  • Once the TelemetryInitializer is active, custom properties should appear under the Request telemetry in Azure Application Insights.

Pom.xml:

<dependencies>
    <!-- Spring Boot Starter Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Spring Boot Actuator for metrics -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <!-- Azure Application Insights -->
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-spring-boot-starter</artifactId>
        <version>2.6.4</version>
    </dependency>
</dependencies>

The above screenshot shows that the custom property customPropertyKey with the value customPropertyValue has been successfully added to the Request telemetry in Azure Application Insights.

This confirms that the custom telemetry enrichment is working correctly.

本文标签: How to add custom properties to Azure Application Insights using Java Spring BootStack Overflow