Skip to content

Commit 8c91a74

Browse files
lrafeeimergify[bot]TimPansino
authored
Enable environment variables for attribute filters (#1558)
* Enable env vars for attribute filters * [MegaLinter] Apply linters fixes * Trigger tests * Change attribute filters to space delimited * Fix test assertion --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Tim Pansino <timpansino@gmail.com>
1 parent 8577eb7 commit 8c91a74

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

newrelic/core/config.py

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ def default_otlp_host(host):
803803
_settings.compressed_content_encoding = "gzip"
804804
_settings.max_payload_size_in_bytes = 1000000
805805

806-
_settings.attributes.enabled = True
807-
_settings.attributes.exclude = []
808-
_settings.attributes.include = []
806+
_settings.attributes.enabled = _environ_as_bool("NEW_RELIC_ATTRIBUTES_ENABLED", default=True)
807+
_settings.attributes.exclude = _environ_as_set(os.environ.get("NEW_RELIC_ATTRIBUTES_EXCLUDE", ""))
808+
_settings.attributes.include = _environ_as_set(os.environ.get("NEW_RELIC_ATTRIBUTES_INCLUDE", ""))
809809

810810
_settings.thread_profiler.enabled = True
811811
_settings.cross_application_tracer.enabled = False
@@ -821,9 +821,15 @@ def default_otlp_host(host):
821821
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
822822
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", default=DEFAULT_RESERVOIR_SIZE
823823
)
824-
_settings.transaction_events.attributes.enabled = True
825-
_settings.transaction_events.attributes.exclude = []
826-
_settings.transaction_events.attributes.include = []
824+
_settings.transaction_events.attributes.enabled = _environ_as_bool(
825+
"NEW_RELIC_TRANSACTION_EVENTS_ATTRIBUTES_ENABLED", default=True
826+
)
827+
_settings.transaction_events.attributes.exclude = _environ_as_set(
828+
os.environ.get("NEW_RELIC_TRANSACTION_EVENTS_ATTRIBUTES_EXCLUDE", "")
829+
)
830+
_settings.transaction_events.attributes.include = _environ_as_set(
831+
os.environ.get("NEW_RELIC_TRANSACTION_EVENTS_ATTRIBUTES_INCLUDE", "")
832+
)
827833

828834
_settings.custom_insights_events.enabled = True
829835
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
@@ -847,13 +853,23 @@ def default_otlp_host(host):
847853
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
848854
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", default=SPAN_EVENT_RESERVOIR_SIZE
849855
)
850-
_settings.span_events.attributes.enabled = True
851-
_settings.span_events.attributes.exclude = []
852-
_settings.span_events.attributes.include = []
856+
_settings.span_events.attributes.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ATTRIBUTES_ENABLED", default=True)
857+
_settings.span_events.attributes.exclude = _environ_as_set(
858+
os.environ.get("NEW_RELIC_SPAN_EVENTS_ATTRIBUTES_EXCLUDE", "")
859+
)
860+
_settings.span_events.attributes.include = _environ_as_set(
861+
os.environ.get("NEW_RELIC_SPAN_EVENTS_ATTRIBUTES_INCLUDE", "")
862+
)
853863

854-
_settings.transaction_segments.attributes.enabled = True
855-
_settings.transaction_segments.attributes.exclude = []
856-
_settings.transaction_segments.attributes.include = []
864+
_settings.transaction_segments.attributes.enabled = _environ_as_bool(
865+
"NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_ENABLED", default=True
866+
)
867+
_settings.transaction_segments.attributes.exclude = _environ_as_set(
868+
os.environ.get("NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_EXCLUDE", "")
869+
)
870+
_settings.transaction_segments.attributes.include = _environ_as_set(
871+
os.environ.get("NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_INCLUDE", "")
872+
)
857873

