Skip to content

Commit

Permalink
Added logging support for instances of RestRequest and RestResponse (#…
Browse files Browse the repository at this point in the history
…613)

* Added new fields & instance method LogEntryEventBuilder.setRestResponseDetails() to store info on instances of System.RestResponse

* Added new fields & instance method LogEntryEventBuilder.setRestRequestDetails() to store info on instances of System.RestRequest

* Added new flexipage sections 'Apex REST Service Request' and 'Apex REST Service Response' in LogEntryRecordPage that conditionally display the new fields for RestRequest and RestResponse

* Renamed the existing flexipage sections 'HTTP Request' and 'HTTP Response' to 'HTTP Callout Request' and 'HTTP Callout Response' for clarity

* Reduced the max length of several existing long textarea fields to conserve some usage of the per-object limit - previously, these fields were all using the max length of 131072, which is more than what's needed
  • Loading branch information
jongpie authored Feb 2, 2024
1 parent 21e02ac commit f602f90
Show file tree
Hide file tree
Showing 65 changed files with 1,840 additions and 34 deletions.
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.12.8
## Unlocked Package - v4.12.9

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

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk6cQAC`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk7BQAS`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk6cQAC`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk7BQAS`

---

Expand Down
8 changes: 8 additions & 0 deletions docs/apex/Configuration/LoggerParameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ Indicates if Nebula Logger will send an error email notification if any internal

Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpResponse`. Controlled by the custom metadata record `LoggerParameter.StoreHttpResponseHeaderValues`, or `true` as the default. Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of `System.HttpResponse` that is logged - this parameter only controls if the header values are stored.

#### `STORE_REST_REQUEST_HEADER_VALUES``Boolean`

Indicates if Nebula Logger will store the header values when logging an instance of `System.RestRequest`. Controlled by the custom metadata record `LoggerParameter.StoreRestRequestHeaderValues`, or `true` as the default. Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of `System.RestRequest` that is logged - this parameter only controls if the header values are stored.

#### `STORE_REST_RESPONSE_HEADER_VALUES``Boolean`

Indicates if Nebula Logger will store the header values when logging an instance of `System.RestResponse`. Controlled by the custom metadata record `LoggerParameter.StoreRestResponseHeaderValues`, or `true` as the default. Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of `System.RestResponse` that is logged - this parameter only controls if the header values are stored.

#### `SYSTEM_DEBUG_MESSAGE_FORMAT``String`

The merge-field syntax to use when calling System.debug(). Controlled by the custom metadata record `LoggerParameter.SystebugMessageFormat`, or `{OriginLocation__c}\n{Message__c}` as the default
Expand Down
40 changes: 40 additions & 0 deletions docs/apex/Logger-Engine/LogEntryEventBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,46 @@ LogEntryEventBuilder

An instance of LogEntryEventBuilder with the given record.

#### `setRestRequestDetails(System.RestRequest request)``LogEntryEventBuilder`

Sets the log entry event's REST Request fields

##### Parameters

| Param | Description |
| --------- | ------------------------------------ |
| `request` | The instance of `RestRequest` to log |

##### Return

**Type**

LogEntryEventBuilder

**Description**

The same instance of `LogEntryEventBuilder`, useful for chaining methods

#### `setRestResponseDetails(System.RestResponse response)``LogEntryEventBuilder`

Sets the log entry event's REST Response fields

##### Parameters

| Param | Description |
| ---------- | ------------------------------------- |
| `response` | The instance of `RestResponse` to log |

##### Return

**Type**

LogEntryEventBuilder

**Description**

The same instance of `LogEntryEventBuilder`, useful for chaining methods

#### `setTopics(List<String> tags)``LogEntryEventBuilder`

Deprecated - use `addTags(List&lt;String&gt; tags)` instead. This method will be removed in a future release
Expand Down
32 changes: 32 additions & 0 deletions nebula-logger/core/main/configuration/classes/LoggerParameter.cls
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,38 @@ public class LoggerParameter {
private set;
}

/**
* @description Indicates if Nebula Logger will store the header values when logging an instance of `System.RestRequest`.
* Controlled by the custom metadata record `LoggerParameter.StoreRestRequestHeaderValues`, or `true` as the default.
* Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of
* `System.RestRequest` that is logged - this parameter only controls if the header values are stored.
*/
public static final Boolean STORE_REST_REQUEST_HEADER_VALUES {
get {
if (STORE_REST_REQUEST_HEADER_VALUES == null) {
STORE_REST_REQUEST_HEADER_VALUES = getBoolean('StoreRestRequestHeaderValues', true);
}
return STORE_REST_REQUEST_HEADER_VALUES;
}
private set;
}

/**
* @description Indicates if Nebula Logger will store the header values when logging an instance of `System.RestResponse`.
* Controlled by the custom metadata record `LoggerParameter.StoreRestResponseHeaderValues`, or `true` as the default.
* Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of
* `System.RestResponse` that is logged - this parameter only controls if the header values are stored.
*/
public static final Boolean STORE_REST_RESPONSE_HEADER_VALUES {
get {
if (STORE_REST_RESPONSE_HEADER_VALUES == null) {
STORE_REST_RESPONSE_HEADER_VALUES = getBoolean('StoreRestResponseHeaderValues', true);
}
return STORE_REST_RESPONSE_HEADER_VALUES;
}
private set;
}

/**
* @description The merge-field syntax to use when calling System.debug().
* Controlled by the custom metadata record `LoggerParameter.SystemDebugMessageFormat`, or `{OriginLocation__c}\n{Message__c}` as the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Store Http Response Header Values</label>
<label>Store HTTP Response Header Values</label>
<protected>false</protected>
<values>
<field>Description__c</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Store REST Request Header Values</label>
<protected>false</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>When set to &apos;true&apos; (default), Nebula Logger will store the header values of any instance of an RestRequest that is logged using the instance method LogEntryEventBuilder.setRestRequestDetails().

When set to &apos;false&apos;, the header values are not stored or referenced by Nebula Logger.

Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of an RestRequest that is logged - this parameter only controls if the header values are stored.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">true</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Store REST Response Header Values</label>
<protected>false</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>When set to &apos;true&apos; (default), Nebula Logger will store the header values of any instance of an RestResponse that is logged using the instance method LogEntryEventBuilder.setRestResponseDetails().

When set to &apos;false&apos;, the header values are not stored or referenced by Nebula Logger.

Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of an RestResponse that is logged - this parameter only controls if the header values are stored.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">true</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
RecordSObjectClassification__c = logEntryEvent.RecordSObjectClassification__c,
RecordSObjectType__c = logEntryEvent.RecordSObjectType__c,
RecordSObjectTypeNamespace__c = logEntryEvent.RecordSObjectTypeNamespace__c,
RestRequestBody__c = logEntryEvent.RestRequestBody__c,
RestRequestBodyMasked__c = logEntryEvent.RestRequestBodyMasked__c,
RestRequestHeaderKeys__c = logEntryEvent.RestRequestHeaderKeys__c,
RestRequestHeaders__c = logEntryEvent.RestRequestHeaders__c,
RestRequestMethod__c = logEntryEvent.RestRequestMethod__c,
RestRequestParameters__c = logEntryEvent.RestRequestParameters__c,
RestRequestRemoteAddress__c = logEntryEvent.RestRequestRemoteAddress__c,
RestRequestResourcePath__c = logEntryEvent.RestRequestResourcePath__c,
RestRequestUri__c = logEntryEvent.RestRequestUri__c,
RestResponseBody__c = logEntryEvent.RestResponseBody__c,
RestResponseBodyMasked__c = logEntryEvent.RestResponseBodyMasked__c,
RestResponseHeaderKeys__c = logEntryEvent.RestResponseHeaderKeys__c,
RestResponseHeaders__c = logEntryEvent.RestResponseHeaders__c,
RestResponseStatusCode__c = logEntryEvent.RestResponseStatusCode__c,
StackTrace__c = logEntryEvent.StackTrace__c,
Timestamp__c = timestamp,
TransactionEntryNumber__c = logEntryEvent.TransactionEntryNumber__c,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
logEntry.HasHttpResponseHeaders__c = logEntry.HttpResponseHeaders__c != null;
logEntry.HasInlineTags__c = logEntry.Tags__c != null;
logEntry.HasRecordJson__c = logEntry.RecordJson__c != null;
logEntry.HasRestRequestBody__c = logEntry.RestRequestBody__c != null;
logEntry.HasRestRequestHeaderKeys__c = logEntry.RestRequestHeaderKeys__c != null;
logEntry.HasRestRequestHeaders__c = logEntry.RestRequestHeaders__c != null;
logEntry.HasRestResponseBody__c = logEntry.RestResponseBody__c != null;
logEntry.HasRestResponseHeaderKeys__c = logEntry.RestResponseHeaderKeys__c != null;
logEntry.HasRestResponseHeaders__c = logEntry.RestResponseHeaders__c != null;
logEntry.HasStackTrace__c = logEntry.StackTrace__c != null;
}
}
Expand Down
Loading

0 comments on commit f602f90

Please sign in to comment.