0

I have a PowerShell function app that I'd like to add logging to, with customDimensions, to Azure Application Insights. It logs a request but I'm struggling to find out how to add custom properties to the existing telemetry client.

So is it even possible to access and add customDimensions / properties to the existing telemetry client within the function app? Specifically for a request. I'm able to do so only when creating a new client and invoking trackRequest, like so:

class MyInitializer3 : Extensibility.ITelemetryInitializer {
    <# Define the class. Try constructors, properties, or methods. #>
    [void]Initialize([Channel.ITelemetry]$Telemetry){
        #$requestTelemetry = [DataContracts.RequestTelemetry]::new()
        $requestTelemetry = [DataContracts.RequestTelemetry]$Telemetry

        $requestTelemetry.Properties["test"] = "test value"
    }
}

$requestTelemetry = [DataContracts.RequestTelemetry]::new()

######################

$telemetryConfig = [Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration]::CreateDefault()
$telemetryConfig.ConnectionString = "XXXXXXXX"

$telemetryConfig.TelemetryInitializers.Add( [MyInitializer3]::new() )

$client = [Microsoft.ApplicationInsights.TelemetryClient]::new($telemetryConfig)

$client.TrackRequest("requestTest",$(get-date),100,201,$true)

But of course the function app already logs a request anyway, and I'd like to add to that.

ScubaManDan
  • 809
  • 8
  • 22

0 Answers0