Skip to content

Commit

Permalink
HPCC-32131 Code review 1
Browse files Browse the repository at this point in the history
- Reenabled commented out logic
- Establishes default batch mode based on exporter type
- Removes useful debug log

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Jun 25, 2024
1 parent d474e06 commit bcddee9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class CTraceManager : implements ITraceManager, public CInterface
void initTracerProviderAndGlobalInternals(const IPropertyTree * traceConfig);
void initTracer(const IPropertyTree * traceConfig);
void cleanupTracer();
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> createExporter(const IPropertyTree * exportConfig);
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> createExporter(const IPropertyTree * exportConfig, bool & shouldBatch);
std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor> createProcessor(const IPropertyTree * exportConfig);

public:
Expand Down Expand Up @@ -1159,7 +1159,7 @@ IProperties * getSpanContext(const ISpan * span)

//---------------------------------------------------------------------------------------------------------------------

std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> CTraceManager::createExporter(const IPropertyTree * exportConfig)
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> CTraceManager::createExporter(const IPropertyTree * exportConfig, bool & shouldBatch)
{
assertex(exportConfig);

Expand All @@ -1172,6 +1172,7 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> CTraceManager::createEx
if (stricmp(exportType.str(), "OS")==0) //To stdout/err
{
LOG(MCoperatorInfo, "Tracing exporter set OS");
shouldBatch = false;
return opentelemetry::exporter::trace::OStreamSpanExporterFactory::Create();
}
else if (stricmp(exportType.str(), "OTLP")==0 || stricmp(exportType.str(), "OTLP-HTTP")==0)
Expand Down Expand Up @@ -1255,6 +1256,7 @@ 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);
}
Expand All @@ -1268,10 +1270,11 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> CTraceManager::createEx

std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor> CTraceManager::createProcessor(const IPropertyTree * exportConfig)
{
bool batchDefault = true;
std::unique_ptr<opentelemetry::v1::sdk::trace::SpanExporter> exporter;
try
{
exporter = createExporter(exportConfig);
exporter = createExporter(exportConfig, batchDefault);
}
catch(const std::exception& e) //polymorphic type std::exception
{
Expand All @@ -1285,7 +1288,11 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor> CTraceManager::createP
if (!exporter)
return nullptr;

if (exportConfig->getPropBool("batch/@enabled", true))
if ( dynamic_cast<opentelemetry::exporter::trace::OStreamSpanExporterFactory * >(exporter.get()) != nullptr ||
dynamic_cast<JLogSpanExporterFactory * >(exporter.get()) != nullptr)
batchDefault = false;

if (exportConfig->getPropBool("batch/@enabled", batchDefault))
{
//Groups several spans together, before sending them to an exporter.
opentelemetry::v1::sdk::trace::BatchSpanProcessorOptions options;
Expand All @@ -1304,7 +1311,6 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor> CTraceManager::createP
*/
options.max_export_batch_size = exportConfig->getPropInt("batch/@maxExportBatchSize", 512);

DBGLOG("Tracing exporter set to batch mode");
return opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(std::move(exporter), options);
}

Expand Down Expand Up @@ -1333,12 +1339,12 @@ void CTraceManager::initTracerProviderAndGlobalInternals(const IPropertyTree * t
enableDefaultLogExporter = traceConfig->getPropBool("enableDefaultLogExporter", enableDefaultLogExporter);
}

//if (enableDefaultLogExporter)
//{
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);
// processors.push_back(opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter)));
//}
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter = JLogSpanExporterFactory::Create(DEFAULT_SPAN_LOG_FLAGS);
processors.push_back(opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter)));
}

opentelemetry::sdk::resource::ResourceAttributes resourceAtts =
{
Expand Down

0 comments on commit bcddee9

Please sign in to comment.