Skip to content

Commit

Permalink
Apex Observability Enhancements (#636)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jongpie authored Feb 29, 2024
1 parent 2e07272 commit 5835da6
Show file tree
Hide file tree
Showing 119 changed files with 7,725 additions and 2,905 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ yarn.lock
# Files to exclude
*.log
**/lwc/jsconfig.json
.config
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.

## Unlocked Package - v4.13.0
## Unlocked Package - v4.13.1

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

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

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

---

Expand Down
4 changes: 4 additions & 0 deletions docs/apex/Configuration/LoggerParameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ The name of the Platform Cache partition to use for caching (when platform cache

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

#### `QUERY_APEX_TRIGGER_DATA``Boolean`

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

#### `QUERY_AUTH_SESSION_DATA``Boolean`

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
Expand Down
46 changes: 46 additions & 0 deletions docs/apex/Log-Management/LogEntryHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ Manages setting fields on `LogEntry__c` before insert &amp; before update

### Methods

#### `apply(LogEntry__c logEntry, Schema.ApexClass topLevelApexClass)``void`

#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`

#### `apply(LogEntry__c logEntry, Schema.ApexClass apexClass)``void`

#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`

#### `apply(LogEntry__c logEntry, Schema.ApexClass apexClass)``void`

#### `apply(LogEntry__c logEntry, Schema.ApexTrigger apexTrigger)``void`

#### `getSObjectType()``Schema.SObjectType`

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

---

### Inner Classes

#### LogEntryHandler.SourceMetadataSnippet class

---

##### Constructors

###### `SourceMetadataSnippet(LoggerStackTrace stackTrace, Schema.ApexClass apexClass)`

###### `SourceMetadataSnippet(LoggerStackTrace stackTrace, Schema.ApexTrigger apexTrigger)`

---

##### Properties

###### `ApiVersion``String`

###### `Code``String`

###### `EndingLineNumber``Integer`

###### `Language``LoggerStackTrace.Source`

###### `StackTrace``Logger`

###### `StartingLineNumber``Integer`

###### `TargetLineNumber``Integer`

###### `TotalLinesOfCode``Integer`

---
48 changes: 48 additions & 0 deletions docs/apex/Log-Management/LogEntryMetadataViewerController.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
layout: default
---

## LogEntryMetadataViewerController class

Controller class for the LWC `logEntryMetadataViewer`

---

### Methods

#### `getMetadata(Id recordId, String sourceMetadata)``LogEntryMetadata`

Returns an instance of the inner class `LogEntryMetadataViewerController.LogEntryMetadata`, which contains information about the log entry&apos;s origin and exception Apex classes

##### Parameters

| Param | Description |
| ---------------- | ---------------------------------------- |
| `recordId` | The `ID` of the `LogEntry__c` record |
| `sourceMetadata` | Either the value `Origin` or `Exception` |

##### Return

**Type**

LogEntryMetadata

**Description**

An instance of `LogEntryMetadataViewerController.LogEntryMetadata`

---

### Inner Classes

#### LogEntryMetadataViewerController.LogEntryMetadata class

---

##### Properties

###### `Code``String`

###### `HasCodeBeenModified``Boolean`

---
42 changes: 41 additions & 1 deletion docs/apex/Log-Management/LogManagementDataSelector.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ List&lt;SObject&gt;

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

#### `getApexClasses(List<String> apexClassNames)``List<ApexClass>`
#### `getApexClasses(Set<String> apexClassNames)``List<ApexClass>`

Returns a list of `ApexClass` records

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

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

#### `getApexTriggers(Set<String> apexTriggerNames)``List<ApexTrigger>`

Returns a list of `ApexTrigger` records

##### Parameters

| Param | Description |
| ------------------ | --------------------------------------- |
| `apexTriggerNames` | The names of the Apex triggers to query |

##### Return

**Type**

List&lt;ApexTrigger&gt;

**Description**

`List&lt;ApexTrigger&gt;` containing any matching records

#### `getById(Schema.SObjectType sobjectType, Set<String> fieldNames, List<Id> recordIds)``List<SObject>`

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

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

#### `getLogEntryById(Id logEntryId)``LogEntry__c`

Returns a `LogEntry__c` record

##### Parameters

| Param | Description |
| ------------ | --------------------------------------------- |
| `logEntryId` | The `ID` of the `LogEntry__c` record to query |

##### Return

**Type**

LogEntry\_\_c

**Description**

The matching `LogEntry__c` record

#### `getLoggerScenariosById(List<Id> logScenarioIds)``List<LoggerScenario__c>`

Returns a `List&lt;LoggerScenario__c&gt;` of records with the specified log scenario IDs
Expand Down
14 changes: 13 additions & 1 deletion docs/apex/Logger-Engine/LogEntryEventBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Builder class that generates each `LogEntryEvent__e` record

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

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

##### Parameters

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

#### `LogEntryEventBuilder(LoggerSettings__c userSettings, System.LoggingLevel entryLoggingLevel, Boolean shouldSave)`

Used by `Logger` to instantiate a new instance of `LogEntryEventBuilder`

##### Parameters

| Param | Description |
| ------------------- | --------------------------------------------------------------------------------------- |
| `userSettings` | The instance of `LoggerSettings__c` for the current to use to control any feature flags |
| `entryLoggingLevel` | The `LoggingLevel` value to use for the log entry |
| `shouldSave` | Indicates if the builder&apos;s instance of `LogEntryEvent__e` should be saved |

---

### Methods
Expand Down
22 changes: 0 additions & 22 deletions docs/apex/Logger-Engine/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -5776,28 +5776,6 @@ List of records to save.

---

##### Methods

###### `Uuid()``public`

Default constructor

###### `getValue()``String`

Getter returning the uuid value

####### Return

**Type**

String

**Description**

A string containing the UUID value.

---

#### Logger.StatusApiResponseProduct class

---
Expand Down
128 changes: 128 additions & 0 deletions docs/apex/Logger-Engine/LoggerStackTrace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
layout: default
---

## LoggerStackTrace class

Class used for tracking &amp; parsing stack traces

### Related

[Logger](Logger)

LogEntryBuilder

---

### Constructors

#### `LoggerStackTrace()`

Constructor that automatically generates &amp; parses stack trace information based on the calling code

#### `LoggerStackTrace(Exception apexException)`

Constructor that parses stack trace information from the provided `Exception`

##### Parameters

| Param | Description |
| --------------- | ------------------------------------ |
| `apexException` | An instance of any `Exception` class |

#### `LoggerStackTrace(String apexStackTraceString)`

Constructor that parses stack trace information from the provided `String`

##### Parameters

| Param | Description |
| ---------------------- | -------------------------------------------------------- |
| `apexStackTraceString` | The original stack trace value generated by the platform |

#### `LoggerStackTrace(SourceLanguage language, String sourceStackTraceString)`

---

### Enums

#### SourceLanguage

#### SourceMetadataType

---

### Properties

#### `Language``Source`

#### `Location``String`

#### `ParsedStackTraceString``String`

#### `Source``public`

---

### Methods

#### `AnonymousBlock()``public`

#### `ApexClass()``public`

#### `ApexTrigger()``public`

#### `AuraDefinitionBundle()``public`

#### `LightningComponentBundle()``public`

#### `ignoreOrigin(System.Type apexType)``void`

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

##### Parameters

| Param | Description |
| ---------- | ------------------------------------ |
| `apexType` | The Apex type of the class to ignore |

#### `ignoreOrigin(SourceLanguage language, String origin)``void`

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

##### Parameters

| Param | Description |
| ---------- | ---------------------------------------------------------------------------- |
| `language` | The source language (Apex or JavaScript) |
| `origin` | The string-based name of the Apex type or lightning component name to ignore |

#### `ignoreOrigins(Set<System.Type> apexTypes)``void`

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

##### Parameters

| Param | Description |
| ----------- | ---------------------------------------------------------- |
| `apexTypes` | A `Set` containing the Apex types of the classes to ignore |

---

### Inner Classes

#### LoggerStackTrace.SourceMetadata class

---

##### Properties

###### `ActionName``String`

###### `ApiName``String`

###### `LineNumber``Integer`

###### `MetadataType``Source`

---
Loading

0 comments on commit 5835da6

Please sign in to comment.