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

feat: new doc page for enable logging for defineData #8199

Merged
merged 2 commits into from
Jan 13, 2025
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
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
"dataaccess",
"dataacess",
"databinding",
"datalogconfig",
"dataset",
"datasource",
"DataSource",
Expand Down
3 changes: 3 additions & 0 deletions src/directory/directory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ export const directory = {
},
{
path: 'src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx'
},
{
path: 'src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx'
}
]
},
Expand Down
111 changes: 111 additions & 0 deletions src/pages/[platform]/build-a-backend/data/enable-logging/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';

export const meta = {
title: 'Enable logging',
description: 'Learn how to enable logging for your Amplify data resource',
platforms: [
'android',
'angular',
'flutter',
'javascript',
'nextjs',
'react',
'react-native',
'swift',
'vue'
]
};

export function getStaticPaths() {
return getCustomStaticPath(meta.platforms);
}

export function getStaticProps(context) {
return {
props: {
platform: context.params.platform,
meta
}
};
}

You can enable logging to debug your GraphQL API using Amazon CloudWatch logs. To learn more about logging and monitoring capabilities for your GraphQL API, visit the [AWS AppSync documentation for logging and monitoring](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html).

## Enable default logging configuration

Default logging can be enabled by setting the `logging` property to `true` in the call to `defineData`. For example:

```ts title="amplify/data/resource.ts"
export const data = defineData({
// ...
logging: true
});
```

Using `logging: true` applies the default configuration:
- `excludeVerboseContent: true` (see [AppSync's Request-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl))
- `fieldLogLevel: 'none'` (see [AppSync's Field-level logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl))
- `retention: '1 week'` (see [Enum RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html))

## Customize logging configuration

You can customize individual configuration values by providing a [`DataLogConfig`](#datalogconfig-fields) object. For example:

```ts title="amplify/data/resource.ts"
export const data = defineData({
// ...
logging: {
excludeVerboseContent: false,
fieldLogLevel: 'all',
retention: '1 month'
}
});
```

<Callout warning>
**WARNING**: Setting `excludeVerboseContent` to `false` logs full queries and user parameters, which can contain sensitive data. We recommend limiting CloudWatch log access to only those roles or users (e.g., DevOps or developers) who genuinely require it, by carefully scoping your IAM policies.
</Callout>

## Configuration Properties

### `logging`
- `true`: Enables default logging.
- `DataLogConfig` object: Overrides one or more default fields.

### `DataLogConfig` Fields

- **`excludeVerboseContent?: boolean`**
- Defaults to `true`
- When `false`, logs can contain request-level logs. See [AppSync's Request-Level Logs](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl).

- **`fieldLogLevel?: DataLogLevel`**
- Defaults to `'none'`
- Supported values of [AppSync's Field Log Levels](https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cwl):
- `'none'`
- `'error'`
- `'info'`
- `'debug'`
- `'all'`

- **`retention?: LogRetention`**
- Number of days to keep the logs
- Defaults to `'1 week'`
- Supported values of [Enum RetentionDays](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.RetentionDays.html):
- `'1 day'`
- `'3 days'`
- `'5 days'`
- `'1 week'`
- `'2 weeks'`
- `'1 month'`
- `'2 months'`
- `'3 months'`
- `'4 months'`
- `'5 months'`
- `'6 months'`
- `'1 year'`
- `'13 months'`
- `'18 months'`
- `'2 years'`
- `'5 years'`
- `'10 years'`
- `'infinite'`
Loading