PHPackages                             waylandace/xray - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. waylandace/xray

AbandonedLibrary[Logging &amp; Monitoring](/categories/logging)

waylandace/xray
===============

A basic PHP instrumentation library for AWS X-Ray

v1.4.3(3y ago)112.3k2BSD-3-ClausePHPPHP ^7.4|^8.0

Since May 19Pushed 2y agoCompare

[ Source](https://github.com/WaylandAce/php-xray)[ Packagist](https://packagist.org/packages/waylandace/xray)[ RSS](/packages/waylandace-xray/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (21)Used By (0)

[![Build Status](https://camo.githubusercontent.com/d167aa4a636389b92c23e549699a0f178a8b0a01f179d04650d010e7381c774b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7761796c616e646163652f7068702d787261792e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/waylandace/php-xray)[![PHP 7.0](https://camo.githubusercontent.com/f478598da073b8b28c0dc535af11096d6274af9b9d61c0ab11e3d6456ac6cf2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e302d626c75652e7376673f7374796c653d666c61742d737175617265)](http://php.net/)
[![Packagist](https://camo.githubusercontent.com/808896b13ed3b4c0c94959f93bb62d78750c6d7c9b80e1d1294b0ae6996430f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7761796c616e646163652f787261792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/waylandace/xray)

waylandace\\xray
================

[](#waylandacexray)

A basic PHP instrumentation library for AWS X-Ray. Fork of

Until Amazon releases an official PHP SDK for AWS X-Ray this library allows you to add basic instrumentation to PHP applications and report traces via the AWS X-Ray daemon.

Please note that no automatic instrumentation of popular libraries is provided. In order to instrument SQL queries, HTTP requests and/or other services you'll be required to create your own wrappers which start and end tracing segments as appropriate.

Installation
------------

[](#installation)

The recommended way to install this library is using Composer:

```
$ composer require waylandace/xray ^1.2
```

Usage
-----

[](#usage)

### Starting a trace

[](#starting-a-trace)

The `Trace` class represents the top-level of an AWS X-Ray trace, and can function as a singleton for easy access from anywhere in your code, including before frameworks and dependency injectors have been initialised.

You should start a trace as early as possible in your request:

```
use Pkerrigan\Xray\Trace;

Trace::getInstance()
    ->setTraceHeader($_SERVER['HTTP_X_AMZN_TRACE_ID'] ?? null)
    ->setName('app.example.com')
    ->setUrl($_SERVER['REQUEST_URI'])
    ->setMethod($_SERVER['REQUEST_METHOD'])
    ->begin();
```

### Adding a segment to a trace

[](#adding-a-segment-to-a-trace)

You can add as many segments to your trace as necessary, including nested segments. To add an SQL query to your trace, you'd do the following:

```
Trace::getInstance()
    ->getCurrentSegment()
    ->addSubsegment(
        (new SqlSegment())
            ->setName('db.example.com')
            ->setDatabaseType('PostgreSQL')
            ->setQuery($mySanitisedQuery)    // Make sure to remove sensitive data before passing in a query
            ->begin()
    );

// Run your query here

Trace::getInstance()
    ->getCurrentSegment()
    ->end();

```

The `getCurrentSegment()` method will always return the most recently opened segment, allowing you to nest as deeply as necessary.

### Adding an exception to a trace

[](#adding-an-exception-to-a-trace)

You can add as many exceptions to your trace as necessary. Nested exceptions will be flattened and included in the trace. Adding an exception does *not* set error/fault flag.

```
Trace::getInstance()
    ->getCurrentSegment()
    ->addException($exception)
    ->setError(true);
```

### Ending a trace

[](#ending-a-trace)

At the end of your request, you'll want to end and submit your trace. By default only submitting via the AWS X-Ray daemon is supported.

```
Trace::getInstance()
    ->end()
    ->setResponseCode(http_response_code())
    ->submit(new DaemonSegmentSubmitter());
```

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~38 days

Total

15

Last Release

1458d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

v1.3.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a84d03e8014b3e51aad4d968631866bc9d5d4cacf3565b1752b4ef0c47458d6d?d=identicon)[WaylandAce](/maintainers/WaylandAce)

---

Top Contributors

[![patrickkerrigan](https://avatars.githubusercontent.com/u/20188719?v=4)](https://github.com/patrickkerrigan "patrickkerrigan (36 commits)")[![WaylandAce](https://avatars.githubusercontent.com/u/1263005?v=4)](https://github.com/WaylandAce "WaylandAce (32 commits)")[![umeku](https://avatars.githubusercontent.com/u/669387?v=4)](https://github.com/umeku "umeku (4 commits)")[![pavelkirpitsov](https://avatars.githubusercontent.com/u/101108921?v=4)](https://github.com/pavelkirpitsov "pavelkirpitsov (1 commits)")[![willtj](https://avatars.githubusercontent.com/u/465569?v=4)](https://github.com/willtj "willtj (1 commits)")

---

Tags

awsapmtracingX-RayAWS X-Ray

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waylandace-xray/health.svg)

```
[![Health](https://phpackages.com/badges/waylandace-xray/health.svg)](https://phpackages.com/packages/waylandace-xray)
```

###  Alternatives

[pkerrigan/xray

A basic PHP instrumentation library for AWS X-Ray

601.4M3](/packages/pkerrigan-xray)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2222.9M248](/packages/open-telemetry-sdk)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[friendsofopentelemetry/opentelemetry-bundle

Traces, metrics, and logs instrumentation within your Symfony application

638.6k](/packages/friendsofopentelemetry-opentelemetry-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
