def getAggregatedError(project, errorHash):
    """Gets (and updates) the error matching the given report, or None if no matching error is found."""
    error = None

    project = getProject(project)

    q = LoggedError.all().filter("project =", project).filter("hash =", errorHash).filter("active =", True)

    for possibility in q:
        return possibility

    return error
def getAggregatedError(project, errorHash):
  """Gets (and updates) the error matching the given report, or None if no matching error is found."""
  error = None

  project = getProject(project)

  q = LoggedError.all().filter('project =', project).filter('hash =', errorHash).filter('active =', True)

  for possibility in q:
    return possibility

  return error
Example #3
0
def getInstances(filters, parent = None, limit = None, offset = None):
  """Gets a list of instances of the given parent error, filtered by the given filters."""

  query = LoggedErrorInstance.all()
  if parent:
    query = query.filter('error =', parent)

  if filters:
    for key, value in filters.items():
      if key in INSTANCE_FILTERS:
        query = filterInstances(query, key, value)
      elif key == 'project' and not parent:
        query = query.filter('project =', getProject(value))

  return query.order('-date').fetch(limit or 51, offset or 0)
Example #4
0
def getInstances(filters, parent=None, limit=None, offset=None):
    """Gets a list of instances of the given parent error, filtered by the given filters."""

    query = LoggedErrorInstance.all()
    if parent:
        query = query.filter('error =', parent)

    if filters:
        for key, value in filters.items():
            if key in INSTANCE_FILTERS:
                query = filterInstances(query, key, value)
            elif key == 'project' and not parent:
                query = query.filter('project =', getProject(value))

    return query.order('-date').fetch(limit or 51, offset or 0)
Example #5
0
def getErrors(filters, limit, offset):
  """Gets a list of errors, filtered by the given filters."""
  for key in filters:
    if key in INSTANCE_FILTERS:
      return None, getInstances(filters, limit=limit, offset=offset)

  errors = LoggedError.all().filter('active =', True)
  for key, value in filters.items():
    if key == 'maxAgeHours':
      errors = errors.filter('firstOccurrence >', datetime.now() - timedelta(hours = int(value)))
    elif key == 'project':
      errors = errors.filter('project =', getProject(value))
    else:
      errors = errors.filter(key, value)
  if 'maxAgeHours' in filters:
    errors = errors.order('-firstOccurrence')
  else:
    errors = errors.order('-lastOccurrence')

  return errors.fetch(limit, offset), None
Example #6
0
  def get(self):
    """Handles a new error report via POST."""
    key = self.request.get('key')

    if key != SECRET_KEY:
      self.error(403)
      return

    counts = []
    project = self.request.get('project')
    if project:
      project = getProject(project)
      if not project:
        self.response.out.write(' '.join(['0' for _ in counts]))
    for minutes in self.request.get('minutes').split():
      query = LoggedErrorInstance.all()
      if project:
        query = query.ancestor(project)
      counts.append(query.filter('date >=', datetime.now() - timedelta(minutes = int(minutes))).count())

    self.response.out.write(' '.join((str(count) for count in counts)))
Example #7
0
def getErrors(filters, limit, offset):
    """Gets a list of errors, filtered by the given filters."""
    for key in filters:
        if key in INSTANCE_FILTERS:
            return None, getInstances(filters, limit=limit, offset=offset)

    errors = LoggedError.all().filter('active =', True)
    for key, value in filters.items():
        if key == 'maxAgeHours':
            errors = errors.filter(
                'firstOccurrence >',
                datetime.now() - timedelta(hours=int(value)))
        elif key == 'project':
            errors = errors.filter('project =', getProject(value))
        else:
            errors = errors.filter(key, value)
    if 'maxAgeHours' in filters:
        errors = errors.order('-firstOccurrence')
    else:
        errors = errors.order('-lastOccurrence')

    return errors.fetch(limit, offset), None
