Skip to content
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

InvalidSequenceTokenException #12

Open
plutext opened this issue Apr 16, 2019 · 1 comment
Open

InvalidSequenceTokenException #12

plutext opened this issue Apr 16, 2019 · 1 comment

Comments

@plutext
Copy link

plutext commented Apr 16, 2019

From AWS Lamba, you might get:

com.amazonaws.AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AWSLogs; Status Code: 400; Error Code: InvalidSequenceTokenException; Request ID: 5645e9c0-5552-11e9-b9f8-71f29888b2c7)

    at com.amazonaws.services.logs.AWSLogsClient.doInvoke(AWSLogsClient.java:2447)
    at com.amazonaws.services.logs.AWSLogsClient.invoke(AWSLogsClient.java:2423)
    at com.amazonaws.services.logs.AWSLogsClient.executePutLogEvents(AWSLogsClient.java:1951)
    at com.amazonaws.services.logs.AWSLogsClient.putLogEvents(AWSLogsClient.java:1926)

This seems to fix it:

        try {
        	nextToken = awsLogs.putLogEvents(
                    logEventReq
                            .withSequenceToken(nextToken)
                            .withLogEvents(events)
            ).getNextSequenceToken();
        	
		} catch (final InvalidSequenceTokenException iste) {
			
			// Copy https://github.com/graingert/cloudwatch-logback-appender/blob/master/src/main/java/com/brickcommerce/aws/logging/CloudWatchWriter.java#L67
			System.err.println("InvalidSequenceTokenException, will reset the token to the expected one");
			nextToken = iste.getExpectedSequenceToken();

		} catch (com.amazonaws.AmazonServiceException ase) {
			
			// But as per stack trace copied above this is what is actually caught on Lambda
			
			// Unable to unmarshall exception response with the unmarshallers provided 
			// (Service: AWSLogs; Status Code: 400; Error Code: InvalidSequenceTokenException; Request ID: 5ad1e6cc-5fdc-11e9-bdef-8759912c2f97
			System.err.println("Response wrapped InvalidSequenceTokenException, will reset the token to the expected one");
			
		    LogStream stream = findLogStream(groupName, currentStreamName);
            nextToken = stream.getUploadSequenceToken();
			
		} catch (Exception e) {
			logContext.addError("Exception while adding log events.", e);
		}

See also https://stackoverflow.com/questions/36876563/amazon-cloud-watch-log-putlogeventsrequest-the-given-sequencetoken-is-invali for reports of this error using other logging libs

@dibog
Copy link
Owner

dibog commented Apr 16, 2019

Hi @plutext,

thanks for your tip. Can it be that the problem occurs as you are writing into the same log stream from different processes? In this case it might be a good idea to make the log stream name unique. Please have a look here: https://github.com/dibog/cloudwatch-logback-appender/blob/master/README.md#-unique-log-stream-names

Cheers,
Dieter

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

No branches or pull requests

2 participants