Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Attribute Filtering #1008

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions newrelic/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class Application(object):

_lock = threading.Lock()
_instances = {}

Expand Down Expand Up @@ -164,7 +163,9 @@ def record_transaction(self, data):

def record_log_event(self, message, level=None, timestamp=None, attributes=None, priority=None):
if self.active:
self._agent.record_log_event(self._name, message, level, timestamp, attributes=attributes, priority=priority)
self._agent.record_log_event(
self._name, message, level, timestamp, attributes=attributes, priority=priority
)

def normalize_name(self, name, rule_type="url"):
if self.active:
Expand Down
6 changes: 3 additions & 3 deletions newrelic/api/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from newrelic.api.time_trace import get_linking_metadata
from newrelic.api.transaction import current_transaction, record_log_event
from newrelic.common import agent_http
from newrelic.common.object_names import parse_exc_info
from newrelic.common.encoding_utils import safe_json_encode
from newrelic.common.object_names import parse_exc_info
from newrelic.core.attribute import truncate
from newrelic.core.config import global_settings, is_expected_error
from newrelic.packages import six
Expand Down Expand Up @@ -133,8 +133,8 @@ def __init__(
"The contributed NewRelicLogHandler has been superseded by automatic instrumentation for "
"logging in the standard lib. If for some reason you need to manually configure a handler, "
"please use newrelic.api.log.NewRelicLogForwardingHandler to take advantage of all the "
"features included in application log forwarding such as proper batching.",
DeprecationWarning
"features included in application log forwarding such as proper batching.",
DeprecationWarning,
)
super(NewRelicLogHandler, self).__init__(level=level)
self.license_key = license_key or self.settings.license_key
Expand Down
14 changes: 8 additions & 6 deletions newrelic/api/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
create_attributes,
create_user_attributes,
process_user_attribute,
resolve_logging_context_attributes,
truncate,
)
from newrelic.core.attribute_filter import (
Expand Down Expand Up @@ -310,7 +311,7 @@ def __init__(self, application, enabled=None, source=None):
self.synthetics_job_id = None
self.synthetics_monitor_id = None
self.synthetics_header = None

# Synthetics Info Header
self.synthetics_type = None
self.synthetics_initiator = None
Expand Down Expand Up @@ -1545,16 +1546,17 @@ def record_log_event(self, message, level=None, timestamp=None, attributes=None,

message = truncate(message, MAX_LOG_MESSAGE_LENGTH)

attrs = get_linking_metadata()
if attributes and (settings and settings.application_logging and settings.application_logging.forwarding and settings.application_logging.forwarding.context_data and settings.application_logging.forwarding.context_data.enabled):
# TODO add attibute filtering
attrs.update({"context." + k: safe_json_encode(v, ignore_string_types=True) for k, v in six.iteritems(attributes)})
collected_attributes = get_linking_metadata()
if attributes and (settings and settings.application_logging.forwarding.context_data.enabled):
context_attributes = resolve_logging_context_attributes(attributes, settings.attribute_filter, "context.")
if context_attributes:
collected_attributes.update(context_attributes)

event = LogEventNode(
timestamp=timestamp,
level=level,
message=message,
attributes=attrs,
attributes=collected_attributes,
)

self._log_events.add(event, priority=priority)
Expand Down
Loading
Loading