logging library doesn't support Exceptions
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 firebase_functions/logger.py 开始,重点查看 error()、write() 和 _entry_from_args(),然后将文档中的 Firebase 日志记录示例与此处显示的 JSON 序列化失败进行比较。完成标准是:记录 Exception 不再抛出错误,并且日志记录 API 会在函数日志中包含 Exception 的完整堆栈跟踪。
由索引模型根据 Issue 内容生成。
描述
The logger in firebase_functions doesn't seem to provide reasonable support for exceptions.
In the example, firebase suggests extracting a portion of the error and including it:
try
...
except:
e = sys.exc_info()[0]
# Attach an error object as the second argument
logger.error("Unable to read quote from Firestore, sending default instead", error=e)
However this fails with an error:
../../../../Library/Caches/pypoetry/virtualenvs/oasis-zYbk3Ww0-py3.11/lib/python3.11/site-packages/firebase_functions/logger.py:130: in error
write(_entry_from_args(LogSeverity.ERROR, *args, **kwargs))
../../../../Library/Caches/pypoetry/virtualenvs/oasis-zYbk3Ww0-py3.11/lib/python3.11/site-packages/firebase_functions/logger.py:95: in write
print(_json.dumps(_remove_circular(entry)), file=write_file)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/__init__.py:231: in dumps
return _default_encoder.encode(obj)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:200: in encode
chunks = self.iterencode(o, _one_shot=True)
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:258: in iterencode
return _iterencode(o, 0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <json.encoder.JSONEncoder object at 0x10166ee10>, o = <class 'TypeError'>
def default(self, o):
"""Implement this method in a subclass such that it returns
a serializable object for ``o``, or calls the base implementation
(to raise a ``TypeError``).
For example, to support arbitrary iterators, you could
implement default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
"""
> raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')
E TypeError: Object of type type is not JSON serializable
../../../../.pyenv/versions/3.11.7/lib/python3.11/json/encoder.py:180: TypeError
Moreover it's not really an ideal API to log a subset of an exception. Ideally the entire stack trace would be included.
If you instead simply print the error, you can see a reasonable stack trace in the logs for the function.
I'd expect the example to not throw. I'd also expect the logging API to explicitly support logging Exceptions with stack traces
- 主要语言
- Python
- 星标
- 167
- 派生
- 36
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-functions-python 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
-
Add support for VPC direct connect可能已有人在做 @IzaakGough 于 104 天前认领。 未关闭feature-request
难度 4/5 3-5 天 新手友好度 48/100
firebase/firebase-functions-python#275 · 1 条评论 · 1 个 reaction ·
-
feature-request
难度 4/5 3-5 天 新手友好度 35/100
firebase/firebase-functions-python#271 · 3 条评论 ·
-
[Bug] stability_digest_payload_from_ce_payload fails with AttributeError: 'dict' object has no attribute 'split'可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug unable to reproduce
难度 3/5 1-2 天 新手友好度 55/100
firebase/firebase-functions-python#260 · 6 条评论 ·
-
feature-request
难度 5/5 一周以上 新手友好度 25/100
firebase/firebase-functions-python#249 · 2 条评论 ·
查看 firebase/firebase-functions-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 3 天内回复
-
Negation with "not" and "no" is ignored during sentiment analysis可能已有人在做 @vivek-3728 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
techcsispit/mess-mood#11 · 1 条评论 ·
-
changelog investigate
难度 2/5 1-3 小时 新手友好度 68/100
ramnes/notion-sdk-py#408 ·
-
good first issue
难度 2/5 1-3 小时 新手友好度 83/100
btclib-org/btclib-wallet#267 ·
维护者通常 1 天内回复
-
good first issue tech-debt
难度 2/5 1-3 小时 新手友好度 85/100
knnmelprop/YAADO#111 ·