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:
- Add the JAR for app insights
- 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
- TelemetryInitializer
- 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:
- Add the JAR for app insights
- 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
- TelemetryInitializer
- 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
1 Answer
Reset to default 0If 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
版权声明:本文标题:How to add custom properties to Azure Application Insights using Java Spring Boot - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736597244a1945168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论