Skip to content

Commit 5c4e09e

Browse files
authored
Added the ability to capture HttpRequest headers (#755)
* Added instance method overload LogEntryEventBuilder.setHttpRequestDetails(System.HttpRequest request, List<String> headersToLog) * Any header keys provided in headersToLog will now be logged * The existing overload, setHttpRequestDetails(System.HttpRequest request), will not log any header information * Added new LogEntryEvent__e fields HttpRequestHeaderKeys__c and HttpRequestHeaders__c to capture the specified list of header keys * Added new LoggerParameter__mdt record StoreHttpRequestHeaderValues to globally control if HttpResponse header values are stored when calling setHttpRequestDetails(System.HttpRequest request, List<String> headersToLog) * This new record mimics the existing record StoreHttpResponseHeaderValues (used for responses) * Added new LogEntry__c fields to store the HttpRequest header keys & values captured on LogEntryEvent__e, as well as some checkbox fields to aid with filtering in SOQL, list views, etc. * HttpRequestHeaderKeys__c * HasHttpRequestHeaderKeys__c - set to true when HttpRequestHeaderKeys__c is not null * HttpRequestHeaders__c * HasHttpRequestHeaders__c - set to true when HttpRequestHeaders__c is not null * Updated the flexipage LogEntryRecordPage to add the 2 new LogEntry__c fields HttpRequestHeaderKeys__c and HttpRequestHeaders__c * Both fields are conditionally displayed when populated, based on their corresponding checkbox fields HasHttpRequestHeaderKeys__c and HasHttpRequestHeaders__c (respectively) * Updated the existing list view AllHttpRequestLogEntries to include the new field HttpRequestHeaderKeys__c (HttpRequestHeader__c is intentionally not included at this time) * Updated build.yml to fail the build if the codecov upload action fails in the pipeline
1 parent 3c38ee8 commit 5c4e09e

32 files changed

Lines changed: 467 additions & 32 deletions

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ jobs:
126126
- name: 'Upload LWC code coverage to Codecov.io'
127127
uses: codecov/codecov-action@v4
128128
with:
129-
token: ${{ secrets.CODECOV_TOKEN }}
129+
fail_ci_if_error: true
130130
flags: LWC
131+
token: ${{ secrets.CODECOV_TOKEN }}
131132

132133
base-scratch-org-tests:
133134
environment: 'Base Scratch Org'
@@ -318,8 +319,9 @@ jobs:
318319
- name: 'Upload Apex test code coverage to Codecov.io'
319320
uses: codecov/codecov-action@v4
320321
with:
321-
token: ${{ secrets.CODECOV_TOKEN }}
322+
fail_ci_if_error: true
322323
flags: Apex
324+
token: ${{ secrets.CODECOV_TOKEN }}
323325

324326
- name: 'Delete Experience Cloud Scratch Org'
325327
run: npx sf org delete scratch --no-prompt

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.7
8+
## Unlocked Package - v4.14.8
99

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

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

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

1818
---
1919

docs/apex/Configuration/LoggerParameter.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ Indicates if Nebula Logger will send an error email notification if any internal
106106

107107
Indicates if Nebula Logger will store the transaction heap limits on `LogEntry__c`, retrieved from the class `System.Limits`. Controlled by the custom metadata record `LoggerParameter.StoreApexHeapSizeLimit`, or `true` as the default. Relies on `LoggerParameter.StoreTransactionLimits` to be true, as well.
108108

109+
#### `STORE_HTTP_REQUEST_HEADER_VALUES``Boolean`
110+
111+
Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpRequest`. Controlled by the custom metadata record `LoggerParameter.StoreHttpRequestHeaderValues`, or `true` as the default. Regardless of how this parameter is configured, Nebula Logger will still log the specified list of header keys of any instance of `System.HttpRequest` that is logged - this parameter only controls if the header values are stored.
112+
109113
#### `STORE_HTTP_RESPONSE_HEADER_VALUES``Boolean`
110114

111115
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.

docs/apex/Logger-Engine/LogEntryEventBuilder.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,27 @@ LogEntryEventBuilder
461461

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

464+
#### `setHttpRequestDetails(System.HttpRequest request, List<String> headersToLog)``LogEntryEventBuilder`
465+
466+
Sets the log entry event&apos;s HTTP Request fields
467+
468+
##### Parameters
469+
470+
| Param | Description |
471+
| -------------- | --------------------------------------------------------------------- |
472+
| `request` | The instance of `HttpRequest` to log |
473+
| `headersToLog` | An instance of `List&lt;String&gt;` containing the header keys to log |
474+
475+
##### Return
476+
477+
**Type**
478+
479+
LogEntryEventBuilder
480+
481+
**Description**
482+
483+
The same instance of `LogEntryEventBuilder`, useful for chaining methods
484+
464485
#### `setHttpResponseDetails(System.HttpResponse response)``LogEntryEventBuilder`
465486

466487
Sets the log entry event&apos;s HTTP Response fields

nebula-logger/core/main/configuration/classes/LoggerParameter.cls

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,22 @@ public class LoggerParameter {
384384
private set;
385385
}
386386

387+
/**
388+
* @description Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpRequest`.
389+
* Controlled by the custom metadata record `LoggerParameter.StoreHttpRequestHeaderValues`, or `true` as the default.
390+
* Regardless of how this parameter is configured, Nebula Logger will still log the specified list of header keys of any instance of
391+
* `System.HttpRequest` that is logged - this parameter only controls if the header values are stored.
392+
*/
393+
public static final Boolean STORE_HTTP_REQUEST_HEADER_VALUES {
394+
get {
395+
if (STORE_HTTP_REQUEST_HEADER_VALUES == null) {
396+
STORE_HTTP_REQUEST_HEADER_VALUES = getBoolean('StoreHttpRequestHeaderValues', true);
397+
}
398+
return STORE_HTTP_REQUEST_HEADER_VALUES;
399+
}
400+
private set;
401+
}
402+
387403
/**
388404
* @description Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpResponse`.
389405
* Controlled by the custom metadata record `LoggerParameter.StoreHttpResponseHeaderValues`, or `true` as the default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<label>Store HTTP Request Header Values</label>
4+
<protected>false</protected>
5+
<values>
6+
<field>Comments__c</field>
7+
<value xsi:nil="true"/>
8+
</values>
9+
<values>
10+
<field>Description__c</field>
11+
<value xsi:type="xsd:string">When set to &apos;true&apos; (default), Nebula Logger will store the header values of any instance of an HttpRequest that is logged using the instance method LogEntryEventBuilder.setHttpRequestDetails().
12+
13+
When set to &apos;false&apos;, the header values are not stored or referenced by Nebula Logger.
14+
15+
Regardless of how this parameter is configured, Nebula Logger will still log the specified list of header keys of any instance of an HttpRequest that is logged - this parameter only controls if the header values are stored.</value>
16+
</values>
17+
<values>
18+
<field>Value__c</field>
19+
<value xsi:type="xsd:string">true</value>
20+
</values>
21+
</CustomMetadata>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
285285
HttpRequestBodyMasked__c = logEntryEvent.HttpRequestBodyMasked__c,
286286
HttpRequestCompressed__c = logEntryEvent.HttpRequestCompressed__c,
287287
HttpRequestEndpoint__c = logEntryEvent.HttpRequestEndpoint__c,
288+
HttpRequestHeaderKeys__c = logEntryEvent.HttpRequestHeaderKeys__c,
289+
HttpRequestHeaders__c = logEntryEvent.HttpRequestHeaders__c,
288290
HttpRequestMethod__c = logEntryEvent.HttpRequestMethod__c,
289291
HttpResponseBody__c = logEntryEvent.HttpResponseBody__c,
290292
HttpResponseBodyMasked__c = logEntryEvent.HttpResponseBodyMasked__c,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
302302
logEntry.HasExceptionSourceSnippet__c = logEntry.ExceptionSourceSnippet__c != null;
303303
logEntry.HasExceptionStackTrace__c = logEntry.ExceptionStackTrace__c != null;
304304
logEntry.HasHttpRequestBody__c = logEntry.HttpRequestBody__c != null;
305+
logEntry.HasHttpRequestHeaderKeys__c = logEntry.HttpRequestHeaderKeys__c != null;
306+
logEntry.HasHttpRequestHeaders__c = logEntry.HttpRequestHeaders__c != null;
305307
logEntry.HasHttpResponseBody__c = logEntry.HttpResponseBody__c != null;
306308
logEntry.HasHttpResponseHeaderKeys__c = logEntry.HttpResponseHeaderKeys__c != null;
307309
logEntry.HasHttpResponseHeaders__c = logEntry.HttpResponseHeaders__c != null;

nebula-logger/core/main/log-management/flexipages/LogEntryRecordPage.flexipage-meta.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,40 @@
11411141
<identifier>RecordHttpRequestMethod_cField1</identifier>
11421142
</fieldInstance>
11431143
</itemInstances>
1144+
<itemInstances>
1145+
<fieldInstance>
1146+
<fieldInstanceProperties>
1147+
<name>uiBehavior</name>
1148+
<value>none</value>
1149+
</fieldInstanceProperties>
1150+
<fieldItem>Record.HttpRequestHeaderKeys__c</fieldItem>
1151+
<identifier>RecordHttpRequestHeaderKeys_cField</identifier>
1152+
<visibilityRule>
1153+
<criteria>
1154+
<leftValue>{!Record.HasHttpRequestHeaderKeys__c}</leftValue>
1155+
<operator>EQUAL</operator>
1156+
<rightValue>true</rightValue>
1157+
</criteria>
1158+
</visibilityRule>
1159+
</fieldInstance>
1160+
</itemInstances>
1161+
<itemInstances>
1162+
<fieldInstance>
1163+
<fieldInstanceProperties>
1164+
<name>uiBehavior</name>
1165+
<value>none</value>
1166+
</fieldInstanceProperties>
1167+
<fieldItem>Record.HttpRequestHeaders__c</fieldItem>
1168+
<identifier>RecordHttpRequestHeaders_cField</identifier>
1169+
<visibilityRule>
1170+
<criteria>
1171+
<leftValue>{!Record.HasHttpRequestHeaders__c}</leftValue>
1172+
<operator>EQUAL</operator>
1173+
<rightValue>true</rightValue>
1174+
</criteria>
1175+
</visibilityRule>
1176+
</fieldInstance>
1177+
</itemInstances>
11441178
<itemInstances>
11451179
<fieldInstance>
11461180
<fieldInstanceProperties>

nebula-logger/core/main/log-management/layouts/LogEntry__c-Log Entry Layout.layout-meta.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@
356356
<behavior>Readonly</behavior>
357357
<field>HttpRequestMethod__c</field>
358358
</layoutItems>
359+
<layoutItems>
360+
<behavior>Readonly</behavior>
361+
<field>HttpRequestHeaderKeys__c</field>
362+
</layoutItems>
363+
<layoutItems>
364+
<behavior>Readonly</behavior>
365+
<field>HttpRequestHeaders__c</field>
366+
</layoutItems>
359367
<layoutItems>
360368
<behavior>Readonly</behavior>
361369
<field>HttpRequestCompressed__c</field>

0 commit comments

Comments
 (0)