Example #8
0
    def get(self):
        """Handles a new error report via POST."""
        key = self.request.get('key')

        if key != SECRET_KEY:
            self.error(403)
            return

        counts = []
        project = self.request.get('project')
        if project:
            project = getProject(project)
            if not project:
                self.response.out.write(' '.join(['0' for _ in counts]))
        for minutes in self.request.get('minutes').split():
            query = LoggedErrorInstance.all()
            if project:
                query = query.ancestor(project)
            counts.append(
                query.filter('date >=',
                             datetime.now() -
                             timedelta(minutes=int(minutes))).count())

        self.response.out.write(' '.join((str(count) for count in counts)))
def _putInstance(exception):
  """Put an exception in the data store."""
  backtraceText = exception.get('backtrace') or ''
  environment = exception.get('environment', 'Unknown')
  message = exception['message'] or ''
  project = exception['project']
  server = exception['serverName']
  timestamp = datetime.fromtimestamp(exception['timestamp'])
  exceptionType = exception.get('type') or ''
  logMessage = exception.get('logMessage')
  context = exception.get('context')
  errorLevel = exception.get('errorLevel')

  errorHash = generateHash(exceptionType, backtraceText)

  error = getAggregatedError(project, errorHash)

  exceptionType = exceptionType.replace('\n', ' ')
  if len(exceptionType) > 500:
    exceptionType = exceptionType[:500]
  exceptionType = exceptionType.replace('\n', ' ')

  needsAggregation = True
  if not error:
    error = LoggedError(
        project = getProject(project),
        backtrace = backtraceText,
        type = exceptionType,
        hash = errorHash,
        active = True,
        errorLevel = errorLevel,
        count = 1,
        firstOccurrence = timestamp,
        lastOccurrence = timestamp,
        lastMessage = message[:300],
        environments = [str(environment)],
        servers = [server])
    error.put()
    needsAggregation = False

  instance = LoggedErrorInstance(
      project = error.project,
      error = error,
      environment = environment,
      type = exceptionType,
      errorLevel = errorLevel,
      date = timestamp,
      message = message,
      server = server,
      logMessage = logMessage)
  if context:
    instance.context = json.dumps(context)
    if 'userId' in context:
      try:
        instance.affectedUser = int(context['userId'])
      except (TypeError, ValueError):
        pass
  instance.put()

  if needsAggregation:
    queueAggregation(error, instance, backtraceText)
def _putInstance(exception):
    """Put an exception in the data store."""
    backtraceText = exception.get("backtrace") or ""
    environment = exception.get("environment", "Unknown")
    message = exception["message"] or ""
    project = exception["project"]
    server = exception["serverName"]
    timestamp = datetime.fromtimestamp(exception["timestamp"])
    exceptionType = exception.get("type") or ""
    logMessage = exception.get("logMessage")
    context = exception.get("context")
    errorLevel = exception.get("errorLevel")

    errorHash = generateHash(exceptionType, backtraceText)

    error = getAggregatedError(project, errorHash)

    exceptionType = exceptionType.replace("\n", " ")
    if len(exceptionType) > 500:
        exceptionType = exceptionType[:500]
    exceptionType = exceptionType.replace("\n", " ")

    needsAggregation = True
    if not error:
        error = LoggedError(
            project=getProject(project),
            backtrace=backtraceText,
            type=exceptionType,
            hash=errorHash,
            active=True,
            errorLevel=errorLevel,
            count=1,
            firstOccurrence=timestamp,
            lastOccurrence=timestamp,
            lastMessage=message[:300],
            environments=[str(environment)],
            servers=[server],
        )
        error.put()
        needsAggregation = False

    instance = LoggedErrorInstance(
        project=error.project,
        error=error,
        environment=environment,
        type=exceptionType,
        errorLevel=errorLevel,
        date=timestamp,
        message=message,
        server=server,
        logMessage=logMessage,
    )
    if context:
        instance.context = json.dumps(context)
        if "userId" in context:
            try:
                instance.affectedUser = int(context["userId"])
            except (TypeError, ValueError):
                pass
    instance.put()

    if needsAggregation:
        queueAggregation(error, instance, backtraceText)