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
4 changes: 3 additions & 1 deletion force-app/main/default/classes/Triton.cls
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ global with sharing class Triton {
builder.tracePoint();
}

builder.limitInfo();
if (!builder.hasFullLimitInfo()) {
builder.limitInfoLite();
}

logs.add(builder.build());
}
Expand Down
44 changes: 35 additions & 9 deletions force-app/main/default/classes/TritonBuilder.cls
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ public with sharing class TritonBuilder {
@TestVisible
private static final String PUBLISH_IMMEDIATE_DML_LIMIT = 'Publish_Immediate_DML_Limit__c';

private static final Set<String> LOG_FIELDS = Schema.SObjectType.pharos__Log__c.fields.getMap().keySet();

private Boolean includeLimitInfo = true;
private Boolean traceable = false;

private pharos.LogBuilder builder;
private Boolean fullLimitInfoRequested = false;

public TritonBuilder cloneBuilder() {
pharos__Log__c clonedLog = this.builder.build().clone(false, true, false, false);
TritonBuilder cloned = new TritonBuilder();
// Copy all attributes from the original log to the new one
pharos__Log__c originalLog = this.builder.build();
for (String field : LOG_FIELDS) {
Object value = originalLog.get(field);
if (value != null) {
cloned.builder.attribute(field, value);
}

// Only iterate POPULATED fields (10-20, not all 50-100)
for (String field : clonedLog.getPopulatedFieldsAsMap().keySet()) {
cloned.builder.attribute(field, clonedLog.get(field));
}

cloned.includeLimitInfo = this.includeLimitInfo;
cloned.fullLimitInfoRequested = this.fullLimitInfoRequested;
cloned.traceable = this.traceable;
cloned.initBuilder();
return cloned;
}
Expand All @@ -126,6 +126,10 @@ public with sharing class TritonBuilder {
this.builder.attribute(REQUEST_ID, System.Request.getCurrent().getRequestId());
}

public Boolean hasFullLimitInfo() {
return this.fullLimitInfoRequested;
}

/**
* Set log category from Category enum.
* @param c -- TritonTypes.Category enum value
Expand Down Expand Up @@ -509,6 +513,28 @@ public with sharing class TritonBuilder {
: this;
}

/**
* Captures and sets the essential transaction limits (CPU Time, Heap Size, DML Statements) on the log record
* @return this builder instance
*/
public TritonBuilder limitInfoLite() {
return this
.attribute(SOQL_QUERIES, System.Limits.getQueries())
.attribute(SOQL_QUERIES_LIMIT, System.Limits.getLimitQueries())
.attribute(SOQL_ROWS, System.Limits.getQueryRows())
.attribute(SOQL_ROWS_LIMIT, System.Limits.getLimitQueryRows())
.attribute(DML_STATEMENTS, System.Limits.getDMLStatements())
.attribute(DML_STATEMENTS_LIMIT, System.Limits.getLimitDMLStatements())
.attribute(DML_ROWS, System.Limits.getDMLRows())
.attribute(DML_ROWS_LIMIT, System.Limits.getLimitDMLRows())
.attribute(CPU_TIME, System.Limits.getCpuTime())
.attribute(CPU_TIME_LIMIT, System.Limits.getLimitCpuTime())
.attribute(HEAP_SIZE, System.Limits.getHeapSize())
.attribute(HEAP_SIZE_LIMIT, System.Limits.getLimitHeapSize())
.attribute(CALLOUTS, System.Limits.getCallouts())
.attribute(CALLOUTS_LIMIT, System.Limits.getLimitCallouts());
}

/**
* Configure builder for an exception
* Sets type from exception type (or defaults to Backend), sets error level,
Expand Down