Skip to content

Add support for capturing function parameters #9

Description

@linear-code

To simplify capturing parameters, we can allow a mapping from parameters to attributes. This can be useful if simple values and no preprocessing is required so they can be directly moved into metadata.

For example, it could look like this:

function test(string $name) {
}

instrument(null, "test", spanAttributes: ['description' => 'name']);

setEndCallback(static function(array $data) {
  $data['metadata']['name'] // contains 'example'
});

test('example');

We can also extend it to allow one level of property access:

function test(Request $request) {
}

instrument(null, "test", spanAttributes: ['description' => ['request', 'getUrl()']]);

This would add the value of $request->getUrl() into $data['metadata']['description']

If the parameter name doesn't exist or any function/property doesn't exist, it should do nothing and not crash the user application

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions