aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

Not able to push my React Native app logs to CloudWatch #12899

Closed cristobalbl86 closed 6 months ago

cristobalbl86 commented 10 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Analytics

Amplify Version

v6

Amplify Categories

analytics

Backend

Amplify CLI

Environment information

``` # Put output below this line System: OS: Windows 11 10.0.22631 CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz Memory: 2.48 GB / 15.82 GB Binaries: Node: 16.20.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Chromium (120.0.2210.133) Internet Explorer: 11.0.22621.1 npmPackages: @aws-amplify/react-native: ^1.0.13 => 1.0.13 @babel/core: ^7.20.0 => 7.23.7 @react-native-async-storage/async-storage: ^1.21.0 => 1.21.0 @react-native-community/netinfo: ^11.2.1 => 11.2.1 @types/react: ~18.2.45 => 18.2.48 @types/react-native: ^0.73.0 => 0.73.0 HelloWorld: 0.0.1 aws-amplify: ^6.0.13 => 6.0.13 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () expo: ~50.0.3 => 50.0.3 expo-status-bar: ~1.11.1 => 1.11.1 react: 18.2.0 => 18.2.0 react-native: 0.73.2 => 0.73.2 typescript: ^5.1.3 => 5.3.3 npmGlobalPackages: @aws-amplify/cli: 12.10.1 expo-cli: 6.3.10 newman: 5.3.2 vsts-npm-auth: 0.42.1 yarn: 1.22.19 ```

Describe the bug

I'm trying to push Amplify Logger logs to AWS CloudWatch

All configs are done in the AWS account, the logGroup and logsStream. My problem is in the react native app, I found this way but the AWSCloudWatchProvider doen't seem to work. Module '"aws-amplify"' has no exported member 'AWSCloudWatchProvider'.ts(2305)

`import { Amplify, AWSCloudWatchProvider } from "aws-amplify"; import { ConsoleLogger as Logger } from "@aws-amplify/core";

import awsmobile from "./src/aws-exports";

Amplify.configure(awsmobile);

const cwLogger = new Logger("cloudwatch", "DEBUG");

cwLogger.addPluggable( new AWSCloudWatchProvider({ logGroupName: "cloudwatchlogs", logStreamName: "cloudwatchstream", region: awsmobile.aws_project_region, }) );

export { cwLogger }; `

And I noticed that you deprecated that provider in this PR: https://github.com/aws-amplify/amplify-js/pull/11830

What is the right way to push the Logger logs to CloudWatch?

Expected behavior

I expect the logger be able to push logs to AWS CloudWatch

Reproduction steps

my app is not able to run, the error comes in the imports section image

Code Snippet

// Put your code below this line.
`import { Amplify, AWSCloudWatchProvider } from "aws-amplify";
import { ConsoleLogger as Logger } from "@aws-amplify/core";

import awsmobile from "./src/aws-exports";

Amplify.configure(awsmobile);

const cwLogger = new Logger("cloudwatch", "DEBUG");

cwLogger.addPluggable(
  new AWSCloudWatchProvider({
    logGroupName: "cloudwatchlogs",
    logStreamName: "cloudwatchstream",
    region: awsmobile.aws_project_region,
  })
);

export { cwLogger };
`

Log output

``` // Put your logs below this line ```

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-west-2",
    "aws_cognito_identity_pool_id": "us-west-2:b6f1ddce-042b-4d30-86dc-ed7dbd51545d",
    "aws_cognito_region": "us-west-2",
    "aws_user_pools_id": "us-west-2_bLrr9q6i2",
    "aws_user_pools_web_client_id": "1pp5610u6dthptv187c2s7so8v",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

export default awsmobile;

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

nadetastic commented 10 months ago

Hi @cristobalbl86 thank you for opening this issue. After taking a look at it, it seems that you are using v5 specific imports with v6 of aws-amplify. For example, AWSCloudWatchProvider was previously available in v5 but is not available in v6.

I'd recommend taking a a look at the migration guide here.

Additionally, also note that the ConsoleLogger is now imported from aws-amplify/utilites and not @aws-amplify/core - documentation.

import { ConsoleLogger } from 'aws-amplify/utils';

Let me know if you have any questions.

cristobalbl86 commented 10 months ago

Hi @cristobalbl86 thank you for opening this issue. After taking a look at it, it seems that you are using v5 specific imports with v6 of aws-amplify. For example, AWSCloudWatchProvider was previously available in v5 but is not available in v6.

I'd recommend taking a a look at the migration guide here.

Additionally, also note that the ConsoleLogger is now imported from aws-amplify/utilites and not @aws-amplify/core - documentation.

import { ConsoleLogger } from 'aws-amplify/utils';

Let me know if you have any questions.

Thank you @nadetastic for the feedback, I already updated my imports. But I still see that the ConsoleLogger in v6 supports the addPluggable method which receives a LoggingProvider parameter. What should I pass there if AWSCloudWatchProvider is not supported?, my goal is to push the logger logs to CloudWatch. Can you point me to any sample in v6? I was checking your docs but still don't find anything that can unblock me.

cristobalbl86 commented 10 months ago

I will appreciate any additional feedback.

nadetastic commented 9 months ago

Hi @cristobalbl86, following up here, thank you for your patience.

V6 doesn’t currently support CloudWatch, and we are working to get this addressed - however I am unable to provide an ETA at this time. In the meantime, a workaround could be to use the AWS SDK (as seen here) to emit the logs yourself.

I’ve marked this as a feature request and will provide any future updates here, but let me know if you have any additional questions.

cwomack commented 6 months ago

For anyone that is following this issue, we will be consolidating the context and feedback detailed here into issue #13336 to better focus our efforts on an implementation strategy for improving CloudWatch support in v6. Please leave any additional context or feedback on that issue, and follow it for further updates on progress as we make it!