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

How to integrate with Laravel 5.3 #301

Closed
tristanjahier opened this issue Feb 15, 2019 · 7 comments
Closed

How to integrate with Laravel 5.3 #301

tristanjahier opened this issue Feb 15, 2019 · 7 comments

Comments

@tristanjahier
Copy link

Hi,

I'm trying to integrate this in a Laravel 5.3 application, but I'm confused about how I am supposed to do it.

In previous releases, this package used to have a LaravelProvider class that I had to register in config/app.php. But it cannot work anymore because the DDTrace\Integrations\Laravel\V5\LaravelProvider class does not exist anymore. And I've read that this is deprecated.

If I understood correctly I have to use DDTrace\Integrations\Laravel\LaravelIntegration but I'm confused about how to use it.

Do I have to call

\DDTrace\Integrations\Laravel\LaravelIntegration::load();

in my AppServiceProvider for example?

@labbati
Copy link
Member

labbati commented Feb 15, 2019

Hi @tristanjahier, please refer to the upgrade guide.

Basically (unless you are doing some manual instrumentation):

  • Remove datadog/dd-trace from your composer dependencies
  • remove the provider
  • remove any code related to datadog
  • install latest version 0.13.1

This is enough if you don't require manual instrumentation.

@labbati
Copy link
Member

labbati commented Feb 18, 2019

Hi @tristanjahier any luck with this? :)

@tristanjahier
Copy link
Author

I'm sorry that was not clear but I was already trying to do a fresh install with 0.13.1, because even if I've tried to install before 0.10, I have never been able to install it properly. In the end, I don't need an upgrade guide but an installation guide.

So if I understand correctly, the minimal setup does not require anything to be done on the app level? No composer package to require, only a PHP extension?

@labbati
Copy link
Member

labbati commented Feb 18, 2019

Hi, that is correct. You only have to install the PHP extension.

Please note that we test for 5.7 (not 5.3) so if you notice unexpected behaviors or any error please notify us and we will add integration tests for this version.

Let me know how it goes!

@tristanjahier
Copy link
Author

Thank you @labbati!

But if I need to do manual instrumentation, what is the proper way to integrate this package into Laravel (apart from requiring datadog/dd-trace)?

The official documentation says:

// Add the PHP tracer bootstrap
require '<APP_ROOT>/vendor/datadog/dd-trace/bridge/dd_init.php';

// Create the first span in the trace
\DDTrace\GlobalTracer::get()->startRootSpan('web.request');

but I feel like there must be a better way to integrate with a Laravel environment.

@labbati
Copy link
Member

labbati commented Feb 19, 2019

Hi @tristanjahier!

let's assume for a moment that you don't need to do manual instrumentation, then just installing the PHP extension (and adding nothing to composer) you already would have a bunch of things from Laravel without the snipped you wrote above. So first of all I would take a look at what you get, because a few things from Laravel (e.g. Pipelines) are already traced.

Now, if you want to do manual instrumentation is because you have specific method (either from laravel or from your own code) that you want to instrument. Please note, though, that the manual instrumentation that you do "adds to" and won't "replace" the spans created by the default auto-instrumentation. If you need to "replace" instead, this is a more advanced topic and deserves a separate thread.

How

If this is true you have two options:

  • depends on datadog/dd-trace in your composer
  • depends on opentracing/opentracing in your composer if you prefer to avoid lock-in into datadog code. This is your choice.

In either case, you are NOT doing require '<APP_ROOT>/vendor/datadog/dd-trace/bridge/dd_init.php'; (this is already done by auto-instrumentation).

Where

It depends. In general you have multiple options to add manual tracing.

For example you can create your own provider and register it before the other providers. Then in the boot() method do something like this:

dd_trace(`My\Class\Of\Interest`, `myMethodOfInterest`, function ($arg1, $arg2) {
    $tracer = \DDTrace\GlobalTracer::get();
    $scope = $tracer->startActiveSpan('curl_exec');
    $span = $scope->getSpan();

    $span->setTag(.....);

    // Within the callback $this is the object instance
    $this->myMethodOfInterest($arg1, $arg2);
    $scope->close();
    return $result;
});

The one above would be my recommended method. But keep in mind that the boot() method should be called before the methods that you want to trace are executed, otherwise it would be to late.

Alternatively, if you don't mind depending on datadog (or open tracing) in your code, you can do this directly in the method (but we don't recommend it)

namespace My\Class\Of;

class Interest
{
    public function myMethodOfInterest($arg1, $arg2)
    {
        $tracer = \DDTrace\GlobalTracer::get();
        $scope = $tracer->startActiveSpan('curl_exec');
        $span = $scope->getSpan();

        $span->setTag(.....);

        // origin implementation

        $scope->close();
        return $result;
    }
}

Does this address your doubts?

@tristanjahier
Copy link
Author

Wow thank you for this extensive and clear answer @labbati! I think you answered my questions entirely. 👍

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

No branches or pull requests

2 participants