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

HttpTransport example does not work #787

Closed
cosminardeleanu opened this issue Mar 6, 2019 · 10 comments
Closed

HttpTransport example does not work #787

cosminardeleanu opened this issue Mar 6, 2019 · 10 comments

Comments

@cosminardeleanu
Copy link

cosminardeleanu commented Mar 6, 2019

Your example from https://docs.sentry.io/platforms/php/#httptransport does not work, or is incomplete.

Used version 2.0.1.

Please add a working version and/or fix the code.

Context: I am trying to send messages, via queues, so i store the Event and dispatch it later, by using the HttpTransport.

use Http\Discovery\HttpAsyncClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Sentry\ClientBuilder;
use Sentry\Transport\HttpTransport;

$options = ['dsn' => '...'];
$builder = ClientBuilder::create($options);
$options = $builder->getOptions();

$transport = new HttpTransport($options, HttpAsyncClientDiscovery::find(), MessageFactoryDiscovery::find());
$builder->setTransport($transport);
$client = $builder->getClient();

echo $client->captureMessage('test message'); // Does not work.

$event = ... // Gathered from queue, serialized object.
$transport->send($event); // Also does not work.

This example does not work.
Looking deep in the sentry code, i have seen that the http transport model, is being filled with various plugins, that actually makes the guzzle6 adapter to work:

new BaseUriPlugin($uriFactory->createUri($options->getDsn())) and new AuthenticationPlugin(new SentryAuthentication($options, $sdkIdentifier, $sdkVersion));.

The only working around was to use the PluginClient and copy/paste the logic from ClientBuilder, private function createHttpClientInstance(): PluginClient.

@Jean85
Copy link
Collaborator

Jean85 commented Mar 6, 2019

As a workaround, you could use the Hub with no default integrations, and send the events from there. IT should result in a smaller code example that works.

@javascriptlove
Copy link

Can't get it to work also, the example is broken and/or incomplete. Seems like we still have to use the old Raven

@Jean85
Copy link
Collaborator

Jean85 commented Jul 1, 2019

This issue could be related to the issues we're facing with async transport...

@ste93cry
Copy link
Collaborator

ste93cry commented Jul 1, 2019

I don't think so, I believe that as written by @cosminardeleanu when you set your transport then you lose all the automation done to set the plugins to the HTTP client needed to authenticate with the server. It's a pity and we can think about fixing it, but for now it's this way

@B-Galati
Copy link
Contributor

B-Galati commented Jul 1, 2019

Just had the same issue, IMHO the spool transport is not usable right now from a DX perspective.

@B-Galati
Copy link
Contributor

B-Galati commented Jul 1, 2019

My workaround for now is to use reflection:

$reflection = new \ReflectionClass(ClientBuilder::class);
$method = $reflection->getMethod('createTransportInstance');
$method->setAccessible(true);
$httpTransport = $method->invoke($clientBuilder);

@RageZBla
Copy link
Contributor

@Jean85 would it acceptable to add a createHttpClientWithPlugin method to the ClientBuilder. That way the users could get their client wrapped without copy pasting the logic.

@Jean85
Copy link
Collaborator

Jean85 commented Jul 18, 2019

I'm not sure on how we should go with that but yes, we were already discussing something like that with @ste93cry. A PR is more than welcome, so we can discuss it over the code.

@RageZBla
Copy link
Contributor

@ste93cry @Jean85 if someone can review #855 and getsentry/sentry-docs#1122 🙇‍♂️

RageZBla added a commit to RageZBla/sentry-php that referenced this issue Aug 18, 2019
getsentry#787

This should ease the process of registering a custom transport.
ste93cry pushed a commit to RageZBla/sentry-php that referenced this issue Aug 27, 2019
getsentry#787

This should ease the process of registering a custom transport.
@ste93cry
Copy link
Collaborator

Closing as the official documentation has been fixed

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

No branches or pull requests

6 participants