Skip to content

Commit

Permalink
Enable tracing only if a tracing context is provided
Browse files Browse the repository at this point in the history
Would be nice if we could enable tracing in all cases. But the current timeout and retry
logic of the Opentelemetry SDK does not work as intended, which can lead to longer hanging
executions in case the configured collector (e.g. Jaeger) is not reachable.

For now only enable tracing in case the caller provides a tracing context. This way we produce
traces only when the caller is interested in them.

This condition can be removed once the timeout and retry logic was fixed
(open-telemetry/opentelemetry-python#4043).

Change-Id: Id9ce70cf3232a5e1bbe9497e8c30a568ac693b78
  • Loading branch information
LarsMichelsen committed Oct 6, 2024
1 parent e711622 commit 9e80088
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions bin/check_mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ cmk.base.utils.register_sigint_handler()

help_function = modes.get("help").handler_function


init_span_processor(
trace.init_tracing(omd_site(), "cmk"),
exporter_from_config(trace.trace_send_config(get_omd_config(cmk.utils.paths.omd_root))),
)
# Would be nice if we could enable tracing in all cases. But the current timeout and retry
# logic of the Opentelemetry SDK does not work as intended, which can lead to longer hanging
# executions in case the configured collector (e.g. Jaeger) is not reachable.
# For now only enable tracing in case the caller provides a tracing context. This way we produce
# traces only when the caller is interested in them.
# This condition can be removed once the timeout and retry logic was fixed
# (https://github.com/open-telemetry/opentelemetry-python/issues/4043).
if trace_context := trace.extract_context_from_environment(dict(os.environ)):
init_span_processor(
trace.init_tracing(omd_site(), "cmk"),
exporter_from_config(trace.trace_send_config(get_omd_config(cmk.utils.paths.omd_root))),
)


# We probably don't really need to register that here, do we?
Expand Down Expand Up @@ -127,8 +134,6 @@ try:
if mode_name not in modes.non_config_options():
config.load()

trace_context = trace.extract_context_from_environment(dict(os.environ))

done, exit_status = False, 0
if mode_name is not None and mode_args is not None:
exit_status = modes.call(mode_name, mode_args, opts, args, trace_context)
Expand Down

0 comments on commit 9e80088

Please sign in to comment.