Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

ref: Use constant for the SDK version

# This is the commit message #2:

docs: Update README.md & CONTRIBUTING.md (#650)

* docs: Update README.md & CONTRIBUTING.md

* Add slogan
# This is the commit message #3:

test: Add dsn to e2e test config (#657)

* test: Add dsn to e2e test config

* Add phpstan exclusion
# This is the commit message #4:

Fix Symfony 6 deprecations in E2E test (#656)


# This is the commit message #5:

fix: Update span ops (#655)
  • Loading branch information
cleptric committed Oct 11, 2022
1 parent 3314c20 commit 838cf45
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 40 deletions.
106 changes: 106 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,106 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Contributing to the Sentry SDK for Symfony

We welcome contributions to `sentry-symfony` by the community.

Please search the [issue tracker](https://github.com/getsentry/sentry-symfony/issues) before creating a new issue (a problem or an improvement request). Please also ask in our [Sentry Community on Discord](https://discord.com/invite/Ww9hbqr) before submitting a new issue. There is a ton of great people in our Discord community ready to help you!

If you feel that you can fix or implement it yourself, please read on to learn how to submit your changes.

## Submitting changes

- Setup the development environment.
- Clone the `sentry-symfony` repository and prepare necessary changes.
- Add tests for your changes to `tests/`.
- Run tests and make sure all of them pass.
- Submit a pull request, referencing any issues it addresses.
- Make sure to update the `CHANGELOG.md` file below the `Unreleased` heading.

We will review your pull request as soon as possible.
Thank you for contributing!

## Development environment

### Clone the repository

```bash
git clone git@github.com:getsentry/sentry-symfony.git
```

Make sure that you have PHP 7.2+ installed. Version 7.4 or higher is required to run style checkers. On macOS, we recommend using brew to install PHP. For Windows, we recommend an official PHP.net release.

### Install the dependencies

Dependencies are managed through [Composer](https://getcomposer.org/):

```bash
composer install
```

### Running tests

Tests can then be run via [PHPUnit](https://phpunit.de/):

```bash
vendor/bin/phpunit
```

## Releasing a new version

(only relevant for Sentry employees)

Prerequisites:

- All changes that should be released must be in the `master` branch.
- Every commit should follow the [Commit Message Format](https://develop.sentry.dev/commit-messages/#commit-message-format) convention.

Manual Process:

- Update CHANGELOG.md with the version to be released. Example commit: https://github.com/getsentry/sentry-symfony/commit/d1d2895c028676113cb191516b80b91abcde31f3.
- On GitHub in the `sentry-symfony` repository go to "Actions" select the "Release" workflow.
- Click on "Run workflow" on the right side and make sure the `master` branch is selected.
- Set "Version to release" input field. Here you decide if it is a major, minor or patch release. (See "Versioning Policy" below)
- Click "Run Workflow"

This will trigger [Craft](https://github.com/getsentry/craft) to prepare everything needed for a release. (For more information see [craft prepare](https://github.com/getsentry/craft#craft-prepare-preparing-a-new-release)) At the end of this process, a release issue is created in the [Publish](https://github.com/getsentry/publish) repository. (Example release issue: https://github.com/getsentry/publish/issues/815)

Now one of the persons with release privileges (most probably your engineering manager) will review this Issue and then add the `accepted` label to the issue.

There are always two persons involved in a release.

If you are in a hurry and the release should be out immediately there is a Slack channel called `#proj-release-approval` where you can see your release issue and where you can ping people to please have a look immediately.

When the release issue is labeled `accepted` [Craft](https://github.com/getsentry/craft) is triggered again to publish the release to all the right platforms. (See [craft publish](https://github.com/getsentry/craft#craft-publish-publishing-the-release) for more information). At the end of this process, the release issue on GitHub will be closed and the release is completed! Congratulations!

There is a sequence diagram visualizing all this in the [README.md](https://github.com/getsentry/publish) of the `Publish` repository.

### Versioning Policy

This project follows [semver](https://semver.org/), with three additions:

- Semver says that major version `0` can include breaking changes at any time. Still, it is common practice to assume that only `0.x` releases (minor versions) can contain breaking changes while `0.x.y` releases (patch versions) are used for backwards-compatible changes (bugfixes and features). This project also follows that practice.

- All undocumented APIs are considered internal. They are not part of this contract.

- Certain features (e.g. integrations) may be explicitly called out as "experimental" or "unstable" in the documentation. They come with their own versioning policy described in the documentation.

We recommend pinning your version requirements against `1.x.*` or `1.x.y`.
Either one of the following is fine:

```json
"sentry/sentry": "^1.0",
"sentry/sentry": "^1",
```

A major release `N` implies the previous release `N-1` will no longer receive updates. We generally do not backport bugfixes to older versions unless they are security relevant. However, feel free to ask for backports of specific commits on the bug tracker.

## Commit message format guidelines

See the documentation on commit messages here:

https://develop.sentry.dev/commit-messages/#commit-message-format
74 changes: 47 additions & 27 deletions README.md
Expand Up @@ -4,31 +4,30 @@
</a>
</p>

# sentry-symfony
_Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us [<kbd>**Check out our open positions**</kbd>](https://sentry.io/careers/)_

Symfony integration for [Sentry](https://getsentry.com/).
# Official Sentry SDK for Symfony

[![Stable release][Last stable image]][Packagist link]
[![License](https://poser.pugx.org/sentry/sentry/license)](https://packagist.org/packages/sentry/sentry)
[![Total Downloads](https://poser.pugx.org/sentry/sentry/downloads)](https://packagist.org/packages/sentry/sentry)
[![Monthly Downloads](https://poser.pugx.org/sentry/sentry/d/monthly)](https://packagist.org/packages/sentry/sentry)
[![License](https://poser.pugx.org/sentry/sentry/license)](https://packagist.org/packages/sentry/sentry)

![CI](https://github.com/getsentry/sentry-symfony/workflows/CI/badge.svg) [![Coverage Status][Master Code Coverage Image]][Master Code Coverage]
[![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/cWnMQeA)

## Benefits
This is the official Symfony SDK for [Sentry](https://getsentry.com/).

## Getting Started

Use `sentry-symfony` for:
Using this `sentry-symfony` SDK provides you with the following benefits:

* A fast Sentry setup
* Easy configuration in your Symfony app
* Automatic wiring in your app. Each event has the following things added automatically to it:
- user
- Symfony environment
- app path
- excluded paths (cache and vendor)
* Quickly integrate and configure Sentry for your Symfony app
* Out of the box, each event will contain the following data by default
- The currently authenticated user
- The Symfony environment

## Installation
### Install

To install the SDK you will need to be using [Composer]([https://getcomposer.org/)
in your project. To install it please see the [docs](https://getcomposer.org/download/).
Expand All @@ -37,7 +36,7 @@ in your project. To install it please see the [docs](https://getcomposer.org/dow
composer require sentry/sentry-symfony
```

If you're using the [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) Composer plugin, it could show a message similar to this:
If you're using the [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) Composer plugin, you might encounter a message similar to this:

```
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Expand All @@ -48,9 +47,8 @@ Do you want to execute this recipe?

Just type `y`, press return, and the procedure will continue.

**Warning:** due to a bug in all versions lower than `6.0` of the [`SensioFrameworkExtra`](https://github.com/sensiolabs/SensioFrameworkExtraBundle) bundle,
if you have it installed you will likely get an error during the execution of the commands above in regards to the missing `Nyholm\Psr7\Factory\Psr17Factory`
class. To workaround the issue, if you are not using the PSR-7 bridge, please change the configuration of that bundle as follows:
**Caution:** Due to a bug in the [`SensioFrameworkExtra`](https://github.com/sensiolabs/SensioFrameworkExtraBundle) bundle, affecting version 6.0 and below, you might run into a missing `Nyholm\Psr7\Factory\Psr17Factory::class` error while executing the commands mentioned above.
If you are not using the PSR-7 bridge, you can work around this issue by changing the configuration of the bundle as follows:

```yaml
sensio_framework_extra:
Expand All @@ -60,7 +58,7 @@ sensio_framework_extra:

For more details about the issue see https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710.

### Step 2: Enable the Bundle
### Enable the Bundle

If you installed the package using the Flex recipe, the bundle will be automatically enabled. Otherwise, enable it by adding it to the list
of registered bundles in the `Kernel.php` file of your project:
Expand All @@ -80,13 +78,16 @@ class AppKernel extends \Symfony\Component\HttpKernel\Kernel
}
```

Note that, unlike before in version 3, the bundle will be enabled in all environments; event reporting, instead, is enabled
only when providing a DSN (see the next step).
The bundle will be enabled in all environments by default.
To enable event reporting, you'll need to add a DSN (see the next step).

## Configuration of the SDK
### Configure

Add your [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) value of your project, if you have Symfony 3.4 add it to ``app/config/config_prod.yml`` for Symfony 4 or newer add the value to `config/packages/sentry.yaml`.
Keep in mind that leaving the `dsn` value empty (or undeclared) in other environments will effectively disable Sentry reporting.
Add the [Sentry DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) of your project.
If you're using Symfony 3.4, add the DSN to your `app/config/config_prod.yml` file.
For Symfony 4 or newer, add the DSN to your `config/packages/sentry.yaml` file.

Keep in mind that by leaving the `dsn` value empty (or undeclared), you will disable Sentry's event reporting.

```yaml
sentry:
Expand All @@ -105,20 +106,19 @@ the [PHP specific](https://docs.sentry.io/platforms/php/#php-specific-options) o

#### Optional: use custom HTTP factory/transport

Since SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to have installed two packages that provides
Since the SDK 2.0 uses HTTPlug to remain transport-agnostic, you need to install two packages that provide
[`php-http/async-client-implementation`](https://packagist.org/providers/php-http/async-client-implementation)
and [`psr/http-message-implementation`](https://packagist.org/providers/psr/http-message-implementation).

This bundle depends on `sentry/sdk`, which is a metapackage that already solves this need, requiring our suggested HTTP
packages: the Curl client and Guzzle's message factories.

If instead you want to use a different HTTP client or message factory, you can override the ``sentry/sdk`` package adding the following to your ``composer.json`` after the ``require`` section:
Instead, if you want to use a different HTTP client or message factory, you can override the ``sentry/sdk`` package by adding the following to your ``composer.json`` after the ``require`` section:
```json
"replace": {
"sentry/sdk": "*"
}
```
This will prevent the installation of ``sentry/sdk`` package and will allow you to install through Composer the HTTP client or message factory of your choice.

For example for using Guzzle's components:

Expand Down Expand Up @@ -154,7 +154,8 @@ sentry:
YourValueObject: 'ValueObjectSerializer'
```

Several serializers can be added and the serializable check is done using **instanceof**. The serializer must implements the `__invoke` method returning an **array** with the information to send to sentry (class name is always sent).
Several serializers can be added and the serializable check is done by using the **instanceof** type operator.
The serializer must implement the `__invoke` method, which needs to return an **array**, containing the information that should be send to Sentry. The class name is always sent by default.

Serializer example:
```php
Expand All @@ -169,6 +170,25 @@ final class ValueObjectSerializer
}
```

## Contributing to the SDK

Please refer to [CONTRIBUTING.md](CONTRIBUTING.md).

## Getting help/support

If you need help setting up or configuring the Symfony SDK (or anything else in the Sentry universe) please head over to the [Sentry Community on Discord](https://discord.com/invite/Ww9hbqr). There is a ton of great people in our Discord community ready to help you!

## Resources

- [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/quickstart/)
- [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
- [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](http://stackoverflow.com/questions/tagged/sentry)
- [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)

## License

Licensed under the Apache 2.0 license, see [`LICENSE`](LICENSE)

[Last stable image]: https://poser.pugx.org/sentry/sentry-symfony/version.svg
[Packagist link]: https://packagist.org/packages/sentry/sentry-symfony
[Master Code Coverage]: https://codecov.io/gh/getsentry/sentry-symfony/branch/master
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Expand Up @@ -10,6 +10,8 @@ parameters:
- src/aliases.php
excludePaths:
- src/aliases.php
- src/Tracing/Cache/TraceableCacheAdapterForV2.php
- src/Tracing/Cache/TraceableTagAwareCacheAdapterForV2.php
- src/Tracing/Doctrine/DBAL/TracingStatementForV2.php
- src/Tracing/Doctrine/DBAL/TracingDriverForV2.php
- src/Tracing/HttpClient/TraceableHttpClientForV4.php
Expand Down
3 changes: 1 addition & 2 deletions src/DependencyInjection/SentryExtension.php
Expand Up @@ -5,7 +5,6 @@
namespace Sentry\SentryBundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use LogicException;
use Psr\Log\NullLogger;
use Sentry\Client;
Expand Down Expand Up @@ -140,7 +139,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
$clientBuilderDefinition = (new Definition(ClientBuilder::class))
->setArgument(0, new Reference('sentry.client.options'))
->addMethodCall('setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER])
->addMethodCall('setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()])
->addMethodCall('setSdkVersion', [SentryBundle::SDK_VERSION])
->addMethodCall('setTransportFactory', [new Reference($config['transport_factory'])])
->addMethodCall('setSerializer', [$serializer])
->addMethodCall('setRepresentationSerializer', [$representationSerializerDefinition])
Expand Down
2 changes: 2 additions & 0 deletions src/SentryBundle.php
Expand Up @@ -14,6 +14,8 @@ final class SentryBundle extends Bundle
{
public const SDK_IDENTIFIER = 'sentry.php.symfony';

public const SDK_VERSION = '4.3.1';

public function build(ContainerBuilder $container): void
{
parent::build($container);
Expand Down
2 changes: 1 addition & 1 deletion src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php
Expand Up @@ -14,7 +14,7 @@ abstract class AbstractTracingStatement
/**
* @internal
*/
public const SPAN_OP_STMT_EXECUTE = 'sql.stmt.execute';
public const SPAN_OP_STMT_EXECUTE = 'db.sql.execute';

/**
* @var HubInterface The current hub
Expand Down
12 changes: 6 additions & 6 deletions src/Tracing/Doctrine/DBAL/TracingDriverConnection.php
Expand Up @@ -23,32 +23,32 @@ final class TracingDriverConnection implements TracingDriverConnectionInterface
/**
* @internal
*/
public const SPAN_OP_CONN_PREPARE = 'sql.conn.prepare';
public const SPAN_OP_CONN_PREPARE = 'db.sql.prepare';

/**
* @internal
*/
public const SPAN_OP_CONN_QUERY = 'sql.conn.query';
public const SPAN_OP_CONN_QUERY = 'db.sql.query';

/**
* @internal
*/
public const SPAN_OP_CONN_EXEC = 'sql.conn.exec';
public const SPAN_OP_CONN_EXEC = 'db.sql.exec';

/**
* @internal
*/
public const SPAN_OP_CONN_BEGIN_TRANSACTION = 'sql.conn.begin_transaction';
public const SPAN_OP_CONN_BEGIN_TRANSACTION = 'db.sql.transaction.begin';

/**
* @internal
*/
public const SPAN_OP_TRANSACTION_COMMIT = 'sql.transaction.commit';
public const SPAN_OP_TRANSACTION_COMMIT = 'db.sql.transaction.commit';

/**
* @internal
*/
public const SPAN_OP_TRANSACTION_ROLLBACK = 'sql.transaction.rollback';
public const SPAN_OP_TRANSACTION_ROLLBACK = 'db.sql.transaction.rollback';

/**
* @var HubInterface The current hub
Expand Down
4 changes: 2 additions & 2 deletions src/Transport/TransportFactory.php
Expand Up @@ -6,14 +6,14 @@

use Http\Client\HttpAsyncClient as HttpAsyncClientInterface;
use Http\Discovery\Psr17FactoryDiscovery;
use Jean85\PrettyVersions;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Log\LoggerInterface;
use Sentry\HttpClient\HttpClientFactory;
use Sentry\Options;
use Sentry\SentryBundle\SentryBundle;
use Sentry\Transport\DefaultTransportFactory;
use Sentry\Transport\TransportFactoryInterface;
use Sentry\Transport\TransportInterface;
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct(
$streamFactory,
$httpClient,
'sentry.php.symfony',
PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()
SentryBundle::SDK_VERSION
),
$logger
);
Expand Down
3 changes: 1 addition & 2 deletions tests/DependencyInjection/SentryExtensionTest.php
Expand Up @@ -5,7 +5,6 @@
namespace Sentry\SentryBundle\Tests\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Sentry\ClientInterface;
Expand Down Expand Up @@ -244,7 +243,7 @@ public function testClientIsCreatedFromOptions(): void

$this->assertCount(6, $methodCalls);
$this->assertDefinitionMethodCallAt($methodCalls[0], 'setSdkIdentifier', [SentryBundle::SDK_IDENTIFIER]);
$this->assertDefinitionMethodCallAt($methodCalls[1], 'setSdkVersion', [PrettyVersions::getVersion('sentry/sentry-symfony')->getPrettyVersion()]);
$this->assertDefinitionMethodCallAt($methodCalls[1], 'setSdkVersion', [SentryBundle::SDK_VERSION]);
$this->assertDefinitionMethodCallAt($methodCalls[2], 'setTransportFactory', [new Reference('App\\Sentry\\Transport\\TransportFactory')]);
$this->assertDefinitionMethodCallAt($methodCalls[5], 'setLogger', [new Reference('app.logger')]);

Expand Down
4 changes: 4 additions & 0 deletions tests/End2End/App/Kernel.php
Expand Up @@ -44,6 +44,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load(__DIR__ . '/deprecations_for_5.yml');
}

if (self::VERSION_ID >= 60000) {
$loader->load(__DIR__ . '/deprecations_for_6.yml');
}

if (interface_exists(MessageBusInterface::class) && self::VERSION_ID >= 40300) {
$loader->load(__DIR__ . '/messenger.yml');
}
Expand Down

0 comments on commit 838cf45

Please sign in to comment.