Skip to content

Commit

Permalink
HPCC-32927 Add a debugging option to allow slow exporters to be tested
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Nov 1, 2024
1 parent 50635e7 commit 5f49e5c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
debugDelay = config->getPropInt("debug/@delay", 0); // An option to allow this exporter to model slow behaviour
}
}

/**
* @return Returns a unique pointer to an empty recordable object
Expand Down Expand Up @@ -255,6 +262,11 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
LOG(MCmonitorEvent, "%s",out.str());
}
}
if (debugDelay)
{
LOG(MCdebugInfo, "Delaying for %dms after exporting %u items", debugDelay, (unsigned)recordables.size());
MilliSleep(debugDelay);
}
return opentelemetry::sdk::common::ExportResult::kSuccess;
}
catch (IException * e)
Expand Down Expand Up @@ -416,6 +428,7 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
private:
SpanLogFlags logFlags = SpanLogFlags::LogNone;
std::atomic_bool shutDown;
unsigned debugDelay = 0;
};

/*#ifdef _USE_CPPUNIT
Expand All @@ -436,10 +449,10 @@ class JLogSpanExporterFactory
/**
* Create a JLogSpanExporter.
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(SpanLogFlags logFlags)
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(SpanLogFlags logFlags, const IPropertyTree * config)
{
return std::unique_ptr<opentelemetry::sdk::trace::SpanExporter>(
new JLogSpanExporter(logFlags));
new JLogSpanExporter(logFlags, config));
}
};

Expand Down Expand Up @@ -1280,9 +1293,10 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> 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());
Expand Down Expand Up @@ -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<opentelemetry::sdk::trace::SpanExporter> exporter = JLogSpanExporterFactory::Create(DEFAULT_SPAN_LOG_FLAGS);
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter = JLogSpanExporterFactory::Create(DEFAULT_SPAN_LOG_FLAGS, nullptr);
processors.push_back(opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter)));
}

Expand Down

0 comments on commit 5f49e5c

Please sign in to comment.