Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Expose rootSpanId for ability to set it as parentSpanId #199

Open
iamacarpet opened this issue Sep 3, 2018 · 1 comment
Open

Expose rootSpanId for ability to set it as parentSpanId #199

iamacarpet opened this issue Sep 3, 2018 · 1 comment

Comments

@iamacarpet
Copy link

Is it possible to expose the rootSpan->spanId() from OpenCensus\Trace\RequestHandler?

Currently it is private private $rootSpan; and I can't see any methods that expose it.

I'm adding tracing for Laravel to our shared library, to run on App Engine Standard (PHP 7.2).

The examples provided creates a service provider which uses the LARAVEL_START constant set at the top of public/index.php to create a span with the startTime backdated to when the application started.

<?php

namespace A1comms\GaeSupportLaravel\Trace;

use OpenCensus\Trace\Tracer;
use Illuminate\Support\ServiceProvider;

class TraceServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if ((!is_gae()) || (php_sapi_name() == 'cli')) {
            return;
        }

        // Create a span that starts from when Laravel first boots (public/index.php)
        Tracer::inSpan(['name' => 'laravel/bootstrap', 'startTime' => LARAVEL_START], function () {});
    }
}

At the moment, this is firing after some other trace events have already taken place, so the tree looks a little bit weird (see screenshow below).

screenshot 1535969804

I'd ideally like to be able to pass rootSpan->spanId() into that spans options as parentSpanId, which should fix the formatting.

@iamacarpet
Copy link
Author

Looking around at this a little more, I wanted to check that even if the parentSpanId is passed through, it would be applied.

Does this imply that it won't be?

As if there is a parent as detected internally by the extension, it'll always prefer that to anything in the span options?

https://github.com/census-instrumentation/opencensus-php/blob/master/ext/opencensus_trace_span.c#L640

I saw in some code comments that setting "parentSpanId" to null in the span options would make it default to the rootSpan->spanId(), but this didn't work either :(.

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

No branches or pull requests

1 participant