Skip to content

Commit ff06c25

Browse files
authored
Bugfix: Apex code snippets auto-truncated (#758)
* Fixed #756 by truncating the Apex code snippets that are saved in the LogEntry__c fields OriginSourceSnippet__c and ExceptionSourceSnippet__c
1 parent 5c4e09e commit ff06c25

6 files changed

Lines changed: 23 additions & 18 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, Process Builder & integrations.
77

8-
## Unlocked Package - v4.14.8
8+
## Unlocked Package - v4.14.9
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oS1QAI)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oS1QAI)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oSQQAY)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oSQQAY)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oS1QAI`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oSQQAY`
1515

16-
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oS1QAI`
16+
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oSQQAY`
1717

1818
---
1919

nebula-logger/core/main/log-management/classes/LogEntryHandler.cls

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,15 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
431431
this.StackTrace = stackTrace;
432432

433433
List<String> allCodeLines = sourceCode.split('\n');
434-
this.setLineNumbers(stackTrace.Source.LineNumber, allCodeLines);
434+
this.setLineNumbers(stackTrace.Source?.LineNumber, allCodeLines);
435435
this.setCode(allCodeLines);
436436
}
437437

438-
private List<String> setLineNumbers(Integer targetLineNumber, List<String> allCodeLines) {
438+
private void setLineNumbers(Integer targetLineNumber, List<String> allCodeLines) {
439+
if (targetLineNumber == null) {
440+
return;
441+
}
442+
439443
Integer numberOfCodeLines = allCodeLines.size();
440444

441445
// TODO consider making these values configurable with 2 new LoggerParameter__mdt records
@@ -456,8 +460,6 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
456460
this.StartingLineNumber = calculcatedStartingLineNumber;
457461
this.TargetLineNumber = targetLineNumber;
458462
this.EndingLineNumber = calculatedEndingLineNumber;
459-
460-
return allCodeLines;
461463
}
462464

463465
private void setCode(List<String> allCodeLines) {
@@ -468,7 +470,10 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
468470
snippetCodeLines.add(allCodeLines.get(targetLineNumberIndex));
469471
}
470472

471-
this.Code = String.join(snippetCodeLines, '\n');
473+
// The field length for OriginSourceSnippet__c and ExceptionSourceSnippet__c is set to 2,000 - but that includes storing
474+
// both the code itself, as well as other JSON data. Using left(1500) should leave room for the other JSON data
475+
// while still avoiding exceeding the field's max length.
476+
this.Code = String.join(snippetCodeLines, '\n').left(1500);
472477
}
473478
}
474479

@@ -540,7 +545,6 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
540545
}
541546

542547
// Newer, general-purpose 'origin source' fields
543-
logEntry.OriginSourceActionName__c = originStackTrace.Source.ActionName;
544548
logEntry.OriginSourceApiVersion__c = 'v' + apexClass.ApiVersion;
545549
logEntry.OriginSourceCreatedById__c = apexClass.CreatedById;
546550
logEntry.OriginSourceCreatedByUsername__c = apexClass.CreatedBy.Username;

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.14.8';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.14.9';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';

nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FORM_FACTOR from '@salesforce/client/formFactor';
66
import { log as lightningLog } from 'lightning/logger';
77
import { LoggerStackTrace } from './loggerStackTrace';
88

9-
const CURRENT_VERSION_NUMBER = 'v4.14.8';
9+
const CURRENT_VERSION_NUMBER = 'v4.14.9';
1010

1111
const LOGGING_LEVEL_EMOJIS = {
1212
ERROR: '⛔',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nebula-logger",
3-
"version": "4.14.8",
3+
"version": "4.14.9",
44
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
55
"author": "Jonathan Gillespie",
66
"license": "MIT",

sfdx-project.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"path": "./nebula-logger/core",
1010
"definitionFile": "./config/scratch-orgs/build-base-scratch-def.json",
1111
"scopeProfiles": true,
12-
"versionNumber": "4.14.8.NEXT",
13-
"versionName": " Store HttpRequest header keys & values",
14-
"versionDescription": "Added method overload setHttpRequestDetails(HttpRequest request, List<String> headersToLog) in LogEntryEventBuilder to capture the specified list of header keys & values when logging an instance of HttpRequest",
12+
"versionNumber": "4.14.9.NEXT",
13+
"versionName": "Bugfix: Apex Code Snippets Auto-Truncated",
14+
"versionDescription": "Updated LogEntryHandler to automatically truncate the code snippets stored in OriginSourceSnippet__c and ExceptionSourceSnippet__c",
1515
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
1616
"unpackagedMetadata": {
1717
"path": "./nebula-logger/extra-tests"
@@ -192,7 +192,8 @@
192192
"Nebula Logger - Core@4.14.5-added-logger-settings-to-utility-bar": "04t5Y0000015oRXQAY",
193193
"Nebula Logger - Core@4.14.6-custom-field-mappings-support-for-lightning-components": "04t5Y0000015oRhQAI",
194194
"Nebula Logger - Core@4.14.7-bugfix:-us-social-security-number-data-mask-rule": "04t5Y0000015oRrQAI",
195-
"Nebula Logger - Core@4.14.8--store-httprequest-header-keys-&-values": "04t5Y0000015oS1QAI",
195+
"Nebula Logger - Core@4.14.8-store-httprequest-header-keys-&-values": "04t5Y0000015oS1QAI",
196+
"Nebula Logger - Core@4.14.9-bugfix:-apex-code-snippets-auto-truncated": "04t5Y0000015oSQQAY",
196197
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
197198
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
198199
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",

0 commit comments

Comments
 (0)