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

TracerProvider::forceFlush should be an API method? #911

Closed
brettmc opened this issue Jan 12, 2023 · 3 comments
Closed

TracerProvider::forceFlush should be an API method? #911

brettmc opened this issue Jan 12, 2023 · 3 comments
Assignees
Labels
question Further information is requested stale This issue didn't have recent activity

Comments

@brettmc
Copy link
Collaborator

brettmc commented Jan 12, 2023

Currently, TracerProvider::forceFlush is an SDK method, which matches the specification
We also document that instrumented code should only rely upon the API

But, if I am instrumenting an application based on react/swoole/roadrunner/etc where one process can serve many requests, I would like to be able to flush traces upon a condition such as request completion or timer. Traces would eventually be exported by a later request or shutdown, but that could be a long time depending on traffic.

$tracerProvider = \OpenTelemetry\API\Common\Instrumentation\Globals::tracerProvider(); // API tracerprovider, could be a no-op

while ($request = $worker->waitRequest()) {
    try {
        $response = $app->handle($request);
        $worker->respond($response);
    } catch (\Throwable $t) {
        $worker->getWorker()->error($t->getMessage());
    }
    // check interface to see if forceFlush is available
    if ($tracerProvider instanceof \OpenTelemetry\SDK\Trace\TracerProviderInterface) {
        $tracerProvider->forceFlush();
    }
}

In the above example, I need to check whether I have an SDK instance to know if I can force flush, thus breaking the "depend only on the API" directive...

@brettmc brettmc added bug Something isn't working question Further information is requested labels Jan 12, 2023
@Nevay
Copy link
Contributor

Nevay commented Jan 25, 2023

Related spec issue: open-telemetry/opentelemetry-specification#2944

I would like to be able to flush traces upon a condition such as request completion or timer.

React and Swoole applications should use a SpanProcessor that utilizes the underlying event loop to flush periodically after scheduledDelayNanos.
Roadrunner applications could use a non-blocking Relay or use a SpanProcessor that autoflushes on a specific condition, e.g. after every server span (open-telemetry/opentelemetry-specification#2944 (comment))

@bobstrecansky bobstrecansky self-assigned this Feb 8, 2023
@brettmc brettmc removed the bug Something isn't working label Mar 1, 2023
@stale
Copy link

stale bot commented Apr 3, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale This issue didn't have recent activity label Apr 3, 2023
@brettmc
Copy link
Collaborator Author

brettmc commented Apr 3, 2023

Closing this, I don't think the spec is going to change. As a future solution, I think that after GA release, we can look to implement better async capabilities into batch processors, based on some prior with from Nevay (which will likely require 8.1+, and a v2 release of the SDK)

@brettmc brettmc closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale This issue didn't have recent activity
Projects
None yet
Development

No branches or pull requests

3 participants