Skip to content

ThreadContext.getRequestTelemetryContext().getRequestTelemetry().setDuration() is not supported by the Application Insights for Java 3.x agent #2808

@rangarnow

Description

@rangarnow

Expected behavior

ThreadContext.getRequestTelemetryContext().getRequestTelemetry().setDuration() method is invoked without errors resulting changed duration of request.

This is needed, because we are receiving message which is then processed asynchronously. Then we have subscribe on Mono result, so in fact I would like to see real time of processing (including subscribe invocation), that's why the need to modify duration of the request programatically.

There is an example code showing my problem and workaround I try to have with ThreadContext.getRequestTelemetryContext().getRequestTelemetry().setDuration():

public void processMessage() {
   long startTime = System.currentTimeMillis();
   RequestTelemetryContext telemetryContext = ThreadContext.getRequestTelemetryContext();
   RequestTelemetry requestTelemetry = telemetryContext.getHttpRequestTelemetry();

   someAsyncTask().subscribe(data -> {
      long endTime = System.currentTimeMillis();
      requestTelemetry.setDuration(new Duration(endTime - startTime)); // Warning is thrown, has no effect

      // This works, but I would like to have parent request with real time, not a dependency
      RemoteDependencyTelemetry telemetry = new RemoteDependencyTelemetry();
      telemetry.setId(requestTelemetry.getId());
      telemetry.setName("Processing time 2");
      telemetry.setDuration(new Duration(endTime - startTime));
   });     
}

Effect:
image

If you have any other idea how to make ServiceBus.process (other than via setting Duration) to take the same time as "Processing time 2" it would be welcome.

I tried also with open telemetry API (given #1442 (comment)), but still no luck:

Span currentSpan = Span.current();
SpanContext spanContext =
                SpanContext.createFromRemoteParent(
                        currentSpan.getSpanContext().getTraceId(), currentSpan.getSpanContext().getSpanId(), TraceFlags.getDefault(), TraceState.getDefault());
try (Scope scope = Context.root().with(Span.wrap(spanContext)).makeCurrent()) {
   Span.current().end();
}

Actual behavior

An error occur when trying to execute this method. This also occur for other methods, like setResponseCode() etc.:
ThreadContext.getRequestTelemetryContext().getRequestTelemetry().setDuration() is not supported by the Application Insights for Java 3.x agent (this message will only be logged once)

To Reproduce

  • use Java program with latest application insights jar 3.4.7,
  • import these dependencies to pom.xml:
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-core</artifactId>
            <version>3.4.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-web</artifactId>
            <version>3.4.7</version>
        </dependency>

Sample Application

System information

Logs

Screenshots

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions