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

Shutdown not called properly #1382

Closed
brutto opened this issue Sep 20, 2024 · 1 comment
Closed

Shutdown not called properly #1382

brutto opened this issue Sep 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@brutto
Copy link

brutto commented Sep 20, 2024

I'lls try to use this library without global instances, so i ll use sdk helper like below (mostly for auto shutdown)

$spanExporter = new SpanExporter(
    (new StreamTransportFactory())->create('php://stdout', 'application/json')
);
$spanProcessor =  BatchSpanProcessor::builder($spanExporter)->build();
$tracerProvider = TracerProvider::builder()
    ->addSpanProcessor(
        $spanProcessor
    )
    ->setResource($resource)
    ->setSampler(new ParentBased(new AlwaysOnSampler()))
    ->build();

$sdk = Sdk::builder()
    ->setTracerProvider($tracerProvider)
    ->setAutoShutdown(true)
    ->build();

Then i use $tracerProvider in standart way

$spanContext = SpanContext::createFromRemoteParent($traceId, $spanId);

$tracer = $tracerProvider->getTracer('test-command');
$span1 = $tracer
    ->spanBuilder('execute1')
    ->addLink($spanContext)
    ->startSpan();

$span1->setStatus(StatusCode::STATUS_OK);

...

$scope = $span1->activate();
$span2 = $tracer
    ->spanBuilder('execute2')
    ->startSpan();

...

$span2->end();
$scope->detach();

$span1->end();

After script is normaly ended no any shutdown functions from providers are called.
But if i use sdk with this method

$sdk = Sdk::builder()
    ->setTracerProvider($tracerProvider)
    ->setAutoShutdown(true)
    ->buildAndRegisterGlobal();

At the end everything are called properly (shutdown method from providers are called).

Also simple register shutdown also called normally

register_shutdown_function([$tracerProvider, 'shutdown']);

Try to find whats the root problem and didnt catch it. =/

@brutto brutto added the bug Something isn't working label Sep 20, 2024
@brutto
Copy link
Author

brutto commented Sep 23, 2024

Resolved.
in my case try to register shutdown in Command::execute method (symfony/console package), but move it into Command::initialize method start register as expected.

@brutto brutto closed this as completed Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant