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

add symfony default tags #116

Merged
merged 5 commits into from Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/SentrySymfonyClient.php
Expand Up @@ -15,6 +15,11 @@ public function __construct(?string $dsn = null, array $options = [])
'name' => 'sentry-symfony',
'version' => SentryBundle::getVersion(),
];
$default_tags = [
'symfony_version' => \Symfony\Component\HttpKernel\Kernel::VERSION,
];
$options['tags'] = $options['tags'] ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umh, I don't understand why you need to do those two lines. Isn't $options['tags']['symfony_version'] = ... just enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • when no tags set, be sure to have atleast an empty array (to be ok, later on with array_merge).
  • merge user provided tags with default tags.

i am quite confident that it works, but open for alternative suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$options['tags']['symfony_version'] = - might fail if tags is not an array/key

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The var is initialized as array $options = [] so it's an array for sure, worst case an empty one.

Since it's an array, setting directly $options['tags']['symfony_version'] will never fail, so merging is unnecessary.

$options['tags'] = array_merge($options['tags'], $default_tags);

parent::__construct($dsn, $options);
}
Expand Down
3 changes: 3 additions & 0 deletions test/SentrySymfonyClientTest.php
Expand Up @@ -22,13 +22,16 @@ public function test_that_it_forwards_options()
{
$client = new SentrySymfonyClient('https://a:b@app.getsentry.com/project', [
'name' => 'test',
'tags' => ['some_custom' => 'test'],
]);

$data = $client->get_default_data();

// Not a big fan of doing this kind of assertions, couples tests to external API...
// Perhaps, refactor is needed for this class?
$this->assertEquals('test', $data['server_name']);
$this->assertEquals(\Symfony\Component\HttpKernel\Kernel::VERSION, $data['tags']['symfony_version']);
$this->assertEquals('test', $data['tags']['some_custom']);
$this->assertEquals('https://app.getsentry.com/api/project/store/', $client->getServerEndpoint(null));
$this->assertEquals('a', $client->public_key);
$this->assertEquals('b', $client->secret_key);
Expand Down