Azure / Azure/azure-functions-java-worker

Exceptions in static blocks blocks not caught/recorded

未关闭
#295 2 条评论 0 个 reaction 已指派 1 人 已指派给 @kaibocai 在 GitHub 查看
area:java-functions Bug P2 reviewed
主要语言
Java
星标
103
派生
74
平均合并
4 天 8 小时
30 天内合并 PR
2

描述

When an exception occurs in a static initialization, it is not logged in AppInsights.

#### Investigative information

Please provide the following:

- Timestamp: 2019-06-21T17:48:38.384
- Invocation ID: `48d86a7c24b1354196e9c0c9b6ee7d19`
- Region: Central US

#### Repro steps
Here's a sample function to reproduce:

```java
package com.yevster;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Optional;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;

public class ProtoFunction {
static {
//Puke!
Optional.empty().orElseThrow(()->new RuntimeException("Life isn't fair!"));
}

@FunctionName("prototype")
public HttpResponseMessage run(@HttpTrigger(name = "req", methods = {
HttpMethod.GET }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request,
final ExecutionContext context) throws MalformedURLException, IOException {

return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "text/html").body("

Rejoice! All is well!

").build();
}
}

```
And here's what AppInsights shows when queried for all exceptions and trace messages after invocation of that function:

[![noexceptionlogged.jpg](https://i.postimg.cc/Fsccphhv/noexceptionlogged.jpg)](https://postimg.cc/7fHfY8Ct)

#### Expected behavior

Provide a description of the expected behavior.

The exception thrown from the static block is recorded in App Insights.

#### Actual behavior

The exception thrown from the static block is **not** recorded in App Insights.

#### Known workarounds

Do not use any static code.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。