Skip to content
Merged
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
16 changes: 14 additions & 2 deletions lambda-extensions/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type LambdaExtensionConfig struct {
MaxDataPayloadSize int
LambdaRegion string
SourceCategoryOverride string
EnhanceJsonLogs bool
}

var defaultLogTypes = []string{"platform", "function"}
Expand Down Expand Up @@ -73,6 +74,7 @@ func (cfg *LambdaExtensionConfig) setDefaults() {
maxConcurrentRequests := os.Getenv("SUMO_MAX_CONCURRENT_REQUESTS")
enableFailover := os.Getenv("SUMO_ENABLE_FAILOVER")
logTypes := os.Getenv("SUMO_LOG_TYPES")
enhanceJsonLogs := os.Getenv("SUMO_ENHANCE_JSON_LOGS")

if numRetry == "" {
cfg.NumRetry = 3
Expand All @@ -99,9 +101,11 @@ func (cfg *LambdaExtensionConfig) setDefaults() {
cfg.LogTypes = strings.Split(logTypes, ",")
}
if retrySleepTime == "" {
cfg.RetrySleepTime = 300 * time.Millisecond
cfg.RetrySleepTime = 300 * time.Millisecond
}
if enhanceJsonLogs == "" {
cfg.EnhanceJsonLogs = true
}

}

func (cfg *LambdaExtensionConfig) validateConfig() error {
Expand All @@ -111,6 +115,7 @@ func (cfg *LambdaExtensionConfig) validateConfig() error {
maxConcurrentRequests := os.Getenv("SUMO_MAX_CONCURRENT_REQUESTS")
enableFailover := os.Getenv("SUMO_ENABLE_FAILOVER")
retrySleepTime := os.Getenv("SUMO_RETRY_SLEEP_TIME_MS")
enhanceJsonLogs := os.Getenv("SUMO_ENHANCE_JSON_LOGS")

var allErrors []string
var err error
Expand Down Expand Up @@ -189,6 +194,13 @@ func (cfg *LambdaExtensionConfig) validateConfig() error {

}

if enhanceJsonLogs != "" {
cfg.EnhanceJsonLogs, err = strconv.ParseBool(enhanceJsonLogs)
if err != nil {
allErrors = append(allErrors, fmt.Sprintf("Unable to parse SUMO_ENHANCE_JSON_LOGS: %v", err))
}
}

// test valid log format type
for _, logType := range cfg.LogTypes {
if !utils.StringInSlice(strings.TrimSpace(logType), validLogTypes) {
Expand Down
8 changes: 6 additions & 2 deletions lambda-extensions/sumoclient/sumoclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ func (s *sumoLogicClient) enhanceLogs(msg responseBody) {
if err != nil {
item["message"] = message
} else {
item["message"] = json
if s.config.EnhanceJsonLogs {
item["message"] = json
} else {
item = json
}
}
} else if ok && logType == "platform.report" {
s.createCWLogLine(item)
Expand Down Expand Up @@ -287,7 +291,7 @@ func (s *sumoLogicClient) SendLogs(ctx context.Context, rawmsg []byte) error {
}

func (s *sumoLogicClient) SendAllLogs(ctx context.Context, allMessages [][]byte) error {
if (len(allMessages) == 0) {
if len(allMessages) == 0 {
s.logger.Debugf("SendAllLogs: No messages to send")
return nil
}
Expand Down