sentry 자체 구축하기
self hosted sentry
센트리가 자체 구축시에도 요금을 지불하는 줄 알았는데, 그건 아닌 것 같다.
오픈소스였고, 이걸 자사 프로덕트와 끼워파는 행위가 금지되는 것이었다. 내부 구축해서 모니터링 용도로 쓰는 건 괜찮다더라. 우리 팀 모니터링 용도로 쓰기엔 좀 안 맞긴 한데, 하나의 url 네트워크 요청마다 어떤 api나 DB 쿼리가 나가는지 관찰하기에는 최적의 용도라고 생각하기에 잠시 구축해봤다. 회사 계정으로 매달 20만원씩 크레딧이 나오는데, 이걸로 이것 저것 실험해보기에는 참 좋은 것 같다. 어쨌든, 구축 과정을 기록해보자.
도커 셋업
먼저 서버 하나 빌리고 도커를 설치해주자. 공식 사이트에서 최소 권장 사양이 4코어에 16기가 램이라고 해서 최소사양에 맞게 빌려봤다. 이렇게만 대여해도 20만원이 넘어서, 매일 오후 9시마다 서버 꺼지게 해놨다.
그리고 미래의 나를 위해서 메모를 남겨두자면, 저 스펙 부족한 것 같다. 램 더 필요한 것 같다. 만약에 다시 리소스 생성한다면 조금 더 널널하게 하도록 하자…
도커와 컴포즈 설치 스크립트는 gpt한테 시켜서 스크립트 짜달라고 했다. 이런 작업 할 때는 참 편한 것 같다. gpt가 작성해준 스크립트는 다음과 같다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
echo "▶️ 1. 도커 이전 버전 제거"
sudo apt-get remove -y docker docker-engine docker.io containerd runc || true
echo "▶️ 2. 필수 패키지 설치"
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
echo "▶️ 3. Docker GPG 키 추가"
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "▶️ 4. Docker 저장소 추가"
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "▶️ 5. Docker 엔진 설치"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
echo "✅ 도커 설치 완료"
echo "▶️ 6. 도커 권한 설정 (현재 사용자에게 docker 그룹 추가)"
sudo usermod -aG docker $USER
echo "✅ 현재 사용자를 docker 그룹에 추가했습니다. 변경 사항을 적용하려면 재로그인이 필요합니다."
echo "▶️ 7. 도커 및 도커 컴포즈 버전 확인"
docker --version
docker compose version
echo "🎉 모든 작업 완료!"
그 다음은 공식 문서에 있는 스크립트 대로 실행해주자. 나는 지오 뭐시기, 그러니까 지리 관련 컨테이너가 작동을 안했던 것 같은데 몇 번을 더 켜봐도 동일했던 걸 보면 메모리 부족인 것 같다. 다음엔 널널하게 빌리자. 서버가 많이 힘들어한다.
1
2
3
4
5
6
7
8
VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/getsentry/self-hosted/releases/latest)
VERSION=${VERSION##*/}
git clone https://github.com/getsentry/self-hosted.git
cd self-hosted
git checkout ${VERSION}
./install.sh
# After installation, run the following to start Sentry:
docker compose up --wait
이거는 정보를 익명으로 보낼지 말지 동의하는 문구들 같은데, 아무래도 회사 코드라 다 노노노 했다.
실행이 완료되면 포트를 열어줘야 한다. 기본적으로 9000번 포트를 사용한다. 나는 귀찮아서 9000 포트를 리다이렉트 시켜줬다. 임시로 잠깐 호스팅하는거라 인증서도 귀찮아서 앞단에 클라우드플레어로 대충 때웠다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# root 권한 확인
if [ "$EUID" -ne 0 ]; then
echo "이 스크립트는 root 권한으로 실행되어야 합니다."
exit 1
fi
# firewalld 실행 중인지 확인
if ! systemctl is-active --quiet firewalld; then
echo "firewalld가 실행 중이 아닙니다. 시작합니다..."
systemctl start firewalld
fi
# 리디렉션 설정 (포트 80 → 9000)
echo "포트 80을 9000으로 리디렉션 설정 중..."
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=9000
firewall-cmd --reload
echo "설정 완료: 포트 80 → 9000 (영구 적용됨)"
나머지는 공식 문서대로 설정해주면 된다. 의존성 설치하고, 하라는 대로 코드 셋업을 진행해준다. 우리는 FastAPI랑 리액트를 사용중이기 때문에 요래조래 코드를 적당히 넣어줬다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pip install --upgrade "sentry-sdk[fastapi]>=2.24.1"
## ....
import sentry_sdk
sentry_sdk.init(
dsn="...",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import * as Sentry from "@sentry/react";
Sentry.init({
dsn: "...",
integrations: [
Sentry.browserTracingIntegration(),
// Or, if you are using react router, use the appropriate integration
// See docs for support for different versions of react router
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/
],
// For finer control of sent transactions you can adjust this value, or
// use tracesSampler
tracesSampleRate: 1.0,
// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
});
이렇게 넣어주면 이슈, 트랜잭션 등등 잡히기 시작할 것이다.
출처
- https://develop.sentry.dev/self-hosted/