Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.

## Unlocked Package - v4.18.3
## Unlocked Package - v4.18.4

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

`sf package install --wait 20 --security-type AdminsOnly --package 04tg70000009GaDAAU`
`sf package install --wait 20 --security-type AdminsOnly --package 04tg7000000BNcPAAW`

---

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 @@ Indicates if Nebula Logger will store scenarios in the custom object `LoggerScen

Indicates if Nebula Logger will store tags in the custom objects `LoggerTag__c` & `LogEntryTag__c`, or in the field `LogEntry__c.Tags__c`. Controlled by the custom metadata record `LoggerParameter.NormalizeTagData`, or `true` as the default

#### `ORGANIZATION_ALLOWLIST` → `Set<String>`

An optional way to enable logging in only specified orgs/environments - this is useful for disabling logging by default in new sandboxes refreshed from a produciton org. When blank/empty, logging will run normally - when org IDs are specified, logging will only run if the current org&apos;s ID is in the configured list.

#### `PLATFORM_CACHE_PARTITION_NAME` → `String`

The name of the Platform Cache partition to use for caching (when platform cache is enabled). Controlled by the custom metadata record `LoggerParameter.PlatformCachePartitionName`, or `LoggerCache` as the default
Expand Down
1 change: 1 addition & 0 deletions nebula-logger/core.package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@
<members>LoggerParameter.LogEntryEventStreamDisplayFields</members>
<members>LoggerParameter.NormalizeScenarioData</members>
<members>LoggerParameter.NormalizeTagData</members>
<members>LoggerParameter.OrganizationAllowlist</members>
<members>LoggerParameter.PlatformCachePartitionName</members>
<members>LoggerParameter.QueryApexClassData</members>
<members>LoggerParameter.QueryApexTriggerData</members>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ public class LoggerParameter {
private set;
}

/**
* @description An optional way to enable logging in only specified orgs/environments - this is useful for disabling logging by default in new sandboxes refreshed from a produciton org.
* When blank/empty, logging will run normally - when org IDs are specified, logging will only run if the current org's ID is in the configured list.
*/
public static final Set<String> ORGANIZATION_ALLOWLIST {
get {
if (ORGANIZATION_ALLOWLIST == null) {
ORGANIZATION_ALLOWLIST = new Set<String>(getStringList('OrganizationAllowlist', new List<String>()));
if (ORGANIZATION_ALLOWLIST.size() == 0) {
ORGANIZATION_ALLOWLIST.add(System.UserInfo.getOrganizationId());
}
}
return ORGANIZATION_ALLOWLIST;
}
private set;
}

/**
* @description The name of the Platform Cache partition to use for caching (when platform cache is enabled).
* Controlled by the custom metadata record `LoggerParameter.PlatformCachePartitionName`, or `LoggerCache` as the default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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>Organization Allowlist</label>
<protected>false</protected>
<values>
<field>Comments__c</field>
<value xsi:nil="true"/>
</values>
<values>
<field>Description__c</field>
<value xsi:type="xsd:string">An optional way to only enable logging in specified orgs/environments - this is useful for disabling logging by default in new sandboxes refreshed from a produciton org. When blank, logging will run normally - when org IDs are specified, logging will only run if the current org's ID is in the configured list.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">[]</value>
</values>
</CustomMetadata>
12 changes: 11 additions & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.18.3';
private static final String CURRENT_VERSION_NUMBER = 'v4.18.4';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';
Expand Down Expand Up @@ -452,6 +452,16 @@ global with sharing class Logger {
loggingUserSettings.SetupOwnerId = loggingUser.Id;
}

// Since we're dealing with strings stored in CMDT, we check for both the 15 & 18 character
// versions of the organization ID.
String fullOrganizationId = System.UserInfo.getOrganizationId();
if (
LoggerParameter.ORGANIZATION_ALLOWLIST.contains(fullOrganizationId) == false &&
LoggerParameter.ORGANIZATION_ALLOWLIST.contains(fullOrganizationId.left(15)) == false
) {
loggingUserSettings.IsEnabled__c = false;
}

return loggingUserSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';

const CURRENT_VERSION_NUMBER = 'v4.18.3';
const CURRENT_VERSION_NUMBER = 'v4.18.4';

const CONSOLE_OUTPUT_CONFIG = {
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ private class LoggerParameter_Tests {
System.Assert.areEqual(mockValue, returnedValue);
}

@IsTest
static void it_should_return_constant_value_for_organization_allowlist() {
List<String> mockValue = new List<String>{ 'SomeValue', 'AnotherValue' };
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(DeveloperName = 'OrganizationAllowlist', Value__c = System.JSON.serialize(mockValue));
LoggerParameter.setMock(mockParameter);

Set<String> returnedValue = LoggerParameter.ORGANIZATION_ALLOWLIST;

System.Assert.areEqual(new Set<String>(mockValue), returnedValue);
}

@IsTest
static void it_should_return_constant_value_for_platform_cache_partition_name() {
String mockValue = 'SomeValue';
Expand Down
80 changes: 80 additions & 0 deletions nebula-logger/core/tests/logger-engine/classes/Logger_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,86 @@ private class Logger_Tests {
System.Assert.isNull(returnedSettings.Id);
}

@IsTest
static void it_should_enable_logging_in_user_settings_when_org_allowlist_is_blank() {
LoggerSettings__c configuredSettings = LoggerSettings__c.getOrgDefaults();
configuredSettings.IsEnabled__c = true;
insert configuredSettings;
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(
DeveloperName = 'OrganizationAllowlist',
Value__c = System.JSON.serialize(new List<String>())
);
LoggerParameter.setMock(mockParameter);
System.Assert.isTrue(LoggerParameter.ORGANIZATION_ALLOWLIST.contains(System.UserInfo.getOrganizationId()));

LoggerSettings__c returnedSettings = Logger.getUserSettings();

configuredSettings = [SELECT Id, IsEnabled__c FROM LoggerSettings__c];
System.Assert.areEqual(true, configuredSettings.IsEnabled__c);
System.Assert.areEqual(true, returnedSettings.IsEnabled__c);
}

@IsTest
static void it_should_enable_logging_in_user_settings_when_current_org_18_character_id_is_in_allowlist() {
LoggerSettings__c configuredSettings = LoggerSettings__c.getOrgDefaults();
configuredSettings.IsEnabled__c = true;
insert configuredSettings;
String organizationId = System.UserInfo.getOrganizationId();
System.Assert.areEqual(18, organizationId.length());
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(
DeveloperName = 'OrganizationAllowlist',
Value__c = System.JSON.serialize(new List<String>{ organizationId })
);
LoggerParameter.setMock(mockParameter);
System.Assert.isTrue(LoggerParameter.ORGANIZATION_ALLOWLIST.contains(System.UserInfo.getOrganizationId()));

LoggerSettings__c returnedSettings = Logger.getUserSettings();

configuredSettings = [SELECT Id, IsEnabled__c FROM LoggerSettings__c];
System.Assert.areEqual(true, configuredSettings.IsEnabled__c);
System.Assert.areEqual(true, returnedSettings.IsEnabled__c);
}

@IsTest
static void it_should_enable_logging_in_user_settings_when_current_org_15_character_id_is_in_allowlist() {
LoggerSettings__c configuredSettings = LoggerSettings__c.getOrgDefaults();
configuredSettings.IsEnabled__c = true;
insert configuredSettings;
String shortenedOrganizationId = System.UserInfo.getOrganizationId().left(15);
System.Assert.areEqual(15, shortenedOrganizationId.length());
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(
DeveloperName = 'OrganizationAllowlist',
Value__c = System.JSON.serialize(new List<String>{ shortenedOrganizationId })
);
LoggerParameter.setMock(mockParameter);
System.Assert.isFalse(LoggerParameter.ORGANIZATION_ALLOWLIST.contains(System.UserInfo.getOrganizationId()));

LoggerSettings__c returnedSettings = Logger.getUserSettings();

configuredSettings = [SELECT Id, IsEnabled__c FROM LoggerSettings__c];
System.Assert.areEqual(true, configuredSettings.IsEnabled__c);
System.Assert.areEqual(true, returnedSettings.IsEnabled__c);
}

@IsTest
static void it_should_disable_logging_in_user_settings_when_current_org_is_not_in_allowlist() {
LoggerSettings__c configuredSettings = LoggerSettings__c.getOrgDefaults();
configuredSettings.IsEnabled__c = true;
insert configuredSettings;
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(
DeveloperName = 'OrganizationAllowlist',
Value__c = System.JSON.serialize(new List<String>{ 'some-org-id-that-is-not-the-current-org-id' })
);
LoggerParameter.setMock(mockParameter);
System.Assert.isFalse(LoggerParameter.ORGANIZATION_ALLOWLIST.contains(System.UserInfo.getOrganizationId()));

LoggerSettings__c returnedSettings = Logger.getUserSettings();

configuredSettings = [SELECT Id, IsEnabled__c FROM LoggerSettings__c];
System.Assert.areEqual(true, configuredSettings.IsEnabled__c);
System.Assert.areEqual(false, returnedSettings.IsEnabled__c);
}

@IsTest
static void it_should_return_system_request_id() {
String expectedRequestId = System.Request.getCurrent().getRequestId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ private class CMDT_LoggerParameter_Tests {
System.Assert.areEqual('true', bundledRecord.Value__c);
}

@IsTest
static void it_has_correct_record_for_organization_allowlist() {
LoggerParameter__mdt bundledRecord = LoggerParameter__mdt.getInstance('OrganizationAllowlist');

System.Assert.isNotNull(bundledRecord, 'Record is missing');
System.Assert.isNull(bundledRecord.Comments__c, 'Comments should be null/blank');
System.Assert.isNotNull(bundledRecord.Description__c, 'Description is missing');
System.Assert.areEqual('Organization Allowlist', bundledRecord.Label);
System.Assert.areEqual('[]', bundledRecord.Value__c);
}

@IsTest
static void it_has_correct_record_for_platform_cache_partition_name() {
LoggerParameter__mdt bundledRecord = LoggerParameter__mdt.getInstance('PlatformCachePartitionName');
Expand Down
Loading