2012-07-17 2 views
3

tastypie와 함께 Django를 사용하고 오류 추적을 위해 Sentry를 사용하고 있습니다.Sentry에 tastypie 오류 메시지가 표시되지 않습니다.

tastypie에서 발생하는 오류는 오류 메시지를 로깅하지 않는 것이 문제입니다.

core.api.api_user.hydrate 
Internal Server Error: /api/v1/test/123/ 

을하고 다음 메시지를 기록한다 :

그들은이 메시지와 함께 기록됩니다

core.api.api_user.hydrate 
int() argument must be a string or a number, not 'dict' 

및 스택 트레이스의 나머지.

이 내 프로젝트 로깅 설정입니다 : 내가 더 나은 내 오류를 기록 할 수있는 방법

LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': True, 
    'root': { 
     'level': 'WARNING', 
     'handlers': ['sentry'], 
    }, 
    'formatters': { 
     'verbose': { 
      'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' 
     }, 
    }, 
    'handlers': { 
     'sentry': { 
      'level': 'ERROR', 
      'class': 'raven.contrib.django.handlers.SentryHandler', 
     }, 
     'console': { 
      'level': 'DEBUG', 
      'class': 'logging.StreamHandler', 
      'formatter': 'verbose' 
     } 
    }, 
    'loggers': { 
     'django.request.tastypie': { 
      "handlers": ["sentry"], 
      "level": "ERROR", 
      "propagate": False 
     }, 
     'django.db.backends': { 
      'level': 'ERROR', 
      'handlers': ['console'], 
      'propagate': False, 
     }, 
     'raven': { 
      'level': 'DEBUG', 
      'handlers': ['console'], 
      'propagate': False, 
     }, 
     'sentry.errors': { 
      'level': 'DEBUG', 
      'handlers': ['console'], 
      'propagate': False, 
     }, 
    }, 
} 

어떤 생각?

장고 1.4 Tastypie 0.9.11 보초 3.5.7

답변

0

나는 당신이와 거의 동일한 설정을 가지고 그것을 잘 작동합니다. 내가 다른 무엇을 가지고 :

  1. 센트리 4.7.9, tastypie 이미 보초 핸들러에 의해 처리되는 오류에 기록하기 때문에이 설정에서 명시 적 tastypie 로거가없는
  2. 일 수 있었다.
  3. 내 서버를 DEBUG = False로 유지합니다. DEBUG = True이면 tastypie는 아무 것도 기록하지 않고 단지 응답 메시지에 오류 메시지를 표시합니다.
0

DEBUG에 모든 정보를 기록하더라도이 500 개의 오류가있는 Sentry 로그가 없습니다.

LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': True, 
    'formatters': { 
     'verbose': { 
      'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' 
     }, 
    }, 
    'handlers': { 
     'console': { 
      'level': 'DEBUG', 
      'class': 'logging.StreamHandler', 
      'formatter': 'verbose' 
     } 
    }, 
    'loggers': { 
     '': { 
      'level': 'DEBUG', 
      'handlers': ['console'], 
     }, 
    } 
} 

그래서, settings.pyMIDDLEWARE_CLASSES에서 나는 다음과 같은 구현 myproduct.middleware.SentryCatchMiddleware으로 raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware을 대체 :

from raven.contrib.django.models import client 
from raven.contrib.django.middleware import Sentry404CatchMiddleware 
import logging 

class SentryCatchMiddleware(Sentry404CatchMiddleware): 
    def process_response(self, request, response): 
     if response.status_code >= 500: 
      data = client.get_data_from_request(request) 
      data.update({ 
       'level': logging.ERROR, 
       'logger': 'http500', 
      }) 
      result = client.captureMessage(message='Internal Server Error: %s' % request.build_absolute_uri(), data=data) 
      request.sentry = { 
       'project_id': data.get('project', client.project), 
       'id': client.get_ident(result), 
      } 
      return response 
     return super(SentryCatchMiddleware, self).process_response(request, response) 

그래도 난 더 나은 솔루션을보고 싶어요!

+0

흠. 프로덕션 환경에서는 오류가 두 번 기록됩니다. 그래서 그것은 참입니다 :'DEBUG = True'는 django.request.tastypie가 기록되지 않았다는 것을 의미합니다. – ivy

0

Tastypie 설정 TASTYPIE_FULL_DEBUG을 사용하십시오. Sentry/Raven을 설정하면 TASTYPIE_FULL_DEBUG에서 까지를으로 설정하면 예외가 기록되고 DEBUG 코어가 출력을 제어합니다.

관련 문제