sentry使用记录

本文详细记录了在Django项目中使用Sentry进行环境搭建的步骤,包括Docker版本检查、docker-compose安装、仓库克隆、环境配置、数据库建立以及DSN的获取。同时,介绍了项目的迁移过程,提供了相关参考资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境搭建

1.查看docker版本信息:docker --version
Docker version 17.09.1-ce, build 19e2cf6

2.安装docker-compose

pip install docker-compose

查看docker-compose版本信息

docker-compose --version

docker-compose version 1.24.0, build 0aa5906

3.克隆仓库:git clone https://github.com/getsentry/onpremise.git
进入仓库:cd onpremise,然后执行以下命令:

  1. docker volume create --name=sentry-data && docker volume create --name=sentry-postgres - Make our local database and sentry volumes
    Docker volumes have to be created manually, as they are declared as external to be more durable.
  2. cp -n .env.example .env - create env config file
  3. docker-compose build - Build and tag the Docker services
  4. docker-compose run --rm web config generate-secret-key - 生成SECRET_KEY,注意最后一行.
    Add it to .env as SENTRY_SECRET_KEY.
  5. docker-compose run --rm web upgrade - Build the database.
    Use the interactive prompts to create a user account.
  6. docker-compose up -d - Lift all services (detached/background mode).关闭:docker-compose down
  7. Access your instance at localhost:9000!

4.浏览器打开 http://localhost:9000,并设置:在这里插入图片描述查看DSN,发现内容为空:
在这里插入图片描述查看文档:The DSN can be found in Sentry by navigating to [Project Name] -> Project Settings -> Client Keys (DSN). '{PROTOCOL}://{PUBLIC_KEY}@{HOST}/{PROJECT_ID}',组合后的dsn=“http://f397b976ce2b407e9772e5a7cd845570:eb5d1f317d0b47cfa71c0b3b85e76bf8@127.0.0.1:9000/3”

具体的django使用很简单,采用的是sentry-sdk,看官方文档即可,但不推荐使用raven,原因是:This SDK has been superseded by a new unified one. The documentation here is preserved for customers using the old client.

项目迁移

1.在旧机器上的操作

登录正在运行的容器
docker exec -it 容器ID  /bin/bash
导出用户与项目等数据,导出的内容为json格式,需要检查下,确保能正常导入
sentry export --exclude savedsearch,rule,permission,migrationhistory,contenttype,option,site,userip,useroption,projectoption,counter,organizationmemberteam,organizationmember,team,organizationoption,projectteam,authenticator,organization,projectbookmark > sentry.json
拷贝数据到本地环境
docker cp 容器ID:/usr/src/sentry/sentry.json .

2.在新机器上的操作

使用scp将旧机器的sentry.json传输到新机器上
拷贝本地数据到docker环境
docker cp sentry.json 容器ID:/usr/src/sentry/sentry.json
导入数据
sentry import sentry.json

参考

https://docs.sentry.io/platforms/python/django/
https://github.com/getsentry/onpremise

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值