opa icon indicating copy to clipboard operation
opa copied to clipboard

Failed to shutdown OpenTelemetry trace exporter gracefully.

Open nicolaschotard opened this issue 1 year ago • 5 comments

Short description

When running OPA with the distributed tracing option enabled, we get the following error when the server is stopped.

Failed to shutdown `OpenTelemetry` trace exporter gracefully.

Steps To Reproduce

  1. Get the latest version of opa (I've tried with version 0.62 and the latest version)
./opa_linux_amd64 version
Version: 0.63.0-dev
Build Commit: d3a4a87f506dec744ed93177c37bea5e2afa186b
Build Timestamp: 2024-03-27T19:08:00Z
Build Hostname: nico-Latitude-7420
Go Version: go1.21.0
Platform: linux/amd64
WebAssembly: available
  1. Run the following command line
./opa_linux_amd64 run --server --set distributed_tracing.type=grpc
  1. Kill the process (Ctrl + C works fine)
  2. The full output should looks like that
./opa_linux_amd64 run --server --set distributed_tracing.type=grpc
{"addrs":[":8181"],"diagnostic-addrs":[],"level":"info","msg":"Initializing server. OPA is running on a public (0.0.0.0) network interface. Unless you intend to expose OPA outside of the host, binding to the localhost interface (--addr localhost:8181) is recommended. See https://www.openpolicyagent.org/docs/latest/security/#interface-binding","time":"2024-03-28T09:18:37+01:00"}
^C{"level":"info","msg":"Shutting down...","time":"2024-03-28T09:18:38+01:00"}
{"level":"info","msg":"Server shutdown.","time":"2024-03-28T09:18:38+01:00"}
{"err":"context canceled","level":"error","msg":"Failed to shutdown OpenTelemetry trace exporter gracefully.","time":"2024-03-28T09:18:38+01:00"}

Expected behavior

The OpenTelemetry trace exporter should be gracefully shut down, and no error should be seen.

Additional context

We have seen this error appeared after upgrading OPA from version 0.59 to 0.62.

nicolaschotard avatar Mar 28 '24 08:03 nicolaschotard

Thanks for bringing this up. I think it's not wired up correctly: This

https://github.com/open-policy-agent/opa/blob/d3a4a87f506dec744ed93177c37bea5e2afa186b/runtime/runtime.go#L538-L543

should happen in the shutdown code path, maybe here https://github.com/open-policy-agent/opa/blob/d3a4a87f506dec744ed93177c37bea5e2afa186b/runtime/runtime.go#L845-L861 or here https://github.com/open-policy-agent/opa/blob/d3a4a87f506dec744ed93177c37bea5e2afa186b/server/server.go#L225-L249

srenatus avatar Mar 28 '24 09:03 srenatus

@nicolaschotard if you'd like to submit a fix based on Stephan's feedback feel free to do so. We're happy to help out. Thanks for reporting this.

ashutosh-narkar avatar Mar 28 '24 17:03 ashutosh-narkar

Hey thank you both for your quick answers. And indeed, moving the rt.traceExporter.Shutdown(ctx) part into the gracefulServerShutdown function seems to fix this issue. I will submit a PR with a fix as soon as I get the time to work on that.

nicolaschotard avatar Apr 02 '24 08:04 nicolaschotard

And I believe this commit introduced the bug.

nicolaschotard avatar Apr 03 '24 14:04 nicolaschotard

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar May 03 '24 20:05 stale[bot]