Skip to content

Commit

Permalink
test http-client tracing enabled/disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Jun 22, 2022
1 parent 8c07a83 commit 61b7a5e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Expand Up @@ -128,7 +128,7 @@ jobs:
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Remove optional packages
run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache --dev --no-update
run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache symfony/http-client --dev --no-update

- name: Install dependencies
uses: ramsey/composer-install@v1
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/config/schema/sentry-1.0.xsd
Expand Up @@ -91,6 +91,7 @@
<xsd:element name="twig" type="tracing-twig" minOccurs="0" maxOccurs="1" />
<xsd:element name="cache" type="tracing-cache" minOccurs="0" maxOccurs="1" />
<xsd:element name="console" type="tracing-console" minOccurs="0" maxOccurs="1" />
<xsd:element name="http-client" type="tracing-http-client" minOccurs="0" maxOccurs="1" />
</xsd:choice>

<xsd:attribute name="enabled" type="xsd:boolean" default="true"/>
Expand All @@ -117,4 +118,8 @@
<xsd:element name="excluded-command" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="tracing-http-client">
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>
</xsd:schema>
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'tracing' => [
'http_client' => [
'enabled' => true,
],
],
]);
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config>
<sentry:tracing>
<sentry:http-client enabled="true" />
</sentry:tracing>
</sentry:config>
</container>
@@ -0,0 +1,4 @@
sentry:
tracing:
http_client:
enabled: true
13 changes: 13 additions & 0 deletions tests/DependencyInjection/SentryExtensionTest.php
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ErrorHandler\Error\FatalError;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
Expand Down Expand Up @@ -380,6 +381,18 @@ public function testTwigTracingExtensionIsConfiguredWhenTwigTracingIsEnabled():
$this->assertTrue($container->hasDefinition(TwigTracingExtension::class));
}

public function testHttpClientTracingExtensionIsConfiguredWhenHttpClientTracingIsEnabled(): void
{
if (!class_exists(HttpClient::class)) {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Http client tracing support cannot be enabled because the symfony/http-client Composer package is not installed.');
}

$container = $this->createContainerFromFixture('http_client_tracing_enabled');

$this->assertTrue($container->getParameter('sentry.tracing.http_client.enabled'));
}

public function testTwigTracingExtensionIsRemovedWhenTwigTracingIsDisabled(): void
{
$container = $this->createContainerFromFixture('full');
Expand Down

0 comments on commit 61b7a5e

Please sign in to comment.