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

docs: alokai metadata #7305

Merged
merged 4 commits into from
Nov 6, 2024
Merged
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
63 changes: 48 additions & 15 deletions docs/content/3.middleware/2.guides/10.logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,64 @@ The middleware application provides a logger instance that automatically attache

The middleware application provides access to the logger in various parts of the system, such as in extensions and integrations. This flexibility allows you to log important events, errors, and other data throughout the lifecycle of your application.

```json[Example log]
In this section, we will explore how to access and use the logger in different parts of the application.

The below examples will demonstrate how to use the application logger in a way that ensures that correct metadata is conveyed in the logs. To achieve that we will use `getLogger` function that will extract the logger instance from the passed argument.

:::tip
The logger is integrated into the middleware to provide additional metadata about the scope of call with every log out of the box. In case of error, it also provides an error boundary.
:::

### Basic Logger usage

For most cases, usage of `logger` is similar to the native `console` but it has a different set of available methods described by [LoggerInterface](#providing-own-logger-handler) interface.

```ts
logger.info("Something went wrong!");
```

Prints:
```json
{
"message": "log message we print",
"message": "Something went wrong!",
"timestamp": "2024-10-22T19:04:18.791Z",
"severity": "INFO",
"context": "middleware",
"scope": {
"integrationName": "adyen",
"functionName": "addedCustomEndpoint",
"hookName": "afterCall",
"type": "requestHook",
"extensionName": "testing-adyen-extension"
"alokai": {
"context": "middleware",
"scope": {
...
}
}
}
```

In this section, we will explore how to access and use the logger in different parts of the application.
The provided logger has a second optional argument that allows you to include custom metadata to be attached to the JSON output. For example:

The below examples will demonstrate how to use the application logger in a way that ensures that correct metadata is conveyed in the logs. To achieve that we will use `getLogger` function that will extract the logger instance from the passed.
```ts
logger.info("I've just fetched a user!", {
userId: "123"
});
```

:::tip
The logger is integrated in the middleware to provide additional metadata about scope of call with every log out of the box. In case of error, it also provides error boundary.
:::
Prints:
```json
{
"message": "I've just fetched a user!",
"timestamp": "2024-10-22T19:04:18.791Z",
"severity": "INFO",
"alokai": {
"context": "middleware",
"scope": {
...
}
},
"userId": "123"
}
```

### Example log
:::warning
It's forbidden to overwrite **alokai** key within provided metadata. Any attempt will be ineffective.
:::

### `extendApp`

Expand Down
Loading