Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document array shapes for parameters and complex array structures? #1656

Closed
Ocramius opened this issue Dec 7, 2023 · 2 comments
Closed

Document array shapes for parameters and complex array structures? #1656

Ocramius opened this issue Dec 7, 2023 · 2 comments

Comments

@Ocramius
Copy link

Ocramius commented Dec 7, 2023

Problem Statement

Hey there! I was working on a codebase this morning, and noticed that Sentry does not really document the various keys that could be passed to functions like Sentry\init().

For example:

    \Sentry\init([
        'dsn' => '<SNIP>',
        'environment' => some_env(),
        'send_default_pii' => true,
        'prefixes' => [
            realpath(__DIR__),
        ],
        'before_send' => new RemoveApiKeyBeforeSending(),
        'traces_sample_rate' => 0.001,
        'profiles_sample_rate' => 1.0,
    ]);

There are tons of configuration options, and tools like PHPStan and Psalm can pick these up.

Solution Brainstorm

It would be nice to declare the the types in the Sentry SDK directly, both for documentation and for type-checking purposes:

/**
 * Creates a new Client and Hub which will be set as current.
 *
- * @param array<string, mixed> $options The client options
+ * @param array{
+ *   dsn?: non-empty-string,
+ *   environment?: non-empty-string,
+ *   send_default_pii?: bool,
+ *   prefixes?: non-empty-list<non-empty-string>,
+ * ...
+ * } $options The client options
 */
function init(array $options = []): void
{
    $client = ClientBuilder::create($options)->getClient();

    SentrySdk::init()->bindClient($client);
}

Note: the 3 ... at the end are part of the type signature (more keys allowed), but obviously, my example is far from exhaustive :D

This can generally be done with functions and methods in the SDK, over time :-)

@cleptric
Copy link
Member

cleptric commented Jul 2, 2024

This was added in #1738.

@cleptric cleptric closed this as completed Jul 2, 2024
@Ocramius
Copy link
Author

Ocramius commented Jul 2, 2024

Amazing! Thanks @PrinsFrank!

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

No branches or pull requests

2 participants