역 추적은 여러 줄의 코드로 구성되어 있습니다. 당신은 GitPython 라이브러리를 사용하여 이러한 라인의 각 git blame
에서 정보를 추출 할 수 있습니다 : 당신이 센트리이 정보를 전송하는 방법을
import sys
import traceback
from git import Repo
def commit_info(file_path, line_number):
for commit, lines in Repo().blame('HEAD', file_path):
line_number -= len(lines)
if line_number <= 0:
return commit.hexsha, commit.committed_datetime, commit.author.name
try:
raise Exception('error')
except Exception:
for filename, line_number, _, _ in traceback.extract_tb(sys.exc_info()[2]):
print filename, line_number, commit_info(filename, line_number)
그리고, 그것은 당신에게 달려 있습니다. 가능한 해결책 중 하나는 하나가 위의 목록 커밋 선택 및 로거를 extra
키워드를 사용하게되어 당신을 위해 일을 할 :
try:
raise Exception
except Exception:
commit = choose_one_commit()
logger.exception('Error', extra={'author': author.name, 'sha': commit.hexsha})
또한,이 extra
매개 변수를 추가 할 수있는 자신 만의 로거를 사용할 수 있습니다 모두 .exception()
, .error()
및 .critical()
전화.
전반적으로 어떤 동작을 달성하고자하는지 매우 모호하며 모든 것이 가능합니다. 그러나 git blame
으로 전화하는 것은 비용이 많이 들고 응용 프로그램의 성능을 크게 저하시킬 수 있습니다.
이것은 Sentry의 기능 요청과 같지만 질문은 아닙니다. – georgexsh
@georgexsh 센트리가 가진 모든 기능을 모르기 때문에 기능 요청이나 질문을 구분할 수 없습니다. – guettli
제목이나 본문에 적어도 하나 이상의 물음표를 포함시킬 수 있습니다 (질문이 분명해 보일지라도). – DJV