Skip to content

Commit 5835da6

Browse files
authored
Apex Observability Enhancements (#636)
* Added new Apex class LoggerStackTrace to manage stack trace parsing for Apex & JavaScript. This includes updating several classes to use LoggerStackTrace (instead of the old parsing logic that was scattered throughout the codebase). * Added new LogEntryEvent__e & LogEntry__c fields to track more stack trace-related data * Added more fields to the existing ApexClass query in the instance method LogManagementDataSelector.getApexClasses() * Updated the instance method LogManagementDataSelector.getApexClasses()to use Set<String> instead of List<String> as the parameter * Added new instance method LogManagementDataSelector.getApexTriggers() & LoggerParameter__mdt record to control querying of ApexTrigger data * Updated LogEntryHandler to generate & store snippets of ApexClass & ApexTrigger code for each log entry's origin & exception (when supplied) * Updated LogEntryHandler to set the new 'origin source' fields for Flow (where possible). The FlowDefinitionView and FlowVersionView objects don't have some of the typical audit fields for created by/date and last modified by, so not all 'origin source' fields are consistently set for Flows * Created new LWC logEntryMetadataViewer to display origin & exception snippets for Apex classes & triggers. This also includes 2 new helper LWCs - loggerCodeViewer & loggerPageSection - and a new static resource LoggerResources, containing PrismJS for formatting code blocks * Updated LWCs loggerHomeHeader and loggerSettings to use loggerPageSection * Updated LWC logViewer to use loggerCodeViewer * Performance improvements - cache network/organization/auth session/user usages in LogEntryEventBuilder * Fixed a testing issue where some tests were passing for the wrong reason due to a bug in LoggerMockDataCreator. Previously, it generated the same string value for every string field, resulting in an inaccurate assert in LogEntryEventHandler_Tests passing, even though the field mapping was wrong in the prod code. Now, the generated string starts with the field's API name, which should at least greatly reduce this issue (though with truncation, etc, there's still a chance it could happen again... good enough, for now) * Fixed .prettierrc for cls and xml files and re-formatted several files * Updated to new version of bummer plugin v0.0.20 to fix some issues with additional properties being unintentionally added to sfdx-project.json * Made some changes to some sample Apex classes for demo purposes
1 parent 2e07272 commit 5835da6

119 files changed

Lines changed: 7725 additions & 2905 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ yarn.lock
1717
# Files to exclude
1818
*.log
1919
**/lwc/jsconfig.json
20+
.config

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 logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.
77

8-
## Unlocked Package - v4.13.0
8+
## Unlocked Package - v4.13.1
99

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

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk8dQAC`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001MkE3QAK`
1515

16-
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk8dQAC`
16+
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001MkE3QAK`
1717

1818
---
1919

