Azure function, app insight

Learn101 0 Reputation points
2023-12-08T16:44:44.4133333+00:00

Can you see why the following azure function can create entries in app insight when run locally but not when deployed on azure, it uses .netframwork 4.8 ? Thanks.

   [FunctionName("Function1")]
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req )
        {

            var configuration = new TelemetryConfiguration
            {
                ConnectionString = "InstrumentationKey=I have the correct value;IngestionEndpoint=https://uksouth-1.in.applicationinsights.azure.com/;LiveEndpoint=https://uksouth.livediagnostics.monitor.azure.com/"
            };

            telemetryClient = new TelemetryClient(configuration);


            telemetryClient.Context.Cloud.RoleName = "Function1";
            telemetryClient.TrackEvent("Function1 TrackEvent");
            telemetryClient.TrackTrace("Function1 TrackTrace");

            telemetryClient.Flush();

            return req.CreateResponse(HttpStatusCode.OK, "Hello ");
        }
    }
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2023-12-09T16:34:43.8+00:00

    Maybe the configuration settings in your Azure environment doesn't match those you're using locally. This includes verifying the InstrumentationKey and any other relevant settings in the TelemetryConfiguration object.

    You may need also to checl the InstrumentationKey in the deployed version it may not be corresponding to the Application Insights resource you are expecting to see the data in.

    Another point is, the Flush() method in Application Insights SDK is asynchronous. In Azure Functions, if the function completes its execution before the telemetry data is sent, the data might be lost. You may think about implementing a delay to allow for the flush operation to complete.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.