Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`JSON` attributes do not show up as valid json in event attributes

未关闭
#2,103 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

先从报告中展示的 handler 的 emit 方法和 HTTPLogItem 构造开始,然后跟踪 log_ctx 如何通过 LogsApi.submit_log 进行序列化。使用 x_request_body 重现 logger.debug 示例,并验证已提交事件的属性保留有效的 JSON 对象值,而不是显示为字符串。

由索引模型根据 Issue 内容生成。

描述

kind/bug stale

Describe the bug
A clear and concise description of what the bug is.
When a valid json is passed as value of a custom event atrribute, In logs it is show as a string and not a json object

To Reproduce

# in the handler

    def emit(self, record):
        env = os.getenv("APP_ENV", "local")
        log_ctx: LogCtxDict = record.__dict__.get("log_ctx", {})
        tags_dict = log_ctx.pop('tags', {})
        tags = [f"{k}:{v}" for k, v in tags_dict.items()]
        tags.append("env:{}".format(env))
        tags_merged = ",".join(tags)
        body = HTTPLog(
            [
                HTTPLogItem(
                    ddsource="python",
                    ddtags=tags_merged,
                    hostname="vv-anyscale-ray-aps1",
                    message=self.format(record),
                    service="vv-ap-thumbnails-v1-{}-service".format(env),
                    timestamp=str(datetime.fromtimestamp(record.created).astimezone().timestamp()),
                    level=record.levelname.lower(),
                    **record.__dict__.get("log_ctx", {})
                )
            ]
        )
        try:
            with ApiClient(self.dd_configuration) as api_client:
                resp = LogsApi(api_client).submit_log(content_encoding=ContentEncoding.GZIP, body=body)
                if "errors" in resp:
                    self.handleError(record)

        except (Exception, ):
            self.handleError(record)




logger.debug(
    "Test debug log",
    log_ctx={
        "x_request_body": json.dumps({"clip_id": "66abc57369bbe0000782ef42"}),
    }
)

Expected behavior
A clear and concise description of what you expected to happen.
The object should be consumed and shown as json,

Screenshots
If applicable, add screenshots to help explain your problem.
image

Environment and Versions (please complete the following information):
A clear and precise description of your setup:

$ poetry show datadog-api-client
 name         : datadog-api-client                         
 version      : 2.27.0                                     
 description  : Collection of all Datadog Public endpoints 

dependencies
 - certifi *
 - python-dateutil *
 - typing-extensions >=4.0.0
 - urllib3 >=1.15

for logs parsing default python pipleline is used
image

主要语言
Python
星标
166
派生
55
平均合并
2 天 17 小时
30 天内合并 PR
73

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DataDog/datadog-api-client-python 的其他 Issue

查看 DataDog/datadog-api-client-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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