Skip to content

Added the ability to capture HttpRequest headers

Compare
Choose a tag to compare
@jongpie jongpie released this 02 Sep 17:46
· 12 commits to main since this release
5c4e09e

Resolved #701 by providing a way to indicate which HttpRequest headers (and values) should be logged - previously, no header information was stored for HttpRequest objects.

Conceptually, this is the same idea as logging headers when calling the other LogEntryBuilder methods below:

  • setHttpResponseDetails(System.HttpResponse response)
  • setRestRequestDetails(System.RestRequest request)
  • setRestResponseDetails(System.RestResponse response)

However, there is one notable difference in the new behavior for logging HttpRequest headers - the HttpRequest class does not have a method to get all of the header keys, so you must explicitly tell Nebula Logger which header keys you want to log.

Core Unlocked Package Changes

  • 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
    • The new fields mimic these existing fields:
      • HttpResponse header data stored in HttpResponseHeaderKeys__c and HttpResponseHeaders__c
      • RestRequest header data stored in RestRequestHeaderKeys__c and RestRequestHeaders__c
      • RestResponse header data stored in RestResponseHeaderKeys__c and RestRequestHeaders__c
  • 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)

Example

This example Apex script will create a LogEntry__c record with data about the HttpRequest - including the 2 specified header keys & their values.

System.HttpRequest httpRequest = new System.HttpRequest();
httpRequest.setBody('{ "hello": "world" }');
httpRequest.setEndpoint('https://fake.salesforce.com');
httpRequest.setHeader('some-header', 'some value');
httpRequest.setHeader('another-header', 'another value');
httpRequest.setMethod('GET');

List<String> headersToLog = new List<String>{ 'some-header', 'another-header' };
Logger.info('logging an HTTP request').setHttpRequestDetails(httpRequest, headersToLog);
Logger.saveLog();

image

Pipeline Changes

  • Updated build.yml to fail the build if the codecov upload action fails

Installation Info

Core Unlocked Package - no namespace

Full Changelog: v4.14.7...v4.14.8