Пример #1
0
    def log_record_to_dict(cls, record):
        output = {
            "timestamp": int(record.created * 1000),
            "message": record.getMessage(),
            "log.level": record.levelname,
            "logger.name": record.name,
            "thread.id": record.thread,
            "thread.name": record.threadName,
            "process.id": record.process,
            "process.name": record.processName,
            "file.name": record.pathname,
            "line.number": record.lineno,
        }
        output.update(get_linking_metadata())

        DEFAULT_LOG_RECORD_KEYS = cls.DEFAULT_LOG_RECORD_KEYS
        if len(record.__dict__) > len(DEFAULT_LOG_RECORD_KEYS):
            for key in record.__dict__:
                if key not in DEFAULT_LOG_RECORD_KEYS:
                    output["extra." + key] = getattr(record, key)

        if record.exc_info:
            output.update(format_exc_info(record.exc_info))

        return output
Пример #2
0
    def format(self, record):
        output = {
            "timestamp": int(record.created * 1000),
            "message": record.getMessage(),
            "log.level": record.levelname,
            "logger.name": record.name,
            "thread.id": record.thread,
            "thread.name": record.threadName,
            "process.id": record.process,
            "process.name": record.processName,
            "file.name": record.pathname,
            "line.number": record.lineno,
        }
        output.update(get_linking_metadata())

        DEFAULT_LOG_RECORD_KEYS = self.DEFAULT_LOG_RECORD_KEYS
        if len(record.__dict__) > len(DEFAULT_LOG_RECORD_KEYS):
            for key in record.__dict__:
                if key not in DEFAULT_LOG_RECORD_KEYS:
                    try:
                        value = str(getattr(record, key))
                    except Exception:
                        continue

                    output["extra." + key] = value

        if record.exc_info:
            output.update(format_exc_info(record.exc_info))
        return json.dumps(output)
Пример #3
0
    def __call__(self, logger, method_name, event_dict):
        # Import ``newrelic`` here because it's only installed in production
        from newrelic.api.log import format_exc_info  # noqa
        from newrelic.api.time_trace import get_linking_metadata  # noqa

        if not isinstance(event_dict, dict):
            return event_dict

        record = event_dict.get('_record')
        if record is None:
            return event_dict

        event_dict.update(get_linking_metadata())

        output = {
            # "timestamp": int(record.created * 1000),
            # "message": record.getMessage(),
            "message": event_dict['event'],
            # "log.level": record.levelname,
            # "logger.name": record.name,
            "thread.id": record.thread,
            "thread.name": record.threadName,
            "process.id": record.process,
            "process.name": record.processName,
            "file.name": record.pathname,
            "line.number": record.lineno,
        }

        if record.exc_info:
            output.update(format_exc_info(record.exc_info))

        event_dict.update(output)
        return event_dict
Пример #4
0
def add_nr_linking_metadata(message):
    available_metadata = get_linking_metadata()
    entity_name = quote(available_metadata.get("entity.name", ""))
    entity_guid = available_metadata.get("entity.guid", "")
    span_id = available_metadata.get("span.id", "")
    trace_id = available_metadata.get("trace.id", "")
    hostname = available_metadata.get("hostname", "")

    nr_linking_str = "|".join(
        ("NR-LINKING", entity_guid, hostname, trace_id, span_id, entity_name))
    return "%s %s|" % (message, nr_linking_str)
Пример #5
0
 def format(self, record):
     output = {
         "timestamp": int(record.created * 1000),
         "message": record.getMessage(),
         "log.level": record.levelname,
         "logger.name": record.name,
         "thread.id": record.thread,
         "thread.name": record.threadName,
         "process.id": record.process,
         "process.name": record.processName,
         "file.name": record.pathname,
         "line.number": record.lineno,
     }
     output.update(get_linking_metadata())
     if record.exc_info:
         output.update(format_exc_info(record.exc_info))
     return json.dumps(output)