microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
296 stars 199 forks source link

Operation ID, Operation Name and Operation Parent ID are empty in AppInsights in Java SDK 2.6.4 #3954

Open ramolapereira opened 5 days ago

ramolapereira commented 5 days ago

Dependencies used:

com.microsoft.azure applicationinsights-logging-log4j2 2.6.4 com.microsoft.azure applicationinsights-core 2.6.4 com.microsoft.azure applicationinsights-web 2.6.4

Operation ID, Operation Name and Operation Parent ID are empty in AppInsights.

Tried to set these values in Java using RequestTelemetryContext. Even then these 3 are empty in AppInsights.

import com.microsoft.applicationinsights.web.internal.RequestTelemetryContext; import com.microsoft.applicationinsights.web.internal.ThreadContext;

import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger;

public class Controller { private static final Logger logger = LogManager.getLogger(Controller.class);

public String sendTelemetry (String operationId, String operationName, String operationParentId) {
    try {

        logger.info("START - Set Operation ID, Operation Name, Operation Parent ID");

            RequestTelemetryContext context = new RequestTelemetryContext(1);
            context.getHttpRequestTelemetry().getContext().getOperation().setId("12345");
            context.getHttpRequestTelemetry().getContext().getOperation().setName("Test Operation Name");
        context.getHttpRequestTelemetry().getContext().getOperation().setParentId("67890");
            ThreadContext.setRequestTelemetryContext(context);

        logger.info("END - Set Operation ID, Operation Name, Operation Parent ID");         
    }
    catch (Exception e) {

    }
}   

}

Both the loggers are sent to AppInsights with empty values for these 3 fields. Tried setting 12 digit values to Operation ID too.

trask commented 4 days ago

hi @ramolapereira, can you use 3.x? 2.x will be retired soon

ramola-pereira commented 4 days ago

Hi @trask ,

We followed the POC provided by MuleSoft here: MuleSoft AppInsights POC

As we have our apps deployed on CloudHub, they don't support use of -javaagent on Cloudhub or Runtime Fabric at this time, hence we cannot upgrade to 3.X as it requires Javaagent.

jeanbisutti commented 3 days ago

@ramolapereira You could use this instrumentation library with this exporter.