In Application Insights,using Java SDK I am trying to add new properties to all telemetry data by overriding Initialize method of telemetry Initializer but this doesn't seem to be working ?

Adarsh 0 Reputation points Microsoft Employee

My application has Beans that instantiates telemetry client with required telemetry configuration and custom telemetry initializer in the following way shown below.

TelemetryConfiguration telemetryConfiguration() {  
TelemetryConfiguration telemetryConfiguration= TelemetryConfiguration.getActive();  telemetryConfiguration.setInstrumentationKey(instrumentationKey);  telemetryConfiguration.getTelemetryInitializers().add(customTelemetryInitializer);  
return telemetryConfiguration;}
TelemetryClient azureMonitor(TelemetryConfiguration telemetryConfiguration) {  return new TelemetryClient(telemetryConfiguration);

And my customInitializer has this code to add new properties:

@Setter private String id;
@Setter private String name;

public void initialize(Telemetry telemetry) {  
if (telemetry.getContext().getCloud().getRoleInstance() != null) {       telemetry.getContext().getProperties().put("id", id);    telemetry.getContext().getProperties().put("name", name);    

I expected that the id and name would be set(in a service that gets executed for every request) and is shown in every appinsights table even if the code does not have any usage of TelemetryClient and calling methods like TrackEvent or TrackMetric or TrackException or TrackTrace? The SDK automatically collects request telemetry, traces , dependencies and will this override put the properties before sending to appinsights? Not sure if ApplicationInsights.json plays a role in these kind of works.

Also is there any document on how initializer can be implemented and used in JAVA? I could find the document only for C# and JavaScript.
Any help would be greatly appreciated. Thanks!

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,489 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 22,911 Reputation points Microsoft Employee
    0 comments No comments