858874
_settings.transaction_tracer.enabled = True
859875
_settings.transaction_tracer.transaction_threshold = None
@@ -864,9 +880,15 @@ def default_otlp_host(host):
864880
_settings.transaction_tracer.function_trace = []
865881
_settings.transaction_tracer.generator_trace = []
866882
_settings.transaction_tracer.top_n = 20
867-
_settings.transaction_tracer.attributes.enabled = True
868-
_settings.transaction_tracer.attributes.exclude = []
869-
_settings.transaction_tracer.attributes.include = []
883+
_settings.transaction_tracer.attributes.enabled = _environ_as_bool(
884+
"NEW_RELIC_TRANSACTION_TRACER_ATTRIBUTES_ENABLED", default=True
885+
)
886+
_settings.transaction_tracer.attributes.exclude = _environ_as_set(
887+
os.environ.get("NEW_RELIC_TRANSACTION_TRACER_ATTRIBUTES_EXCLUDE", "")
888+
)
889+
_settings.transaction_tracer.attributes.include = _environ_as_set(
890+
os.environ.get("NEW_RELIC_TRANSACTION_TRACER_ATTRIBUTES_INCLUDE", "")
891+
)
870892

871893
_settings.error_collector.enabled = True
872894
_settings.error_collector.capture_events = True
@@ -879,9 +901,15 @@ def default_otlp_host(host):
879901
)
880902
_settings.error_collector.expected_status_codes = set()
881903
_settings.error_collector._error_group_callback = None
882-
_settings.error_collector.attributes.enabled = True
883-
_settings.error_collector.attributes.exclude = []
884-
_settings.error_collector.attributes.include = []
904+
_settings.error_collector.attributes.enabled = _environ_as_bool(
905+
"NEW_RELIC_ERROR_COLLECTOR_ATTRIBUTES_ENABLED", default=True
906+
)
907+
_settings.error_collector.attributes.exclude = _environ_as_set(
908+
os.environ.get("NEW_RELIC_ERROR_COLLECTOR_ATTRIBUTES_EXCLUDE", "")
909+
)
910+
_settings.error_collector.attributes.include = _environ_as_set(
911+
os.environ.get("NEW_RELIC_ERROR_COLLECTOR_ATTRIBUTES_INCLUDE", "")
912+
)
885913

886914
_settings.browser_monitoring.enabled = True
887915
_settings.browser_monitoring.auto_instrument = True
@@ -890,9 +918,15 @@ def default_otlp_host(host):
890918
_settings.browser_monitoring.debug = False
891919
_settings.browser_monitoring.ssl_for_http = None
892920
_settings.browser_monitoring.content_type = ["text/html"]
893-
_settings.browser_monitoring.attributes.enabled = False
894-
_settings.browser_monitoring.attributes.exclude = []
895-
_settings.browser_monitoring.attributes.include = []
921+
_settings.browser_monitoring.attributes.enabled = _environ_as_bool(
922+
"NEW_RELIC_BROWSER_MONITORING_ATTRIBUTES_ENABLED", default=False
923+
)
924+
_settings.browser_monitoring.attributes.exclude = _environ_as_set(
925+
os.environ.get("NEW_RELIC_BROWSER_MONITORING_ATTRIBUTES_EXCLUDE", "")
926+
)
927+
_settings.browser_monitoring.attributes.include = _environ_as_set(
928+
os.environ.get("NEW_RELIC_BROWSER_MONITORING_ATTRIBUTES_INCLUDE", "")
929+
)
896930

897931
_settings.transaction_name.limit = None
898932
_settings.transaction_name.naming_scheme = os.environ.get("NEW_RELIC_TRANSACTION_NAMING_SCHEME")

tests/agent_unittests/test_agent_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test_connect(
466466
# Verify that agent settings sent have converted null, containers, and
467467
# unserializable types to string
468468
assert agent_settings_payload["proxy_host"] == "None"
469-
assert agent_settings_payload["attributes.include"] == "[]"
469+
assert agent_settings_payload["attributes.include"] == str(set())
470470
assert agent_settings_payload["feature_flag"] == str(set())
471471
assert isinstance(agent_settings_payload["attribute_filter"], str)
472472

0 commit comments

Comments
 (0)