Skip to content

Commit

Permalink
Fix AWS CloudWatch sequence token handling for new/empty log streams (#…
Browse files Browse the repository at this point in the history
…4717)

* Handle nil sequence token for empty log streams

* Include rejection info in the error message
  • Loading branch information
errordeveloper authored Aug 18, 2021
1 parent 5b78c62 commit 35717d4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions exporter/awscloudwatchlogsexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (e *exporter) Start(ctx context.Context, host component.Host) error {
}
e.client = cloudwatchlogs.New(sess)

e.logger.Debug("Retrieving Cloud Watch sequence token")
e.logger.Debug("Retrieving CloudWatch sequence token")
out, err := e.client.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
LogGroupName: aws.String(e.config.LogGroupName),
LogStreamNamePrefix: aws.String(e.config.LogStreamName),
Expand All @@ -73,6 +73,10 @@ func (e *exporter) Start(ctx context.Context, host component.Host) error {
return
}
stream := out.LogStreams[0]
if stream.UploadSequenceToken == nil {
e.logger.Debug("CloudWatch sequence token is nil, will assume empty")
return
}
e.seqToken = *stream.UploadSequenceToken
})
return startErr
Expand All @@ -99,14 +103,19 @@ func (e *exporter) PushLogs(ctx context.Context, ld pdata.Logs) (err error) {
LogGroupName: aws.String(e.config.LogGroupName),
LogStreamName: aws.String(e.config.LogStreamName),
LogEvents: logEvents,
SequenceToken: aws.String(e.seqToken),
}
if e.seqToken != "" {
input.SequenceToken = aws.String(e.seqToken)
} else {
e.logger.Debug("Putting log events without a sequence token")
}

out, err := e.client.PutLogEvents(input)
if err != nil {
return err
}
if info := out.RejectedLogEventsInfo; info != nil {
return fmt.Errorf("log event rejected")
return fmt.Errorf("log event rejected: %s", info.String())
}
e.logger.Debug("Log events are successfully put")

Expand Down

0 comments on commit 35717d4

Please sign in to comment.