Skip to content

Commit

Permalink
Merge pull request #19258 from ghalliday/issue32927
Browse files Browse the repository at this point in the history
HPCC-32927 Add a debugging option to allow slow exporters to be tested

Reviewed-By: Rodrigo Pastrana <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Nov 4, 2024
2 parents 0e602df + 87a880e commit 2c60f61
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)
{
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
Expand Down Expand Up @@ -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)
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 debugDelayMs = 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 2c60f61

Please sign in to comment.