Skip to content

Commit

Permalink
cmk-ui-job-scheduler: remove potential timeout
Browse files Browse the repository at this point in the history
Calling any function decorated with `@tracer.start_as_current_span` will
cause `opentelemetry/sdk/trace/export/__init__.py::shutdown` to timeout
in the parent process. This only happens if tracing is active.

Thus, calling `trace.init_tracing` before `daemonize` is unsafe.

Below a minimal example:

```python
import os
from pathlib import Path

from cmk.ccc.daemon import daemonize
from cmk.ccc.site import get_omd_config, omd_site, resource_attributes_from_config

from cmk import trace
from cmk.trace.export import exporter_from_config, init_span_processor
from cmk.trace.logs import add_span_log_handler

tracer = trace.get_tracer()

def main() -> None:
    omd_root = Path(os.environ.get("OMD_ROOT", ""))
    init_span_processor(
        trace.init_tracing(
            service_namespace="",
            service_name="example-service",
            service_instance_id=omd_site(),
            extra_resource_attributes=resource_attributes_from_config(omd_root),
        ),
        exporter_from_config(trace.trace_send_config(get_omd_config(omd_root))),
    )
    add_span_log_handler()

    testme()
    print("testme is done")
    daemonize()

@tracer.start_as_current_span("example")
def testme() -> None:
    pass
```

Change-Id: I93f2d5b7542907a88180e4933fa3d71beb800711
(cherry picked from commit bf6e3f7)
  • Loading branch information
SoloJacobs committed Jan 22, 2025
1 parent 4e9a967 commit e6b491c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmk/gui/job_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def main(crash_report_callback: Callable[[Exception], str]) -> int:
omd_root = Path(os.environ.get("OMD_ROOT", ""))

_setup_console_logging()

daemonize()

init_span_processor(
trace.init_tracing(
service_namespace="",
Expand All @@ -75,8 +78,6 @@ def main(crash_report_callback: Callable[[Exception], str]) -> int:
)
add_span_log_handler()

daemonize()

# The import and load_pugins take a few seconds and we don't want to delay the
# pre-daemonize phase with this, because it also slows down "omd start" significantly.
from cmk.gui import main_modules
Expand Down

0 comments on commit e6b491c

Please sign in to comment.