Skip to content
Open
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
84 changes: 84 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Tests

on:
push:
branches: [main]
pull_request:

jobs:
linux:
name: PHP ${{ matrix.php }}${{ matrix.ts && ' (ZTS)' || '' }} (Linux)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
ts: [false, true]
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-ts: ${{ matrix.ts }}

- name: Build
run: |
phpize
./configure --enable-sentry
make

- name: Test
run: make test TESTS="--show-diff" NO_INTERACTION=1

valgrind:
name: Valgrind (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Install valgrind
run: sudo apt-get install -y valgrind

- name: Build
run: |
phpize
./configure --enable-sentry
make

- name: Test under valgrind
run: make test TESTS="--show-diff -m" NO_INTERACTION=1

windows:
name: PHP ${{ matrix.php-version }} (${{ matrix.arch }}, ${{ matrix.ts == '' && 'nts' || 'ts' }}) (Windows)
needs: get-windows-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.get-windows-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4

- uses: php/php-windows-builder/extension@v1
with:
php-version: ${{ matrix.php-version }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}
args: --enable-sentry

get-windows-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4

- id: matrix
uses: php/php-windows-builder/extension-matrix@v1
with:
php-version-list: '8.0, 8.1, 8.2, 8.3, 8.4, 8.5'
arch-list: x64
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
# sentry-php-tracer

This is work in progress.
> [!CAUTION]
> Work in progress. Expect API changes while not 1.0

Sentry extension to enable automatic instrumentation of methods and functions.

Methods/functions can be instrumented by either declaring the #[\Sentry\Trace] attribute on them
or registering them with `\Sentry\instrument("MyClass", "myFunction)`.

The extension is meant to only provide telemetry information for methods/functions, such as `duration` or `start_time`.
Creating spans and maintaining a proper span will be done in the SDK to minimize the number of required updates
for the extension itself.

## Callbacks

The extension offers two callbacks, one before a function is executed and one after execution.

Data returned in the startCallback will be passed back as second parameter of the endCallback.
This provides a way to pass data between the callbacks without a custom storage.

Each callback gets a data array as first parameter with the following keys:

| Key | When | Description |
|------------|-----------|--------------------------------------------------|
| start_time | start,end | The start time as float timestamp |
| end_time | end | The end time as float timestamp |
| duration | end | The duration in float milliseconds |
| name | start,end | The name of the function/method |
| metadata | start,end | The array with the metadata specified, see below |

### Example

```php
\Sentry\setStartCallback(static function (array $data) {
return ['spanId' => generateSpanId()];
});

\Sentry\setEndCallback(static function (array $data, $userData) {
setTelemetryData([
'name' => $data['name'],
'duration' => $data['duration'],
'spanId' => $userData['spanId'];
]);
});

```

## Attributes/Metadata

Metadata/attributes can be provided in the attribute and the instrument function.

Attribute:
`#[\Sentry\Trace(['my-attribute' => 'test', 'other' => 'foo'])]`

Function:
`\Sentry\instrument("MyClass", "myFunction", ['my-attribute' => 'test', 'other' => 'foo']`

## Build the extension

Expand Down
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PHP_ARG_ENABLE(sentry, whether to enable Sentry support,
[ --enable-sentry Enable Sentry support])
if test "$PHP_SENTRY" = "yes"; then
AC_DEFINE(HAVE_SENTRY, 1, [Whether you have Sentry])
PHP_NEW_EXTENSION(Sentry, sentry.c, $ext_shared)
PHP_NEW_EXTENSION(sentry, sentry.c, $ext_shared)
fi
5 changes: 5 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG_ENABLE("sentry", "Enable Sentry support", "no");
if (PHP_SENTRY == "yes") {
AC_DEFINE("HAVE_SENTRY", 1, "Whether you have Sentry");
EXTENSION("Sentry", "sentry.c", true);
}
17 changes: 0 additions & 17 deletions php_sentry.h

This file was deleted.

Loading
Loading