Sentry 与 FastApi 集成

问题描述 投票:0回答:1

我有一个 FastApi 应用程序在 nginx 反向代理端口 80 之上的端口 3000 上本地运行,因此我可以请求 localhost/api/v1/docs 等。我还在本地配置了哨兵,并在端口 9000 上运行。

现在我使用以下代码将哨兵集成到 FastApi:

sentry_sdk.init(
    dsn="http://<key>@localhost:9000/2",

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,
)

在 FastApi 日志中,它发出警告:

sentry_sdk.integrations.logging:sentry_patched_callhandlers:96 - 在连接因“NewConnectionError(”:无法建立新连接:[Errno 111] 连接被拒绝')':/api/2/envelope/

我不知道我哪里做错了。

我正在运行 2 个 nginx docker 容器,1 个用于 FastApi 应用程序,第 2 个默认带有 Sentry。

我尝试将 FastApi 的 nginx 端口从 80 更改为 81,但仍然出现相同的警告。

python docker nginx fastapi sentry
1个回答
0
投票

我知道这是一个较旧的问题,但使用内部主机的 docker 地址可以解决此问题,而无需使用特殊的设置网络。

使用

host.docker.internal
这可以解决如下。

http://<key>@host.docker.internal:9000/2

来源

© www.soinside.com 2019 - 2024. All rights reserved.