Azure / Azure/azure-functions-host

Custom telemetry does not arrive at Application Insight

Open
#7,688 14 comments 0 reactions 2 assignees Claimed by @v-bbalaiagar View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

#### Check for a solution in the Azure portal
Done, not applicable

#### Issue:
I have made an Azure function that send custom telemetry to Application Insight when the function is run locally. However,
running the function one azure function host custom telemetry from the Java Azure function is not being send to Application Insight.

#### Please provide the following:

- Timestamp: 2021-09-23T06:50:24Z
- Function App version: 3.2 (Linux/Java) (Same observation on windows)
- Function App name: anderstest-functions-20210922205930008
- Function name: HttpExample
- Invocation ID: 33e8d4c7-6f66-4d58-82bf-7213ed632eaf
- Region: westeurope

#### Repro steps

1. Build and deploy attached project to Azure in bash (anderstest-functions.zip)
a. az login
b. go to project folder
c. mvn clean package
d. mvn azure-function:deploy
2. Go to Azure portal and copy Instrumentation key for the newly created Application Insight in the function resource group
3. In the Function.java file replace with the copied key
4. Re-deploy the function
a. mvn clean package
b. mvn azure-function:deploy
5. As part of clean package a test is run locally on the computer, which produces a customEvent in the Application insights transaction search called “WinGame” after a short wait (as expected)
6. Go to the created function app and into the function HttpExample
7. Go to Code + Test tab
8. Press Test/Run and choose any input and press Run
Confirm that log entries from the context logger appears in Application Insights after a short wait, but that the custom event “WinGame” never appears.

#### Expected behavior

Custom event telemetry should appear in Application Insight

#### Actual behavior

Custom event telemetry does not appear in Application Insight when run from azure (However, does when run locally)

#### Related information

Provide any related information

Fucntion code:

```java
public class Function {
static final TelemetryClient telemetryClient = new TelemetryClient();

@FunctionName("HttpExample")
public HttpResponseMessage run(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage> request,
final ExecutionContext context) {
context.getLogger().warning("Java HTTP trigger processed a request.");

context.getLogger().warning("Sending custom telemetry ");

telemetryClient.getContext().setInstrumentationKey("");
telemetryClient.trackEvent("WinGame");

telemetryClient.flush();

context.getLogger().warning("Custom telemetry send");

// Parse query parameter
final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);

if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}
}
```
[anderstest-functions.zip](https://github.com/Azure/azure-functions-host/files/7215906/anderstest-functions.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.