Skip to content

Add telemetry logging support to Trigger Actions Framework #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ssk42
Copy link

@ssk42 ssk42 commented Jun 20, 2025

Summary

Implements a pluggable telemetry logging system for the Trigger Actions Framework to track Salesforce limits and performance metrics during trigger action execution. This feature addresses issue #176 by providing developers with debugging and performance monitoring capabilities.

Key Features

  • ITriggerActionTelemetryLogger interface for pluggable telemetry implementations
  • Default LimitLogger implementation tracking SOQL queries, DML statements, CPU time, and heap usage
  • TelemetryContext class providing execution metadata (action class, operation, sObject type, record count)
  • Enable_Telemetry__c checkbox field to enable/disable telemetry per trigger action
  • Telemetry_Logger_Class__c text field to specify custom logger implementations
  • Namespace-aware permission checking for improved package compatibility

Implementation Details

  • Telemetry logging occurs at START and FINISH phases of trigger action execution
  • Graceful fallback to LimitLogger if custom logger class fails to instantiate
  • Debug-level logging for minimal performance impact
  • Comprehensive test coverage with all 147 tests passing
  • Compatible with existing trigger actions without requiring changes

Testing

  • ✅ All existing tests continue to pass (147/147)
  • ✅ New test classes added for LimitLogger and telemetry functionality
  • ✅ Successfully deployed to scratch org without issues
  • ✅ Namespace safety validated with permission checking enhancements

Usage Example

// Enable telemetry in Custom Metadata Type
Trigger_Action__mdt myAction = new Trigger_Action__mdt(
    Apex_Class_Name__c = 'MyTriggerAction',
    Enable_Telemetry__c = true,
    Telemetry_Logger_Class__c = 'LimitLogger' // Optional, defaults to LimitLogger
);

Sample debug output:

[START] BEFORE_INSERT on Account.MyTriggerAction (5 records) - Queries: 0/100, DML: 0/150, CPU: 12/10000ms, Heap: 2048/6000000bytes
[FINISH] BEFORE_INSERT on Account.MyTriggerAction (5 records) - Queries: 2/100, DML: 0/150, CPU: 45/10000ms, Heap: 3072/6000000bytes

Test plan

  • All existing tests pass (147/147 tests)
  • New telemetry functionality properly tested
  • Scratch org deployment successful
  • No breaking changes to existing functionality
  • Telemetry can be enabled/disabled per trigger action
  • Custom logger classes can be specified and fall back gracefully
  • Namespace-aware permission checking works correctly

🤖 Generated with Claude Code

Implement pluggable telemetry logging system to track Salesforce limits and performance metrics during trigger action execution. This feature helps with debugging and performance monitoring in development environments.

Key Features:
- ITriggerActionTelemetryLogger interface for pluggable telemetry implementations
- Default LimitLogger implementation tracking SOQL, DML, CPU, and heap limits
- TelemetryContext providing execution metadata (action, operation, sObject, record count)
- Enable_Telemetry__c checkbox field to enable/disable telemetry per trigger action
- Telemetry_Logger_Class__c field to specify custom logger implementations
- Namespace-aware permission checking for better package compatibility
- Comprehensive test coverage with 147 tests passing

Implementation Details:
- Telemetry logging occurs at START and FINISH phases of trigger action execution
- Graceful fallback to LimitLogger if custom logger class fails to instantiate
- Debug-level logging for minimal performance impact
- Not recommended for production environments

Closes mitchspano#176

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

google-cla bot commented Jun 20, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant