From 87a880e5c00d17161ad65819b74e19a817ccd866 Mon Sep 17 00:00:00 2001 From: Gavin Halliday Date: Fri, 1 Nov 2024 13:36:17 +0000 Subject: [PATCH] HPCC-32927 Add a debugging option to allow slow exporters to be tested Signed-off-by: Gavin Halliday --- system/jlib/jtrace.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/system/jlib/jtrace.cpp b/system/jlib/jtrace.cpp index 69c4f2d0baf..b126fd04fd6 100644 --- a/system/jlib/jtrace.cpp +++ b/system/jlib/jtrace.cpp @@ -165,7 +165,14 @@ static const char * spanKindToString(opentelemetry::trace::SpanKind spanKind) class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter { public: - JLogSpanExporter(SpanLogFlags spanLogFlags) : logFlags(spanLogFlags), shutDown(false) {} + JLogSpanExporter(SpanLogFlags spanLogFlags, const IPropertyTree * config) : + logFlags(spanLogFlags), shutDown(false) + { + if (config) + { + debugDelayMs = config->getPropInt("debug/@delayMs", 0); // An option to allow this exporter to model slow behaviour + } + } /** * @return Returns a unique pointer to an empty recordable object @@ -255,6 +262,11 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter LOG(MCmonitorEvent, "%s",out.str()); } } + if (debugDelayMs) + { + LOG(MCdebugInfo, "Delaying for %dms after exporting %u items", debugDelayMs, (unsigned)recordables.size()); + MilliSleep(debugDelayMs); + } return opentelemetry::sdk::common::ExportResult::kSuccess; } catch (IException * e) @@ -416,6 +428,7 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter private: SpanLogFlags logFlags = SpanLogFlags::LogNone; std::atomic_bool shutDown; + unsigned debugDelayMs = 0; }; /*#ifdef _USE_CPPUNIT @@ -436,10 +449,10 @@ class JLogSpanExporterFactory /** * Create a JLogSpanExporter. */ - static std::unique_ptr Create(SpanLogFlags logFlags) + static std::unique_ptr Create(SpanLogFlags logFlags, const IPropertyTree * config) { return std::unique_ptr( - new JLogSpanExporter(logFlags)); + new JLogSpanExporter(logFlags, config)); } }; @@ -1280,9 +1293,10 @@ std::unique_ptr CTraceManager::createEx if (logFlags == SpanLogFlags::LogNone) logFlags = DEFAULT_SPAN_LOG_FLAGS; + shouldBatch = false; LOG(MCoperatorInfo, "Tracing exporter set to JLog: logFlags( LogAttributes LogParentInfo %s)", logFlagsStr.str()); - return JLogSpanExporterFactory::Create(logFlags); + return JLogSpanExporterFactory::Create(logFlags, exportConfig); } else LOG(MCoperatorWarning, "Tracing exporter type not supported: '%s'", exportType.str()); @@ -1362,7 +1376,7 @@ void CTraceManager::initTracerProviderAndGlobalInternals(const IPropertyTree * t if (enableDefaultLogExporter) { //Simple option to create logging to the log file - primarily to aid developers. - std::unique_ptr exporter = JLogSpanExporterFactory::Create(DEFAULT_SPAN_LOG_FLAGS); + std::unique_ptr exporter = JLogSpanExporterFactory::Create(DEFAULT_SPAN_LOG_FLAGS, nullptr); processors.push_back(opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter))); }