Skip to content

Commit 4690b6f

Browse files
Adjust Log Messages (#507)
* Tiny adjustments from support pairing * [Mega-Linter] Apply linters fixes * Fix type error * [Mega-Linter] Apply linters fixes * Trigger tests Co-authored-by: TimPansino <[email protected]> Co-authored-by: Uma Annamalai <[email protected]>
1 parent cea37d2 commit 4690b6f

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

newrelic/api/log.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import re
1615
import json
1716
import logging
18-
17+
import re
1918
from logging import Formatter, LogRecord
2019

21-
from newrelic.core.attribute import truncate
2220
from newrelic.api.time_trace import get_linking_metadata
2321
from newrelic.api.transaction import current_transaction
24-
from newrelic.common.object_names import parse_exc_info
2522
from newrelic.common import agent_http
23+
from newrelic.common.object_names import parse_exc_info
24+
from newrelic.core.attribute import truncate
2625
from newrelic.core.config import global_settings, is_expected_error
2726

2827

@@ -89,7 +88,7 @@ def safe_str(object, *args, **kwargs):
8988
class NewRelicLogHandler(logging.Handler):
9089
"""This is an experimental log handler provided by the community. Use with caution."""
9190

92-
PATH="/log/v1"
91+
PATH = "/log/v1"
9392

9493
def __init__(
9594
self,
@@ -141,7 +140,13 @@ def emit(self, record):
141140
"An unexpected HTTP response of %r was received for request made to https://%s:%d%s."
142141
"The response payload for the request was %r. If this issue persists then please "
143142
"report this problem to New Relic support for further investigation."
144-
% (status_code, self.client._host, self.client._port, self.PATH, truncate(response.decode("utf-8"), maxlen=1024))
143+
% (
144+
status_code,
145+
self.client._host,
146+
self.client._port,
147+
self.PATH,
148+
truncate(response.decode("utf-8"), 1024),
149+
)
145150
)
146151

147152
except Exception:

newrelic/core/agent_protocol.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from newrelic import version
1919
from newrelic.common import system_info
2020
from newrelic.common.agent_http import ApplicationModeClient, ServerlessModeClient
21-
from newrelic.core.internal_metrics import internal_count_metric
2221
from newrelic.common.encoding_utils import (
2322
json_decode,
2423
json_encode,
@@ -32,11 +31,13 @@
3231
KubernetesUtilization,
3332
PCFUtilization,
3433
)
34+
from newrelic.core.attribute import truncate
3535
from newrelic.core.config import (
3636
fetch_config_setting,
3737
finalize_application_settings,
3838
global_settings_dump,
3939
)
40+
from newrelic.core.internal_metrics import internal_count_metric
4041
from newrelic.network.exceptions import (
4142
DiscardDataForRequest,
4243
ForceAgentDisconnect,
@@ -135,9 +136,7 @@ class AgentProtocol(object):
135136
),
136137
),
137138
}
138-
PARAMS_ALLOWLIST = frozenset(
139-
("method", "protocol_version", "marshal_format", "run_id")
140-
)
139+
PARAMS_ALLOWLIST = frozenset(("method", "protocol_version", "marshal_format", "run_id"))
141140

142141
SECURITY_SETTINGS = (
143142
"capture_params",
@@ -219,9 +218,7 @@ def send(self, method, payload=()):
219218
params, headers, payload = self._to_http(method, payload)
220219

221220
try:
222-
response = self.client.send_request(
223-
params=params, headers=headers, payload=payload
224-
)
221+
response = self.client.send_request(params=params, headers=headers, payload=payload)
225222
except NetworkInterfaceException:
226223
# All HTTP errors are currently retried
227224
raise RetryDataForRequest
@@ -245,10 +242,8 @@ def send(self, method, payload=()):
245242
"method": method,
246243
"status_code": status,
247244
"headers": headers,
248-
"params": {
249-
k: v for k, v in params.items() if k in self.PARAMS_ALLOWLIST
250-
},
251-
"content": data,
245+
"params": {k: v for k, v in params.items() if k in self.PARAMS_ALLOWLIST},
246+
"content": truncate(data, 1024),
252247
"agent_run_id": self._run_token,
253248
},
254249
)
@@ -277,26 +272,18 @@ def _connect_payload(app_name, linked_applications, environment, settings):
277272
ip_address = system_info.getips()
278273

279274
connect_settings = {}
280-
connect_settings["browser_monitoring.loader"] = settings[
281-
"browser_monitoring.loader"
282-
]
283-
connect_settings["browser_monitoring.debug"] = settings[
284-
"browser_monitoring.debug"
285-
]
275+
connect_settings["browser_monitoring.loader"] = settings["browser_monitoring.loader"]
276+
connect_settings["browser_monitoring.debug"] = settings["browser_monitoring.debug"]
286277

287278
security_settings = {}
288279
security_settings["capture_params"] = settings["capture_params"]
289280
security_settings["transaction_tracer"] = {}
290-
security_settings["transaction_tracer"]["record_sql"] = settings[
291-
"transaction_tracer.record_sql"
292-
]
281+
security_settings["transaction_tracer"]["record_sql"] = settings["transaction_tracer.record_sql"]
293282

294283
utilization_settings = {}
295284
# metadata_version corresponds to the utilization spec being used.
296285
utilization_settings["metadata_version"] = 5
297-
utilization_settings[
298-
"logical_processors"
299-
] = system_info.logical_processor_count()
286+
utilization_settings["logical_processors"] = system_info.logical_processor_count()
300287
utilization_settings["total_ram_mib"] = system_info.total_physical_memory()
301288
utilization_settings["hostname"] = hostname
302289
if ip_address:
@@ -451,9 +438,7 @@ def connect(
451438
with cls(settings, host=redirect_host, client_cls=client_cls) as protocol:
452439
configuration = protocol.send(
453440
"connect",
454-
cls._connect_payload(
455-
app_name, linked_applications, environment, settings
456-
),
441+
cls._connect_payload(app_name, linked_applications, environment, settings),
457442
)
458443

459444
# Apply High Security Mode to server_config, so the local
@@ -487,9 +472,7 @@ def finalize(self):
487472

488473
class ServerlessModeProtocol(AgentProtocol):
489474
def __init__(self, settings, host=None, client_cls=ServerlessModeClient):
490-
super(ServerlessModeProtocol, self).__init__(
491-
settings, host=host, client_cls=client_cls
492-
)
475+
super(ServerlessModeProtocol, self).__init__(settings, host=host, client_cls=client_cls)
493476
self._metadata = {
494477
"protocol_version": self.VERSION,
495478
"execution_environment": os.environ.get("AWS_EXECUTION_ENV", None),
@@ -525,9 +508,7 @@ def connect(
525508
client_cls=ServerlessModeClient,
526509
):
527510
aws_lambda_metadata = settings.aws_lambda_metadata
528-
settings = finalize_application_settings(
529-
{"cross_application_tracer.enabled": False}, settings
530-
)
511+
settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings)
531512
# Metadata must come from the original settings object since it
532513
# can be modified later
533514
settings.aws_lambda_metadata = aws_lambda_metadata

newrelic/core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ def error_matches_rules(
11571157

11581158
if not settings:
11591159
# Unable to find rules to match with
1160-
_logger.error(
1160+
_logger.debug(
11611161
"Failed to retrieve exception rules: No settings supplied, or found on transaction or trace."
11621162
)
11631163
return None

0 commit comments

Comments
 (0)