2 回答
TA贡献1805条经验 获得超9个赞
在文档中找到正确的部分后,事情变得非常简单:
def main(mytimer: func.TimerRequest, context: func.Context) -> None:
try:
invocation_id = context.invocation_id
# Function continues here.
except Exception as e:
logging.error("Main program failed with error: " + str(e))
请注意,此解决方案仅在func.Context分配给时才有效context。使用任何其他名称都会context给我带来错误 -.-
TA贡献1824条经验 获得超6个赞
刚刚在此处添加了操作 ID,根据文档,Traceparent 的第二部分是 Trace_id,它将成为日志控制台中的操作 ID。
def main(mytimer: func.TimerRequest, context: func.Context) -> None:
try:
invocation_id = context.invocation_id
traceparent = context.trace_context.Traceparent
try:
operation_id = f"{traceparent}".split('-')[1]
except IndexError as i_err:
# as a backup option
logging.exception(i_err)
operation_id = 'default_id'
except Exception as final_err:
logging.exception(final_err)
# Function continues here.
except Exception as e:
logging.error("Main program failed with error: " + str(e))
添加回答
举报