You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(core): add TraceMethod attribute with return and exception control
Replace the argument-only TraceArguments attribute with a unified
TraceMethod attribute that governs all method-level tracing from one
place. Beyond capturing arguments, it can now record the return value
as a span attribute and toggle exception recording independently, so
callers can trace outcomes without leaking sensitive stack details.
When exception recording is off, the span is still marked as errored
without attaching the exception message.
* refactor(core): replace TraceArguments with TraceMethod
feat(core): capture return values and control exception recording
Remove the deprecated TraceArguments attribute now that TraceMethod
supersedes it, and migrate all fixtures, tests and benchmarks to the
new attribute. The scan map now carries per-method arguments, return
and exception flags instead of a bare argument-position map, so
callers can toggle argument capture, return-value recording and
exception details independently.
Raise the phpbench memory_limit to 512M to keep class-generation
benchmarks from exhausting memory.
---
Header is two lines because the change is genuinely both a rename and a feature; collapse to just the `refactor` line if you want one type. → skipped: nothing.
* refactor(docs): rename TraceArguments to TraceMethod
Align the READMEs with the renamed attribute, which now captures
the return value and records exceptions in addition to arguments.
Document the new `arguments`/`return`/`exception` flags on both
the attribute and the direct `register()` method map, plus the
`code.return` span attribute and the exception-event opt-out.
* feat(deps): pin internal package to self.version in bundles
Ensure the Laravel and Symfony bundles always require the exact
core package version from this monorepo instead of a loose ^0.3
constraint, keeping them in lockstep on every release.
Copy file name to clipboardExpand all lines: packages/core/README.md
+29-20Lines changed: 29 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ namespace App\Service;
30
30
31
31
class OrderService
32
32
{
33
-
public function pay(int $orderId, string $card, Address $address): void {}
33
+
public function pay(int $orderId, string $card, Address $address): string {}
34
34
public function healthCheck(): bool {}
35
35
}
36
36
@@ -49,21 +49,23 @@ use Eerzho\Instrumentation\Class\Attribute\Trace;
49
49
// #[Trace(include: ['pay'])] // or: only pay
50
50
class OrderService
51
51
{
52
-
public function pay(int $orderId, string $card, Address $address): void {}
52
+
public function pay(int $orderId, string $card, Address $address): string {}
53
53
public function healthCheck(): bool {}
54
54
}
55
55
```
56
56
57
-
### 2. `#[TraceArguments]` — pick the captured arguments
57
+
### 2. `#[TraceMethod]` — capture arguments, return value, and exceptions
58
58
59
59
```php
60
-
use Eerzho\Instrumentation\Class\Attribute\TraceArguments;
60
+
use Eerzho\Instrumentation\Class\Attribute\TraceMethod;
61
61
62
-
#[TraceArguments(exclude: ['card'])] // capture every arg but card
63
-
// #[TraceArguments(include: ['orderId'])] // or: only orderId
64
-
public function pay(int $orderId, string $card, Address $address): void {}
62
+
#[TraceMethod(exclude: ['card'])] // capture every arg but card
63
+
// #[TraceMethod(include: ['orderId'])] // or: only orderId
64
+
public function pay(int $orderId, string $card, Address $address): string {}
65
65
```
66
66
67
+
By default, it captures the arguments and the return value, and records exceptions. Turn each off with `arguments: false`, `return: false`, or `exception: false` (a disabled exception still sets the span status to `ERROR`, only its event is omitted).
68
+
67
69
### 3. `#[TraceProperties]` — expand an object argument
68
70
69
71
```php
@@ -95,20 +97,24 @@ Skip `AttributeScanner` and hand `register()` the method map directly:
95
97
```php
96
98
ClassInstrumentation::register([
97
99
OrderService::class => [
98
-
'pay' => ['orderId' => 0], // trace, capture orderId only
99
-
'cancel' => [], // trace, capture nothing
100
+
'pay' => [
101
+
'arguments' => ['orderId' => 0], // name => position
Each entry maps a class → its methods → each method's arguments (`name => position`). Anything not listed is not traced or not captured.
111
+
Each method maps to its `arguments` (`name => position`) plus the `return` and `exception` flags. Missing keys default to off. Anything not listed is not traced.
106
112
107
113
## Traced output
108
114
109
115
### Selecting what to trace
110
116
111
-
`include` and `exclude` behave the same wherever they appear — `#[Trace]`, `#[TraceArguments]`, `#[TraceProperties]`:
117
+
`include` and `exclude` behave the same wherever they appear — `#[Trace]`, `#[TraceMethod]`, `#[TraceProperties]`:
|`code.file.path`| File where the method is defined |
162
+
|`code.line.number`| Line number of the method |
163
+
|`code.return`| Return value, serialized the same way (on success, unless `return: false`) |
164
+
| Method arguments | Parameter name → serialized value |
158
165
159
166
If the method throws, the span records an `exception` event and its status is set to `ERROR`:
160
167
@@ -164,18 +171,20 @@ If the method throws, the span records an `exception` event and its status is se
164
171
|`exception.message`| Exception message |
165
172
|`exception.stacktrace`| Full stack trace |
166
173
174
+
With `exception: false` the status still becomes `ERROR`, but the event above is omitted.
175
+
167
176
## How it works
168
177
169
178
`AttributeScanner::scan()` reflects over the classes you pass it:
170
179
171
180
1. Skips abstract classes, interfaces, traits, and enums.
172
181
2. Reads `#[Trace]` on the class — no attribute, no instrumentation.
173
-
3. Collects the public methods allowed by `include` / `exclude`, and for each the arguments allowed by `#[TraceArguments]`.
182
+
3. Collects the public methods allowed by `include` / `exclude`, and for each the arguments, return value, and exception recording configured by `#[TraceMethod]`.
174
183
175
-
It returns a `class → method → {argument: position}` map. `ClassInstrumentation::register()` then installs an `ext-opentelemetry` hook on every mapped method:
184
+
It returns a `class → method → {arguments, return, exception}` map. `ClassInstrumentation::register()` then installs an `ext-opentelemetry` hook on every mapped method:
176
185
177
186
-**pre** — opens the span and attaches the `code.*` attributes and serialized arguments.
178
-
-**post** — records the exception and sets `ERROR` status if the method threw, then ends the span.
187
+
-**post** — captures the return value on success, records the exception and sets `ERROR` status on failure, then ends the span.
0 commit comments