PHPackages                             arrowsphere/cloudwatch-logs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. arrowsphere/cloudwatch-logs

ActiveLibrary

arrowsphere/cloudwatch-logs
===========================

Logs management in CloudWatch

2.0.2(6mo ago)118.9k↑18.6%2MITPHPPHP &gt;=8.0CI passing

Since Jul 6Pushed 6mo ago4 watchersCompare

[ Source](https://github.com/ArrowSphere/cloudwatch-logs)[ Packagist](https://packagist.org/packages/arrowsphere/cloudwatch-logs)[ RSS](/packages/arrowsphere-cloudwatch-logs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (9)Used By (0)

ArrowSphere CloudWatch Logs
===========================

[](#arrowsphere-cloudwatch-logs)

This composer package allows to log data in CloudWatch, with auto-generated correlation id to follow the logs throughout all processes and their children.

⚙️ Installation
---------------

[](#️-installation)

Install the latest version with

```
$ composer require arrowsphere/cloudwatch-logs
```

Request identifiers management
------------------------------

[](#request-identifiers-management)

### 📖 Introduction

[](#-introduction)

We manage 3 types of identifiers to help us identify our requests and follow their logs.

The request id, identified as `ars-request-id`, is the unique identifier for the current request. It is auto-generated and cannot be null.

The parent id, identified as `ars-parent-id`, is the identifier of the parent request, that directly called this one. It can be null if the current request is the originator of a process.

The correlation id, identified as `ars-correlation-id`, is the identifier of the originator request of the process.

Whenever an event is logged, we should have those 3 headers indicated in the logging context.

### 🔧 How to use

[](#-how-to-use)

#### The header ids

[](#the-header-ids)

The three header ids are automatically logged by the logger system provided by this package, however if you want to pass them through to other API calls, you'll have to access them by yourself.

You can access the headers by using class `ArsHeaderManager`.

The simplest way to use this class is to use static method `ArsHeaderManager::initFromGlobals()` with no argument, it works as a singleton, and will populate the ids with whatever is already present in the `$_SERVER` superglobal.

The `$_SERVER` superglobal will then contain all three ids (parent id being an empty string if there's none).

Here's an example of code to make use of the variables:

```
$arsHeaderManager = \ArrowSphere\CloudWatchLogs\Processor\ArsHeader\ArsHeaderManager::initFromGlobals();

$requestId = $arsHeaderManager->getRequestId();
$correlationId = $arsHeaderManager->getCorrelationId();
$parentId = $arsHeaderManager->getParentId();

// Now you have all three variables and can use them however you want.
```

#### The logger

[](#the-logger)

This package provides a monolog handler for CloudWatch. To use it you'll have to instanciate it with the following parameters:

```
