/
config.py
1390 lines (1030 loc) · 45 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" This module provides a structure to hang the configuration settings. We
use an empty class structure and manually populate it. The global defaults
will be overlaid with any settings from the local agent configuration file.
For a specific application we will then deep copy the global default
settings and then overlay that with application settings obtained from the
server side core application. Finally, to allow for local testing and
debugging, for selected override configuration settings, we will apply back
the global defaults or those from local agent configuration.
"""
import copy
import logging
import os
import re
import threading
import newrelic.packages.six as six
from newrelic.common.object_names import parse_exc_info
from newrelic.core.attribute import MAX_ATTRIBUTE_LENGTH
from newrelic.core.attribute_filter import AttributeFilter
try:
import urlparse
except ImportError:
import urllib.parse as urlparse
try:
import grpc
from newrelic.core.infinite_tracing_pb2 import ( # pylint: disable=W0611,C0412 # noqa: F401
Span,
)
except Exception:
grpc = None
# By default, Transaction Events and Custom Events have the same size
# reservoir. Error Events have a different default size.
# Slow harvest (Every 60 seconds)
DEFAULT_RESERVOIR_SIZE = 1200
ERROR_EVENT_RESERVOIR_SIZE = 100
SPAN_EVENT_RESERVOIR_SIZE = 2000
# Fast harvest (Every 5 seconds, so divide by 12 to get average per minute value)
CUSTOM_EVENT_RESERVOIR_SIZE = 3600
LOG_EVENT_RESERVOIR_SIZE = 10000
ML_EVENT_RESERVOIR_SIZE = 100000
# settings that should be completely ignored if set server side
IGNORED_SERVER_SIDE_SETTINGS = [
"utilization.logical_processors",
"utilization.total_ram_mib",
"utilization.billing_hostname",
]
class _NullHandler(logging.Handler):
def emit(self, record):
pass
_logger = logging.getLogger(__name__)
_logger.addHandler(_NullHandler())
# The Settings objects and the global default settings. We create a
# distinct type for each sub category of settings that the agent knows
# about so that an error when accessing a non-existent setting is more
# descriptive and identifies the category of settings. When applying
# server side configuration we create normal Settings object for new
# sub categories we don't know about.
class Settings(object):
nested = False
def __repr__(self):
return repr(self.__dict__)
def __iter__(self):
return iter(flatten_settings(self).items())
def __contains__(self, item):
return hasattr(self, item)
def create_settings(nested):
return type("Settings", (Settings,), {"nested": nested})()
class TopLevelSettings(Settings):
_host = None
_otlp_host = None
@property
def host(self):
if self._host:
return self._host
return default_host(self.license_key)
@host.setter
def host(self, value):
self._host = value
@property
def otlp_host(self):
if self._otlp_host:
return self._otlp_host
return default_otlp_host(self.host)
@otlp_host.setter
def otlp_host(self, value):
self._otlp_host = value
class AttributesSettings(Settings):
pass
class GCRuntimeMetricsSettings(Settings):
enabled = False
class MemoryRuntimeMetricsSettings(Settings):
pass
class MachineLearningSettings(Settings):
pass
class MachineLearningInferenceEventsValueSettings(Settings):
pass
class AIMonitoringSettings(Settings):
@property
def llm_token_count_callback(self):
return self._llm_token_count_callback
class AIMonitoringStreamingSettings(Settings):
pass
class AIMonitoringRecordContentSettings(Settings):
pass
class PackageReportingSettings(Settings):
pass
class CodeLevelMetricsSettings(Settings):
pass
class ThreadProfilerSettings(Settings):
pass
class TransactionTracerSettings(Settings):
pass
class TransactionTracerAttributesSettings(Settings):
pass
class ErrorCollectorSettings(Settings):
@property
def error_group_callback(self):
return self._error_group_callback
class ErrorCollectorAttributesSettings(Settings):
pass
class BrowserMonitorSettings(Settings):
pass
class BrowserMonitorAttributesSettings(Settings):
pass
class TransactionNameSettings(Settings):
pass
class TransactionMetricsSettings(Settings):
pass
class RumSettings(Settings):
pass
class SlowSqlSettings(Settings):
pass
class AgentLimitsSettings(Settings):
pass
class ConsoleSettings(Settings):
pass
class DebugSettings(Settings):
pass
class CrossApplicationTracerSettings(Settings):
pass
class TransactionEventsSettings(Settings):
pass
class TransactionEventsAttributesSettings(Settings):
pass
class CustomInsightsEventsSettings(Settings):
pass
class MlInsightsEventsSettings(Settings):
pass
class ProcessHostSettings(Settings):
pass
class SyntheticsSettings(Settings):
pass
class MessageTracerSettings(Settings):
pass
class UtilizationSettings(Settings):
pass
class StripExceptionMessageSettings(Settings):
pass
class DatastoreTracerSettings(Settings):
pass
class DatastoreTracerInstanceReportingSettings(Settings):
pass
class DatastoreTracerDatabaseNameReportingSettings(Settings):
pass
class HerokuSettings(Settings):
pass
class SpanEventSettings(Settings):
pass
class SpanEventAttributesSettings(Settings):
pass
class DistributedTracingSettings(Settings):
pass
class ServerlessModeSettings(Settings):
pass
class TransactionSegmentSettings(Settings):
pass
class TransactionSegmentAttributesSettings(Settings):
pass
class EventLoopVisibilitySettings(Settings):
pass
class ApplicationLoggingSettings(Settings):
pass
class ApplicationLoggingForwardingSettings(Settings):
pass
class ApplicationLoggingForwardingContextDataSettings(Settings):
pass
class ApplicationLoggingMetricsSettings(Settings):
pass
class ApplicationLoggingLocalDecoratingSettings(Settings):
pass
class InfiniteTracingSettings(Settings):
_trace_observer_host = None
@property
def enabled(self):
return bool(self._trace_observer_host)
@property
def trace_observer_host(self):
return self._trace_observer_host
@trace_observer_host.setter
def trace_observer_host(self, value):
if value and self._can_enable_infinite_tracing():
self._trace_observer_host = self._normalize_host(value)
else:
self._trace_observer_host = None
@staticmethod
def _normalize_host(value):
u = urlparse.urlparse(value)
if u.hostname:
_logger.warning(
"An invalid host (%s) was configured for infinite tracing. "
"A host of %s has been extracted by interpreting the "
"configuration value as a URL. An update to the configuration "
"value is recommended.",
value,
u.hostname,
)
return u.hostname
elif "/" in value or ":" in value:
_logger.error(
"An invalid host (%s) was configured for infinite tracing. "
"Please verify that only the host name was supplied via the "
"infinite tracing configuration. "
"Falling back to infinite tracing disabled.",
value,
)
return None
return value
@staticmethod
def _can_enable_infinite_tracing():
if grpc is None:
_logger.error(
"Unable to import libraries required for infinite tracing. "
"Please run pip install newrelic[infinite-tracing] "
"to install required dependencies. "
"Falling back to infinite tracing disabled."
)
return False
return True
class InstrumentationSettings(Settings):
pass
class InstrumentationGraphQLSettings(Settings):
pass
class EventHarvestConfigSettings(Settings):
nested = True
_lock = threading.Lock()
@property
def report_period_ms(self):
with self._lock:
return vars(_settings.event_harvest_config).get("report_period_ms", 60 * 1000)
@report_period_ms.setter
def report_period_ms(self, value):
with self._lock:
vars(_settings.event_harvest_config)["report_period_ms"] = value
vars(self)["report_period_ms"] = value
class EventHarvestConfigHarvestLimitSettings(Settings):
nested = True
_settings = TopLevelSettings()
_settings.agent_limits = AgentLimitsSettings()
_settings.application_logging = ApplicationLoggingSettings()
_settings.application_logging.forwarding = ApplicationLoggingForwardingSettings()
_settings.application_logging.forwarding.context_data = ApplicationLoggingForwardingContextDataSettings()
_settings.application_logging.metrics = ApplicationLoggingMetricsSettings()
_settings.application_logging.local_decorating = ApplicationLoggingLocalDecoratingSettings()
_settings.application_logging.metrics = ApplicationLoggingMetricsSettings()
_settings.machine_learning = MachineLearningSettings()
_settings.machine_learning.inference_events_value = MachineLearningInferenceEventsValueSettings()
_settings.ai_monitoring = AIMonitoringSettings()
_settings.ai_monitoring.streaming = AIMonitoringStreamingSettings()
_settings.ai_monitoring.record_content = AIMonitoringRecordContentSettings()
_settings.package_reporting = PackageReportingSettings()
_settings.attributes = AttributesSettings()
_settings.browser_monitoring = BrowserMonitorSettings()
_settings.browser_monitoring.attributes = BrowserMonitorAttributesSettings()
_settings.code_level_metrics = CodeLevelMetricsSettings()
_settings.console = ConsoleSettings()
_settings.cross_application_tracer = CrossApplicationTracerSettings()
_settings.custom_insights_events = CustomInsightsEventsSettings()
_settings.ml_insights_events = MlInsightsEventsSettings()
_settings.datastore_tracer = DatastoreTracerSettings()
_settings.datastore_tracer.database_name_reporting = DatastoreTracerDatabaseNameReportingSettings()
_settings.datastore_tracer.instance_reporting = DatastoreTracerInstanceReportingSettings()
_settings.debug = DebugSettings()
_settings.distributed_tracing = DistributedTracingSettings()
_settings.error_collector = ErrorCollectorSettings()
_settings.error_collector.attributes = ErrorCollectorAttributesSettings()
_settings.event_harvest_config = EventHarvestConfigSettings()
_settings.event_harvest_config.harvest_limits = EventHarvestConfigHarvestLimitSettings()
_settings.event_loop_visibility = EventLoopVisibilitySettings()
_settings.gc_runtime_metrics = GCRuntimeMetricsSettings()
_settings.memory_runtime_pid_metrics = MemoryRuntimeMetricsSettings()
_settings.heroku = HerokuSettings()
_settings.infinite_tracing = InfiniteTracingSettings()
_settings.instrumentation = InstrumentationSettings()
_settings.instrumentation.graphql = InstrumentationGraphQLSettings()
_settings.message_tracer = MessageTracerSettings()
_settings.process_host = ProcessHostSettings()
_settings.rum = RumSettings()
_settings.serverless_mode = ServerlessModeSettings()
_settings.slow_sql = SlowSqlSettings()
_settings.span_events = SpanEventSettings()
_settings.span_events.attributes = SpanEventAttributesSettings()
_settings.strip_exception_messages = StripExceptionMessageSettings()
_settings.synthetics = SyntheticsSettings()
_settings.thread_profiler = ThreadProfilerSettings()
_settings.transaction_events = TransactionEventsSettings()
_settings.transaction_events.attributes = TransactionEventsAttributesSettings()
_settings.transaction_metrics = TransactionMetricsSettings()
_settings.transaction_name = TransactionNameSettings()
_settings.transaction_segments = TransactionSegmentSettings()
_settings.transaction_segments.attributes = TransactionSegmentAttributesSettings()
_settings.transaction_tracer = TransactionTracerSettings()
_settings.transaction_tracer.attributes = TransactionTracerAttributesSettings()
_settings.utilization = UtilizationSettings()
_settings.log_file = os.environ.get("NEW_RELIC_LOG", None)
_settings.audit_log_file = os.environ.get("NEW_RELIC_AUDIT_LOG", None)
def _environ_as_int(name, default=0):
val = os.environ.get(name, default)
try:
return int(val)
except ValueError:
return default
def _environ_as_float(name, default=0.0):
val = os.environ.get(name, default)
try:
return float(val)
except ValueError:
return default
def _environ_as_bool(name, default=False):
flag = os.environ.get(name, default)
if default is None or default:
try:
flag = not flag.lower() in ["off", "false", "0"]
except AttributeError:
pass
else:
try:
flag = flag.lower() in ["on", "true", "1"]
except AttributeError:
pass
return flag
def _environ_as_set(name, default=""):
value = os.environ.get(name, default)
return set(value.split())
def _environ_as_mapping(name, default=""):
result = []
items = os.environ.get(name, default)
# Strip all whitespace and semicolons from the end of the string.
# That way, when we split a valid labels string by ';', the resulting
# list will contain no empty elements. When we loop through the
# elements, if we see one that is empty, or can't be split by ':',
# then we know the string has an invalid format.
items = items.strip("; \t\n\r\f\v")
if not items:
return result
for item in items.split(";"):
try:
key, value = item.split(":")
except ValueError:
_logger.warning(
"Invalid configuration. Cannot parse: %r. Expected format 'key1:value1;key2:value2 ... '.", items
)
result = []
break
key = key.strip()
value = value.strip()
if key and value:
result.append((key, value))
else:
_logger.warning(
"Invalid configuration. Cannot parse: %r. Expected format 'key1:value1;key2:value2 ... '.", items
)
result = []
break
return result
def _parse_status_codes(value, target):
items = value.split()
for item in items:
try:
negate = item.startswith("!")
if negate:
item = item[1:]
start, end = item.split("-")
values = set(range(int(start), int(end) + 1))
if negate:
target.difference_update(values)
else:
target.update(values)
except ValueError:
if negate:
target.discard(int(item))
else:
target.add(int(item))
return target
def _parse_attributes(s):
valid = []
for item in s.split():
if "*" not in item[:-1] and len(item.encode("utf-8")) < 256:
valid.append(item)
else:
_logger.warning("Improperly formatted attribute: %r", item)
return valid
def default_host(license_key):
if not license_key:
return "collector.newrelic.com"
region_aware_match = re.match("^(.+?)x", license_key)
if not region_aware_match:
return "collector.newrelic.com"
region = region_aware_match.group(1)
host = "collector." + region + ".nr-data.net"
return host
def default_otlp_host(host):
HOST_MAP = {
"collector.newrelic.com": "otlp.nr-data.net",
"collector.eu.newrelic.com": "otlp.eu01.nr-data.net",
"gov-collector.newrelic.com": "gov-otlp.nr-data.net",
"staging-collector.newrelic.com": "staging-otlp.nr-data.net",
"staging-collector.eu.newrelic.com": "staging-otlp.eu01.nr-data.net",
"staging-gov-collector.newrelic.com": "staging-gov-otlp.nr-data.net",
"fake-collector.newrelic.com": "fake-otlp.nr-data.net",
}
otlp_host = HOST_MAP.get(host, None)
if not otlp_host:
default = HOST_MAP["collector.newrelic.com"]
_logger.warn("Unable to find corresponding OTLP host using default %s" % default)
otlp_host = default
return otlp_host
_LOG_LEVEL = {
"CRITICAL": logging.CRITICAL,
"ERROR": logging.ERROR,
"WARNING": logging.WARNING,
"INFO": logging.INFO,
"DEBUG": logging.DEBUG,
}
_settings.enabled = _environ_as_bool("NEW_RELIC_ENABLED", False)
_settings.feature_flag = _environ_as_set("NEW_RELIC_FEATURE_FLAG", "")
_settings.log_level = os.environ.get("NEW_RELIC_LOG_LEVEL", "INFO").upper()
if _settings.log_level in _LOG_LEVEL:
_settings.log_level = _LOG_LEVEL[_settings.log_level]
else:
_settings.log_level = logging.INFO
_settings.license_key = os.environ.get("NEW_RELIC_LICENSE_KEY", None)
_settings.api_key = os.environ.get("NEW_RELIC_API_KEY", None)
_settings.ssl = _environ_as_bool("NEW_RELIC_SSL", True)
_settings.host = os.environ.get("NEW_RELIC_HOST")
_settings.otlp_host = os.environ.get("NEW_RELIC_OTLP_HOST")
_settings.port = int(os.environ.get("NEW_RELIC_PORT", "0"))
_settings.otlp_port = int(os.environ.get("NEW_RELIC_OTLP_PORT", "0"))
_settings.agent_run_id = None
_settings.entity_guid = None
_settings.request_headers_map = {}
_settings.proxy_scheme = os.environ.get("NEW_RELIC_PROXY_SCHEME", None)
_settings.proxy_host = os.environ.get("NEW_RELIC_PROXY_HOST", None)
_settings.proxy_port = int(os.environ.get("NEW_RELIC_PROXY_PORT", "0"))
_settings.proxy_user = os.environ.get("NEW_RELIC_PROXY_USER", None)
_settings.proxy_pass = os.environ.get("NEW_RELIC_PROXY_PASS", None)
_settings.ca_bundle_path = os.environ.get("NEW_RELIC_CA_BUNDLE_PATH", None)
_settings.app_name = os.environ.get("NEW_RELIC_APP_NAME", "Python Application")
_settings.linked_applications = []
_settings.process_host.display_name = os.environ.get("NEW_RELIC_PROCESS_HOST_DISPLAY_NAME", None)
_settings.labels = _environ_as_mapping("NEW_RELIC_LABELS", "")
_settings.monitor_mode = _environ_as_bool("NEW_RELIC_MONITOR_MODE", True)
_settings.developer_mode = _environ_as_bool("NEW_RELIC_DEVELOPER_MODE", False)
_settings.high_security = _environ_as_bool("NEW_RELIC_HIGH_SECURITY", False)
_settings.attribute_filter = None
_settings.collect_errors = True
_settings.collect_error_events = True
_settings.collect_traces = True
_settings.collect_span_events = True
_settings.collect_analytics_events = True
_settings.collect_custom_events = True
_settings.apdex_t = _environ_as_float("NEW_RELIC_APDEX_T", 0.5)
_settings.web_transactions_apdex = {}
_settings.capture_params = None
_settings.ignored_params = []
_settings.capture_environ = True
_settings.include_environ = [
"REQUEST_METHOD",
"HTTP_USER_AGENT",
"HTTP_REFERER",
"CONTENT_TYPE",
"CONTENT_LENGTH",
"HTTP_HOST",
"HTTP_ACCEPT",
]
_settings.max_stack_trace_lines = 50
_settings.sampling_rate = 0
_settings.startup_timeout = float(os.environ.get("NEW_RELIC_STARTUP_TIMEOUT", "0.0"))
_settings.shutdown_timeout = float(os.environ.get("NEW_RELIC_SHUTDOWN_TIMEOUT", "2.5"))
_settings.beacon = None
_settings.error_beacon = None
_settings.application_id = None
_settings.browser_key = None
_settings.episodes_url = None
_settings.js_agent_loader = None
_settings.js_agent_file = None
_settings.url_rules = []
_settings.metric_name_rules = []
_settings.transaction_name_rules = []
_settings.transaction_segment_terms = []
_settings.account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID")
_settings.cross_process_id = None
_settings.primary_application_id = os.environ.get("NEW_RELIC_PRIMARY_APPLICATION_ID", "Unknown")
_settings.trusted_account_ids = []
_settings.trusted_account_key = os.environ.get("NEW_RELIC_TRUSTED_ACCOUNT_KEY")
_settings.encoding_key = None
_settings.sampling_target = 10
_settings.sampling_target_period_in_seconds = 60
_settings.compressed_content_encoding = "gzip"
_settings.max_payload_size_in_bytes = 1000000
_settings.attributes.enabled = True
_settings.attributes.exclude = []
_settings.attributes.include = []
_settings.thread_profiler.enabled = True
_settings.cross_application_tracer.enabled = False
_settings.gc_runtime_metrics.enabled = False
_settings.gc_runtime_metrics.top_object_count_limit = 5
_settings.memory_runtime_pid_metrics.enabled = _environ_as_bool(
"NEW_RELIC_MEMORY_RUNTIME_PID_METRICS_ENABLED", default=True
)
_settings.transaction_events.enabled = True
_settings.transaction_events.attributes.enabled = True
_settings.transaction_events.attributes.exclude = []
_settings.transaction_events.attributes.include = []
_settings.custom_insights_events.enabled = True
_settings.custom_insights_events.max_attribute_value = _environ_as_int(
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_ATTRIBUTE_VALUE", default=MAX_ATTRIBUTE_LENGTH
)
_settings.ml_insights_events.enabled = False
_settings.distributed_tracing.enabled = _environ_as_bool("NEW_RELIC_DISTRIBUTED_TRACING_ENABLED", default=True)
_settings.distributed_tracing.exclude_newrelic_header = False
_settings.span_events.enabled = _environ_as_bool("NEW_RELIC_SPAN_EVENTS_ENABLED", default=True)
_settings.span_events.attributes.enabled = True
_settings.span_events.attributes.exclude = []
_settings.span_events.attributes.include = []
_settings.transaction_segments.attributes.enabled = True
_settings.transaction_segments.attributes.exclude = []
_settings.transaction_segments.attributes.include = []
_settings.transaction_tracer.enabled = True
_settings.transaction_tracer.transaction_threshold = None
_settings.transaction_tracer.record_sql = "obfuscated"
_settings.transaction_tracer.stack_trace_threshold = 0.5
_settings.transaction_tracer.explain_enabled = True
_settings.transaction_tracer.explain_threshold = 0.5
_settings.transaction_tracer.function_trace = []
_settings.transaction_tracer.generator_trace = []
_settings.transaction_tracer.top_n = 20
_settings.transaction_tracer.attributes.enabled = True
_settings.transaction_tracer.attributes.exclude = []
_settings.transaction_tracer.attributes.include = []
_settings.error_collector.enabled = True
_settings.error_collector.capture_events = True
_settings.error_collector.capture_source = False
_settings.error_collector.ignore_classes = []
_settings.error_collector.ignore_status_codes = _parse_status_codes("100-102 200-208 226 300-308 404", set())
_settings.error_collector.expected_classes = []
_settings.error_collector.expected_status_codes = set()
_settings.error_collector._error_group_callback = None
_settings.error_collector.attributes.enabled = True
_settings.error_collector.attributes.exclude = []
_settings.error_collector.attributes.include = []
_settings.browser_monitoring.enabled = True
_settings.browser_monitoring.auto_instrument = True
_settings.browser_monitoring.loader = "rum" # Valid values: 'full', 'none'
_settings.browser_monitoring.loader_version = None
_settings.browser_monitoring.debug = False
_settings.browser_monitoring.ssl_for_http = None
_settings.browser_monitoring.content_type = ["text/html"]
_settings.browser_monitoring.attributes.enabled = False
_settings.browser_monitoring.attributes.exclude = []
_settings.browser_monitoring.attributes.include = []
_settings.transaction_name.limit = None
_settings.transaction_name.naming_scheme = os.environ.get("NEW_RELIC_TRANSACTION_NAMING_SCHEME")
_settings.slow_sql.enabled = True
_settings.synthetics.enabled = True
_settings.agent_limits.data_collector_timeout = 30.0
_settings.agent_limits.transaction_traces_nodes = 2000
_settings.agent_limits.sql_query_length_maximum = 16384
_settings.agent_limits.slow_sql_stack_trace = 30
_settings.agent_limits.max_sql_connections = 4
_settings.agent_limits.sql_explain_plans = 30
_settings.agent_limits.sql_explain_plans_per_harvest = 60
_settings.agent_limits.slow_sql_data = 10
_settings.agent_limits.merge_stats_maximum = None
_settings.agent_limits.errors_per_transaction = 5
_settings.agent_limits.errors_per_harvest = 20
_settings.agent_limits.slow_transaction_dry_harvests = 5
_settings.agent_limits.thread_profiler_nodes = 20000
_settings.agent_limits.synthetics_events = 200
_settings.agent_limits.synthetics_transactions = 20
_settings.agent_limits.data_compression_threshold = 64 * 1024
_settings.agent_limits.data_compression_level = None
_settings.infinite_tracing.trace_observer_host = os.environ.get("NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_HOST", None)
_settings.infinite_tracing.trace_observer_port = _environ_as_int("NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_PORT", 443)
_settings.infinite_tracing.compression = _environ_as_bool("NEW_RELIC_INFINITE_TRACING_COMPRESSION", default=True)
_settings.infinite_tracing.batching = _environ_as_bool("NEW_RELIC_INFINITE_TRACING_BATCHING", default=True)
_settings.infinite_tracing.ssl = True
_settings.infinite_tracing.span_queue_size = _environ_as_int("NEW_RELIC_INFINITE_TRACING_SPAN_QUEUE_SIZE", 10000)
_settings.instrumentation.graphql.capture_introspection_queries = os.environ.get(
"NEW_RELIC_INSTRUMENTATION_GRAPHQL_CAPTURE_INTROSPECTION_QUERIES", False
)
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE
)
_settings.event_harvest_config.harvest_limits.custom_event_data = _environ_as_int(
"NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", CUSTOM_EVENT_RESERVOIR_SIZE
)
_settings.event_harvest_config.harvest_limits.ml_event_data = _environ_as_int(
"NEW_RELIC_ML_INSIGHTS_EVENTS_MAX_SAMPLES_STORED", ML_EVENT_RESERVOIR_SIZE
)
_settings.event_harvest_config.harvest_limits.span_event_data = _environ_as_int(
"NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED", SPAN_EVENT_RESERVOIR_SIZE
)
_settings.event_harvest_config.harvest_limits.error_event_data = _environ_as_int(
"NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED", ERROR_EVENT_RESERVOIR_SIZE
)
_settings.event_harvest_config.harvest_limits.log_event_data = _environ_as_int(
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_MAX_SAMPLES_STORED", LOG_EVENT_RESERVOIR_SIZE
)
_settings.console.listener_socket = None
_settings.console.allow_interpreter_cmd = False
_settings.debug.ignore_all_server_settings = False
_settings.debug.local_settings_overrides = []
_settings.debug.disable_api_supportability_metrics = False
_settings.debug.log_agent_initialization = False
_settings.debug.log_data_collector_calls = False
_settings.debug.log_data_collector_payloads = False
_settings.debug.log_malformed_json_data = False
_settings.debug.log_transaction_trace_payload = False
_settings.debug.log_thread_profile_payload = False
_settings.debug.log_normalization_rules = False
_settings.debug.log_raw_metric_data = False
_settings.debug.log_normalized_metric_data = False
_settings.debug.log_explain_plan_queries = False
_settings.debug.log_autorum_middleware = False
_settings.debug.record_transaction_failure = False
_settings.debug.enable_coroutine_profiling = False
_settings.debug.explain_plan_obfuscation = "simple"
_settings.debug.disable_certificate_validation = False
_settings.debug.log_untrusted_distributed_trace_keys = False
_settings.debug.disable_harvest_until_shutdown = False
_settings.debug.connect_span_stream_in_developer_mode = False
_settings.debug.otlp_content_encoding = None
_settings.message_tracer.segment_parameters_enabled = True
_settings.utilization.detect_aws = True
_settings.utilization.detect_azure = True
_settings.utilization.detect_docker = True
_settings.utilization.detect_kubernetes = True
_settings.utilization.detect_gcp = True
_settings.utilization.detect_pcf = True
_settings.utilization.logical_processors = _environ_as_int("NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS")
_settings.utilization.total_ram_mib = _environ_as_int("NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB")
_settings.utilization.billing_hostname = os.environ.get("NEW_RELIC_UTILIZATION_BILLING_HOSTNAME")
_settings.strip_exception_messages.enabled = False
_settings.strip_exception_messages.allowlist = []
_settings.datastore_tracer.instance_reporting.enabled = True
_settings.datastore_tracer.database_name_reporting.enabled = True
_settings.heroku.use_dyno_names = _environ_as_bool("NEW_RELIC_HEROKU_USE_DYNO_NAMES", default=True)
_settings.heroku.dyno_name_prefixes_to_shorten = list(
_environ_as_set("NEW_RELIC_HEROKU_DYNO_NAME_PREFIXES_TO_SHORTEN", "scheduler run")
)
_settings.serverless_mode.enabled = _environ_as_bool("NEW_RELIC_SERVERLESS_MODE_ENABLED", default=False)
_settings.aws_lambda_metadata = {}
_settings.event_loop_visibility.enabled = True
_settings.event_loop_visibility.blocking_threshold = 0.1
_settings.code_level_metrics.enabled = True
_settings.application_logging.enabled = _environ_as_bool("NEW_RELIC_APPLICATION_LOGGING_ENABLED", default=True)
_settings.application_logging.forwarding.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED", default=True
)
_settings.application_logging.forwarding.context_data.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_ENABLED", default=False
)
_settings.application_logging.forwarding.context_data.include = _environ_as_set(
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_INCLUDE", default=""
)
_settings.application_logging.forwarding.context_data.exclude = _environ_as_set(
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_EXCLUDE", default=""
)
_settings.application_logging.metrics.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_METRICS_ENABLED", default=True
)
_settings.application_logging.local_decorating.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED", default=False
)
_settings.machine_learning.enabled = _environ_as_bool("NEW_RELIC_MACHINE_LEARNING_ENABLED", default=False)
_settings.machine_learning.inference_events_value.enabled = _environ_as_bool(
"NEW_RELIC_MACHINE_LEARNING_INFERENCE_EVENT_VALUE_ENABLED", default=False
)
_settings.ai_monitoring.enabled = _environ_as_bool("NEW_RELIC_AI_MONITORING_ENABLED", default=False)
_settings.ai_monitoring.streaming.enabled = _environ_as_bool("NEW_RELIC_AI_MONITORING_STREAMING_ENABLED", default=True)
_settings.ai_monitoring.record_content.enabled = _environ_as_bool(
"NEW_RELIC_AI_MONITORING_RECORD_CONTENT_ENABLED", default=True
)
_settings.ai_monitoring._llm_token_count_callback = None
_settings.package_reporting.enabled = _environ_as_bool("NEW_RELIC_PACKAGE_REPORTING_ENABLED", default=True)
_settings.ml_insights_events.enabled = _environ_as_bool("NEW_RELIC_ML_INSIGHTS_EVENTS_ENABLED", default=False)
def global_settings():
"""This returns the default global settings. Generally only used
directly in test scripts and test harnesses or when applying global
settings from agent configuration file. Making changes to the settings
object returned by this function will not have any effect on any
applications that have already been initialised. This is because when
the settings are obtained from the core application a snapshot of these
settings will be taken.
>>> global_settings = global_settings()
>>> global_settings.browser_monitoring.auto_instrument = True
>>> global_settings.browser_monitoring.auto_instrument
True
"""
return _settings
def flatten_settings(settings):
"""This returns dictionary of settings flattened into a single
key namespace or a nested hierarchy according to the settings object.
"""
def _flatten(settings, o, name=None):
for key, value in vars(o).items():
# Remove any leading underscores on keys accessed through
# properties for reporting.
if key.startswith("_"):
key = key[1:]
if name:
key = "%s.%s" % (name, key)
if isinstance(value, Settings):
if value.nested:
_settings = settings[key] = {}
_flatten(_settings, value)