Skip to content

Support using a named credential for self-calling REST API endpoints in the current org #996

Description

@jongpie

Context

Currently, the save method REST can be used to save logging data via a callout from & to the current org. This is (as far as I know) not a widely used option, but it can occasionally be helpful in situations where Apex code is already making callouts, so 1 more callout (to the org itself) can be better than worrying about errors like You have uncommitted work pending. Please commit or rollback before calling out.

The current implementation just uses the value of System.UserInfo.getSessionId() as the Bearer token in the REST call's Authorization header. This can be a problem for a few reasons:

  • Not all transactions have a session ID, so the current approach could fail in some transactions
  • Not all users have access to make callouts to the Salesforce REST API, so the current approach could fail for some users

What

I'd like to provide a way for Logger.RestApiSaver to use a named credential (with System.UserInfo.getSessionId() still as a fallback option). For now, this would only be used for saving via REST API - but there are some possible future enhancements that would benefit from being able to call the REST API (including some Tooling API endpoints), so introducing a named credential for Nebula Logger to use could be advantageous elsewhere too.

How

One way to possibly handle this is with a new LoggerParameter__mdt record, where admins can specify the name of a NamedCredential to use when making callout.

  • I think there are a lot of limitations & possible concerns with including a named credential directly in the package, but I should revisit this to make sure.
  • Assuming there are limitations/valid concerns with bundling a named credential, admins would be responsible for creating & configuring the named credential on their own, then saving the name in the hypothetical, new LoggerParameter__mdt record

Metadata

Metadata

Assignees

No one assigned

    Labels

    Layer: ConfigurationItems related to the custom hierarchy setting LoggerSettings__c or any included custom metadata typeLayer: Logger EngineItems related to the core logging engineLogging Source: APIItems related to using Nebula Logger via REST APISalesforce Feature: SecurityItems related to the security model (object-level access, field-level security, record sharing)Type: EnhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions