Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ statusProvider:
name: github
artifactProvider:
name: none
preReleaseCommand: ""
targets:
- name: github
- name: registry
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Use constant for the SDK version (#1367)

## 3.8.1 (2022-09-21)

- fix: Do not throw an TypeError on numeric HTTP headers (#1370)
Expand Down
24 changes: 24 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -eux

if [ "$(uname -s)" != "Linux" ]; then
echo "Please use the GitHub Action."
exit 1
fi

SCRIPT_DIR="$( dirname "$0" )"
cd $SCRIPT_DIR/..

OLD_VERSION="${1}"
NEW_VERSION="${2}"

echo "Current version: $OLD_VERSION"
echo "Bumping version: $NEW_VERSION"

function replace() {
! grep "$2" $3
perl -i -pe "s/$1/$2/g" $3
grep "$2" $3 # verify that replacement was successful
}

replace "SDK_VERSION = '[0-9.]+'" "SDK_VERSION = '$NEW_VERSION'" ./src/Client.php
8 changes: 6 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sentry;

use GuzzleHttp\Promise\PromiseInterface;
use Jean85\PrettyVersions;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Sentry\Integration\IntegrationInterface;
Expand Down Expand Up @@ -33,6 +32,11 @@ final class Client implements ClientInterface
*/
public const SDK_IDENTIFIER = 'sentry.php';

/**
* The version of the SDK.
*/
public const SDK_VERSION = '3.8.0';

/**
* @var Options The client options
*/
Expand Down Expand Up @@ -102,7 +106,7 @@ public function __construct(
$this->representationSerializer = $representationSerializer ?? new RepresentationSerializer($this->options);
$this->stacktraceBuilder = new StacktraceBuilder($options, $this->representationSerializer);
$this->sdkIdentifier = $sdkIdentifier ?? self::SDK_IDENTIFIER;
$this->sdkVersion = $sdkVersion ?? PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
$this->sdkVersion = $sdkVersion ?? self::SDK_VERSION;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sentry;

use Http\Discovery\Psr17FactoryDiscovery;
use Jean85\PrettyVersions;
use Psr\Log\LoggerInterface;
use Sentry\HttpClient\HttpClientFactory;
use Sentry\Serializer\RepresentationSerializerInterface;
Expand Down Expand Up @@ -59,7 +58,7 @@ final class ClientBuilder implements ClientBuilderInterface
/**
* @var string The SDK version of the Client
*/
private $sdkVersion;
private $sdkVersion = Client::SDK_VERSION;

/**
* Class constructor.
Expand All @@ -69,7 +68,6 @@ final class ClientBuilder implements ClientBuilderInterface
public function __construct(Options $options = null)
{
$this->options = $options ?? new Options();
$this->sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sentry;

use Jean85\PrettyVersions;
use Sentry\Context\OsContext;
use Sentry\Context\RuntimeContext;
use Sentry\Tracing\Span;
Expand Down Expand Up @@ -153,7 +152,7 @@ final class Event
/**
* @var string The Sentry SDK version
*/
private $sdkVersion;
private $sdkVersion = Client::SDK_VERSION;

/**
* @var EventType The type of the Event
Expand All @@ -164,7 +163,6 @@ private function __construct(?EventId $eventId, EventType $eventType)
{
$this->id = $eventId ?? EventId::generate();
$this->timestamp = microtime(true);
$this->sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
$this->type = $eventType;
}

Expand Down
6 changes: 2 additions & 4 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sentry\Tests;

use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Sentry\Client;
use Sentry\ClientBuilder;
Expand Down Expand Up @@ -38,14 +37,13 @@ public function testNullTransportIsUsedWhenNoServerIsConfigured(): void
public function testClientBuilderFallbacksToDefaultSdkIdentifierAndVersion(): void
{
$callbackCalled = false;
$expectedVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();

$options = new Options();
$options->setBeforeSendCallback(function (Event $event) use ($expectedVersion, &$callbackCalled) {
$options->setBeforeSendCallback(function (Event $event) use (&$callbackCalled) {
$callbackCalled = true;

$this->assertSame(Client::SDK_IDENTIFIER, $event->getSdkIdentifier());
$this->assertSame($expectedVersion, $event->getSdkVersion());
$this->assertSame(Client::SDK_VERSION, $event->getSdkVersion());

return null;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Serializer/PayloadSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Sentry\Tests\Serializer;

use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Sentry\Breadcrumb;
use Sentry\Client;
use Sentry\Context\OsContext;
use Sentry\Context\RuntimeContext;
use Sentry\Event;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function serializeDataProvider(): iterable
{
ClockMock::withClockMock(1597790835);

$sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
$sdkVersion = Client::SDK_VERSION;

yield [
Event::createEvent(new EventId('fc9442f5aef34234bb22b9a615e30ccd')),
Expand Down