Azure函数间歇性不可见问题的排查咨询
Azure函数间歇性不可见问题的排查咨询
我写了一个HTTP触发的Azure函数,功能是把消息发送到Service Bus队列,代码和绑定配置如下。现在遇到一个奇怪的问题:有时候函数会突然在Azure Functions控制台里看不到了,但我根本没改任何配置,想请教大家可能是什么原因?
我的函数代码与配置
function_app.py
@app.route(route="http_trigger") @app.service_bus_queue_output(arg_name="msgout", queue_name="ftdx", connection="AzureWebJobsServiceBus") def http_trigger(req: func.HttpRequest, msgout: func.Out[str]) -> func.HttpResponse: """Azure Function HTTP trigger that sends messages to Service Bus.""" logging.info('Python HTTP trigger function processed a request.') try: req_body = req.get_json() message_body = req_body.get("message") if not message_body: return func.HttpResponse("Invalid request: 'message' field is required", status_code=400) # Send message to Service Bus msgout.set(message_body) return func.HttpResponse("Message sent to Service Bus.", status_code=200) except ValueError: return func.HttpResponse("Invalid JSON payload", status_code=400)
function.json
{ "bindings": [ { "type": "httpTrigger", "direction": "in", "authLevel": "function", "methods": ["post"] }, { "type": "http", "direction": "out" }, { "type": "serviceBus", "direction": "out", "name": "msgout", "queueName": "ftdx", "connection": "AzureWebJobsServiceBus" } ], "scriptFile": "function_app.py" }
host.json
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" } }
local.setting.json
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "python", "AzureWebJobsServiceBus": "myKey" } }
我初步想到的排查方向
- 函数实例回收/冷启动异常:会不会是Azure自动回收实例或者冷启动过程中,函数元数据没正确加载?但冷启动一般是延迟,不至于直接看不到函数吧?
- 绑定配置冲突:我同时用了Python装饰器和function.json定义绑定,会不会有时候Azure运行时解析冲突,导致函数被判定为无效?
- 存储账户异常:函数元数据存在
AzureWebJobsStorage对应的存储账户里,如果存储账户临时不可用或权限出问题,会不会导致函数列表加载失败? - 扩展包版本bug:host.json里用了4.x的扩展包,会不会某些版本的扩展包有间歇性识别函数的bug?
- 未捕获的运行时错误:有没有可能函数运行时出现未捕获的错误,导致运行时把函数标记为不可用,但我没在Application Insights里查到相关日志?
有没有朋友遇到过类似的问题?或者有其他我没考虑到的排查点?麻烦指点一下!
备注:内容来源于stack exchange,提问作者Alexandra Cezar
相关产品推荐
相关产品推荐

