App Insights TelemetryClient - Migrating from V2 to V3

Dave Westerman 0 Reputation points
2023-02-27T21:18:44.03+00:00

We have been using the App Insights V2 TelemetryClient to create custom events in our Spring Boot Java app. We are trying to migrate to V3. Although the following web site says "There are typically no code changes when upgrading to 3.x.", in our case, the existing code gets a compile error, because the TelemetryConfiguration class no longer exists in V3.

https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-upgrade-from-2x

    TelemetryConfiguration.getActive().instrumentationKey = metricPublisherRequestDTO.ikey
    val telemetryClient = TelemetryClient()

    telemetryClient.trackEvent(
        metricPublisherRequestDTO.name,
        metricPublisherRequestDTO.properties,
        metricPublisherRequestDTO.metrics
    )

We need to be able to programmatically set the instrumentation key / connection string, because this is a generic service that we use to talk to any App Insights instance. We can find no way to do that. I tried the following, but it doesn't work:

    val telemetryClient = TelemetryClient()
    val telemetryContext = telemetryClient.context
    telemetryContext.connectionString = metricPublisherRequestDTO.ikey

Does anyone have any idea what we need to do this?

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,786 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karakoc, Gürcan 0 Reputation points
    2023-09-28T13:23:35.3033333+00:00

    Hi Dave,

    could you find a solution for this issue?

    Best regards,

    Gürcan

    0 comments No comments