docs/apex/Configuration/LoggerParameter.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ The name of the Platform Cache partition to use for caching (when platform cache
5050

5151
Controls if Nebula Logger queries `ApexClass` data. When set to `false`, any `ApexClass` fields on `LogEntryEvent__e` and `Log__c` will not be populated Controlled by the custom metadata record `LoggerParameter.QueryApexClassData`, or `true` as the default
5252

53+
#### `QUERY_APEX_TRIGGER_DATA``Boolean`
54+
55+
Controls if Nebula Logger queries `ApexTrigger` data. When set to `false`, any `ApexTrigger` fields on `LogEntryEvent__e` and `Log__c` will not be populated Controlled by the custom metadata record `LoggerParameter.QueryApexTriggerData`, or `true` as the default
56+
5357
#### `QUERY_AUTH_SESSION_DATA``Boolean`
5458

5559
Controls if Nebula Logger queries `Schema.AuthSession` data. When set to `false`, any `Schema.AuthSession` fields on `LogEntryEvent__e` and `Log__c` will not be populated Controlled by the custom metadata record `LoggerParameter.QueryAuthSessionData`, or `true` as the default

docs/apex/Log-Management/LogEntryHandler.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Manages setting fields on `LogEntry__c` before insert &amp; before update
1010

1111
### Methods
1212

13+
#### `apply(LogEntry__c logEntry, Schema.ApexClass topLevelApexClass)``void`
14+
15+
#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`
16+
17+
#### `apply(LogEntry__c logEntry, Schema.ApexClass apexClass)``void`
18+
19+
#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`
20+
21+
#### `apply(LogEntry__c logEntry, Schema.ApexClass apexClass)``void`
22+
23+
#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`
24+
1325
#### `getSObjectType()``Schema.SObjectType`
1426

1527
Returns SObject Type that the handler is responsible for processing
@@ -25,3 +37,37 @@ Schema.SObjectType
2537
The instance of `SObjectType`
2638

2739
---
40+
41+
### Inner Classes
42+
43+
#### LogEntryHandler.SourceMetadataSnippet class
44+
45+
---
46+
47+
##### Constructors
48+
49+
###### `SourceMetadataSnippet(LoggerStackTrace stackTrace, Schema.ApexClass apexClass)`
50+
51+
###### `SourceMetadataSnippet(LoggerStackTrace stackTrace, Schema.ApexTrigger apexTrigger)`
52+
53+
---
54+
55+
##### Properties
56+
57+
###### `ApiVersion``String`
58+
59+
###### `Code``String`
60+
61+
###### `EndingLineNumber``Integer`
62+
63+
###### `Language``LoggerStackTrace.Source`
64+
65+
###### `StackTrace``Logger`
66+
67+
###### `StartingLineNumber``Integer`
68+
69+
###### `TargetLineNumber``Integer`
70+
71+
###### `TotalLinesOfCode``Integer`
72+
73+
---
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
layout: default
3+
---
4+
5+
## LogEntryMetadataViewerController class
6+
7+
Controller class for the LWC `logEntryMetadataViewer`
8+
9+
---
10+
11+
### Methods
12+
13+
#### `getMetadata(Id recordId, String sourceMetadata)``LogEntryMetadata`
14+
15+
Returns an instance of the inner class `LogEntryMetadataViewerController.LogEntryMetadata`, which contains information about the log entry&apos;s origin and exception Apex classes
16+
17+
##### Parameters
18+
19+
| Param | Description |
20+
| ---------------- | ---------------------------------------- |
21+
| `recordId` | The `ID` of the `LogEntry__c` record |
22+
| `sourceMetadata` | Either the value `Origin` or `Exception` |
23+
24+
##### Return
25+
26+
**Type**
27+
28+
LogEntryMetadata
29+
30+
**Description**
31+
32+
An instance of `LogEntryMetadataViewerController.LogEntryMetadata`
33+
34+
---
35+
36+
### Inner Classes
37+
38+
#### LogEntryMetadataViewerController.LogEntryMetadata class
39+
40+
---
41+
42+
##### Properties
43+
44+
###### `Code``String`
45+
46+
###### `HasCodeBeenModified``Boolean`
47+
48+
---

docs/apex/Log-Management/LogManagementDataSelector.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ List&lt;SObject&gt;
3131

3232
`List&lt;SObject&gt;` containing any records in the specified `SObjectType`
3333

34-
#### `getApexClasses(List<String> apexClassNames)``List<ApexClass>`
34+
#### `getApexClasses(Set<String> apexClassNames)``List<ApexClass>`
3535

3636
Returns a list of `ApexClass` records
3737

@@ -51,6 +51,26 @@ List&lt;ApexClass&gt;
5151

5252
`List&lt;ApexClass&gt;` containing any matching records
5353

54+
#### `getApexTriggers(Set<String> apexTriggerNames)``List<ApexTrigger>`
55+
56+
Returns a list of `ApexTrigger` records
57+
58+
##### Parameters
59+
60+
| Param | Description |
61+
| ------------------ | --------------------------------------- |
62+
| `apexTriggerNames` | The names of the Apex triggers to query |
63+
64+
##### Return
65+
66+
**Type**
67+
68+
List&lt;ApexTrigger&gt;
69+
70+
**Description**
71+
72+
`List&lt;ApexTrigger&gt;` containing any matching records
73+
5474
#### `getById(Schema.SObjectType sobjectType, Set<String> fieldNames, List<Id> recordIds)``List<SObject>`
5575

5676
Dynamically queries &amp; returns records in the specified `SObjectType` based on the specified record IDs
@@ -257,6 +277,26 @@ List&lt;LogEntry\_\_c&gt;
257277

258278
The matching `List&lt;LogEntry__c&gt;` records
259279

280+
#### `getLogEntryById(Id logEntryId)``LogEntry__c`
281+
282+
Returns a `LogEntry__c` record
283+
284+
##### Parameters
285+
286+
| Param | Description |
287+
| ------------ | --------------------------------------------- |
288+
| `logEntryId` | The `ID` of the `LogEntry__c` record to query |
289+
290+
##### Return
291+
292+
**Type**
293+
294+
LogEntry\_\_c
295+
296+
**Description**
297+
298+
The matching `LogEntry__c` record
299+
260300
#### `getLoggerScenariosById(List<Id> logScenarioIds)``List<LoggerScenario__c>`
261301

262302
Returns a `List&lt;LoggerScenario__c&gt;` of records with the specified log scenario IDs

docs/apex/Logger-Engine/LogEntryEventBuilder.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Builder class that generates each `LogEntryEvent__e` record
1616

1717
#### `LogEntryEventBuilder(LoggerSettings__c userSettings, System.LoggingLevel entryLoggingLevel, Boolean shouldSave, Set<String> ignoredOrigins)`
1818

19-
Used by `Logger` to instantiate a new instance of `LogEntryEventBuilder`
19+
`Deprecated` - Formally used by `Logger` to instantiate a new instance of `LogEntryEventBuilder`
2020

2121
##### Parameters
2222

@@ -27,6 +27,18 @@ Used by `Logger` to instantiate a new instance of `LogEntryEventBuilder`
2727
| `shouldSave` | Indicates if the builder&apos;s instance of `LogEntryEvent__e` should be saved |
2828
| `ignoredOrigins` | A `Set&lt;String&gt;` of the names of any Apex classes that should be ignored when parsing the entry&apos;s origin |
2929

30+
#### `LogEntryEventBuilder(LoggerSettings__c userSettings, System.LoggingLevel entryLoggingLevel, Boolean shouldSave)`
31+
32+
Used by `Logger` to instantiate a new instance of `LogEntryEventBuilder`
33+
34+
##### Parameters
35+
36+
| Param | Description |
37+
| ------------------- | --------------------------------------------------------------------------------------- |
38+
| `userSettings` | The instance of `LoggerSettings__c` for the current to use to control any feature flags |
39+
| `entryLoggingLevel` | The `LoggingLevel` value to use for the log entry |
40+
| `shouldSave` | Indicates if the builder&apos;s instance of `LogEntryEvent__e` should be saved |
41+
3042
---
3143

3244
### Methods

docs/apex/Logger-Engine/Logger.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,28 +5776,6 @@ List of records to save.
57765776

57775777
---
57785778

5779-
##### Methods
5780-
5781-
###### `Uuid()``public`
5782-
5783-
Default constructor
5784-
5785-
###### `getValue()``String`
5786-
5787-
Getter returning the uuid value
5788-
5789-
####### Return
5790-
5791-
**Type**
5792-
5793-
String
5794-
5795-
**Description**
5796-
5797-
A string containing the UUID value.
5798-
5799-
---
5800-
58015779
#### Logger.StatusApiResponseProduct class
58025780

58035781
---
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
layout: default
3+
---
4+
5+
## LoggerStackTrace class
6+
7+
Class used for tracking &amp; parsing stack traces
8+
9+
### Related
10+
11+
[Logger](Logger)
12+
13+
LogEntryBuilder
14+
15+
---
16+
17+
### Constructors
18+
19+
#### `LoggerStackTrace()`
20+
21+
Constructor that automatically generates &amp; parses stack trace information based on the calling code
22+
23+
#### `LoggerStackTrace(Exception apexException)`
24+
25+
Constructor that parses stack trace information from the provided `Exception`
26+
27+
##### Parameters
28+
29+
| Param | Description |
30+
| --------------- | ------------------------------------ |
31+
| `apexException` | An instance of any `Exception` class |
32+
33+
#### `LoggerStackTrace(String apexStackTraceString)`
34+
35+
Constructor that parses stack trace information from the provided `String`
36+
37+
##### Parameters
38+
39+
| Param | Description |
40+
| ---------------------- | -------------------------------------------------------- |
41+
| `apexStackTraceString` | The original stack trace value generated by the platform |
42+
43+
#### `LoggerStackTrace(SourceLanguage language, String sourceStackTraceString)`
44+
45+
---
46+
47+
### Enums
48+
49+
#### SourceLanguage
50+
51+
#### SourceMetadataType
52+
53+
---
54+
55+
### Properties
56+
57+
#### `Language``Source`
58+
59+
#### `Location``String`
60+
61+
#### `ParsedStackTraceString``String`
62+
63+
#### `Source``public`
64+
65+
---
66+
67+
### Methods
68+
69+
#### `AnonymousBlock()``public`
70+
71+
#### `ApexClass()``public`
72+
73+
#### `ApexTrigger()``public`
74+
75+
#### `AuraDefinitionBundle()``public`
76+
77+
#### `LightningComponentBundle()``public`
78+
79+
#### `ignoreOrigin(System.Type apexType)``void`
80+
81+
Adds the specified Apex type to the the current transaction&apos;s list of ignored origin locations. Any ignored types will be removed from the StackTrace\_\_c field, and will be skipped when determining the log entry&apos;s origin location
82+
83+
##### Parameters
84+
85+
| Param | Description |
86+
| ---------- | ------------------------------------ |
87+
| `apexType` | The Apex type of the class to ignore |
88+
89+
#### `ignoreOrigin(SourceLanguage language, String origin)``void`
90+
91+
Adds the specified string-based origin to the the current transaction&apos;s list of ignored origin locations for the specified source language. Any ignored types will be removed from the StackTrace\_\_c field, and will be skipped when determining the log entry&apos;s origin location
92+
93+
##### Parameters
94+
95+
| Param | Description |
96+
| ---------- | ---------------------------------------------------------------------------- |
97+
| `language` | The source language (Apex or JavaScript) |
98+
| `origin` | The string-based name of the Apex type or lightning component name to ignore |
99+
100+
#### `ignoreOrigins(Set<System.Type> apexTypes)``void`
101+
102+
Adds the specified Apex types to the list of ignored origin locations for the current transaction. Any ignored types will be removed from the StackTrace\_\_c field, and will be skipped when determining the log entry&apos;s origin location
103+
104+
##### Parameters
105+
106+
| Param | Description |
107+
| ----------- | ---------------------------------------------------------- |
108+
| `apexTypes` | A `Set` containing the Apex types of the classes to ignore |
109+
110+
---
111+
112+
### Inner Classes
113+
114+
#### LoggerStackTrace.SourceMetadata class
115+
116+
---
117+
118+
##### Properties
119+
120+
###### `ActionName``String`
121+
122+
###### `ApiName``String`
123+
124+
###### `LineNumber``Integer`
125+
126+
###### `MetadataType``Source`
127+
128+
---

0 commit comments

Comments
 (0)