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

AWSCloudWatchProvider fails to log to a brand-new log stream #9050

Closed
3 tasks done
ibliskavka opened this issue Oct 17, 2021 · 8 comments
Closed
3 tasks done

AWSCloudWatchProvider fails to log to a brand-new log stream #9050

ibliskavka opened this issue Oct 17, 2021 · 8 comments
Assignees
Labels
pending-response Issue is pending response from the issue requestor

Comments

@ibliskavka
Copy link

ibliskavka commented Oct 17, 2021

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Not applicable

Amplify Categories

Not applicable

Environment information

Put output below this line

System:
OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Memory: 9.66 GB / 12.33 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.17.5 - /usr/bin/node
Yarn: 1.22.11 - /mnt/c/Users/iblis/AppData/Roaming/npm/yarn
npm: 6.14.14 - /usr/bin/npm
npmGlobalPackages:
aws-cdk: 1.122.0
npm: 6.14.14

Describe the bug

AWSCloudWatchProvider (packages/core/src/Providers/AWSCloudWatchProvider.ts) throws the following errors when sending logs to a brand new stream.

API Response

{"__type":"InvalidParameterException","message":"1 validation error detected: Value '' at 'sequenceToken' failed to satisfy constraint: Member must have length greater than or equal to 1"}

When I call the CloudWatch API directly without a token to initialize the first stream message, the provider works.

Expected behavior

AWSCloudWatchProvider shouldn't be initializing _nextSequenceToken to empty string. The value should be undefined.

Original Line: 379
this._nextSequenceToken = logStream.uploadSequenceToken || '';

Requested Changes:
this._nextSequenceToken = logStream.uploadSequenceToken || undefined;

Reproduction steps

  1. Create a new aws-amplify logger
  2. Add Pluggable: AWSCloudWatchProvider with a non-existing stream name
  3. Attempt to log an entry

Code Snippet

const logger = new Logger('test', 'DEBUG);
logger.addPluggable(
    new AWSCloudWatchProvider({
      logGroupName: `/app/dev`,
      logStreamName: 'brand-new-stream',
      region: 'us-east-2`,
    })
  );

logger.debug('hello');

Log output

**API Response** ``` {"__type":"InvalidParameterException","message":"1 validation error detected: Value '' at 'sequenceToken' failed to satisfy constraint: Member must have length greater than or equal to 1"} ```

Log Output

31:07.130 AWSCloudWatch - failure during log push: InvalidParameterException: 1 validation error detected: Value '' at 'sequenceToken' failed to satisfy constraint: Member must have length greater than or equal to 1

31:07.130 AWSCloudWatch - error during _safeUploadLogEvents: TypeError: Cannot read properties of undefined (reading 'nextSequenceToken')

[ERROR] 31:07.130 AWSCloudWatch - error when calling _safeUploadLogEvents in the timer interval - TypeError: Cannot read properties of undefined (reading 'nextSequenceToken')

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@chrisbonifacio chrisbonifacio self-assigned this Oct 18, 2021
@chrisbonifacio chrisbonifacio added this to Pending Triage in Issues Triaging via automation Oct 18, 2021
@chrisbonifacio
Copy link
Contributor

Hi @ibliskavka 👋 thanks for raising this issue! Since you provided the correction for the line of code, would you like to submit a Pull Request for the team to review?

@chrisbonifacio chrisbonifacio added the pending-response Issue is pending response from the issue requestor label Oct 18, 2021
@chrisbonifacio chrisbonifacio moved this from Pending Triage to Can't Reproduce / Pending Response in Issues Triaging Oct 18, 2021
@chrisbonifacio
Copy link
Contributor

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you. Thank you!

Issues Triaging automation moved this from Can't Reproduce / Pending Response to Triaged/Closed By DSE Nov 4, 2021
@aaronlna
Copy link
Contributor

aaronlna commented Nov 7, 2021

Why was this issue closed? The steps that were originally posted look correct in how to reproduce the problem. I ran into this issue this morning and there looks to be others posting about it under the original feature PR.

When writing to an empty log-stream for the first time then all writes will fail because _nextSequenceToken will be an empty string that fails input validation to PutLogEventsCommand. This means you can never begin writing events. I've had to work around this by publishing an event manually, but this isn't feasible for my product that will need to generate new log streams per different sources. We won't have a mechanism in this case for writing an event out-of-band to a new, empty log stream.

I'd be happy to post a PR.

@slavco86
Copy link

Same here! When trying to follow instructions in #8309 to get Amplify to send logs to Cloudwatch, at first I was unable to because of exactly same error - sequence token.
Once I have manually added a log inside the stream with some dummy data - everything worked as expected

@ashika01
Copy link
Contributor

I have merged in #9181. Thank you @aaronlna. It is now in aws-amplify@unstable and should be released in @latest thursday during our weekly release cycle. Could you verify by upgrading to unstable and let us know if there are any issues?

@ashika01 ashika01 self-assigned this Nov 22, 2021
@aaronlna
Copy link
Contributor

aaronlna commented Dec 8, 2021

Thanks for the merge. I checked out unstable and it is working for my use-case-- no issues discovered.

@ashika01
Copy link
Contributor

ashika01 commented Dec 8, 2021

it is also in latest now. Thanks for verifying I am closing this issue 🚀 Thank you all for your wonderful contribution. Feel free to open up any issue you have 👍

@ashika01 ashika01 closed this as completed Dec 8, 2021
@github-actions
Copy link

github-actions bot commented Dec 9, 2022

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending-response Issue is pending response from the issue requestor
Projects
No open projects
Issues Triaging
Triaged/Closed By DSE
Development

No branches or pull requests

5 participants