0

I setup some dependency tracking for a Azure Function App implemented with Java. Therefore I added applicationinsights-core as dependency, see Add the Application Insights SDK for Java to your project.

<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>applicationinsights-core</artifactId>
  <version>2.6.2</version>
</dependency>

To create a dependencies entry, I use an instance of TelemetryClient.

// call an external service, e.g. ADLS file upload..
long start = System.currentTimeMillis();
uploadFile();
long elapsed = System.currentTimeMillis() - start;

// void trackDependency(String dependencyName, String commandName, Duration duration, boolean success)
new TelemetryClient().trackDependency(
  "ADLS", "upload file", new Duration(elapsed), true);

The resulting dependencies entry looks strange. It misses the cloud_RoleName, which usually identifies the creator of the entry. In addition, the commandName is passed as data property and there seems no way to set the type property of the entry.

While I found no dedicated Java Function App documentation for dependency tracking, the general Java documentation recommends to use the applicationinsights-agent additionally (see Java codeless application monitoring Azure Monitor Application Insights). The agent handles the telemetry of applicationinsights-core (see Supported custom telemetry). But it isn't obvious to me, how to setup the agent for Azure Function App.

How can I setup the cloud_RoleName? Is there a way to set dependencies's type property?

sschmeck
  • 7,233
  • 4
  • 40
  • 67

1 Answers1

1

I found a solution using just applicationinsights-core.

  • The cloud_RoleName can be taken from the environment variable WEBSITE_SITE_NAME.
  • The type can be configured via a setter of RemoteDependencyTelemetry.
// create depedencies entry
createTelemetryClient().trackDependency(
  buildTelemetry("ADSL", "upload file", "custom context", successful, elapsed));
// ..

private TelemetryClient createTelemetryClient() {
  TelemetryConfiguration configuration = TelemetryConfiguration.getActive();
  configuration.setRoleName(System.getenv("WEBSITE_SITE_NAME"));
  return new TelemetryClient(configuration);
}

private RemoteDependencyTelemetry buildTelemetry(String type,
                                                 String name,
                                                 String data,
                                                 boolean successful,
                                                 long elapsed) {
    RemoteDependencyTelemetry telemetry = new RemoteDependencyTelemetry(
        name,
        data,
        new Duration(elapsed),
        successful);
    telemetry.setType(type);
    return telemetry;
}
sschmeck
  • 7,233
  • 4
  • 40
  • 67