Skip to content

Commit

Permalink
HPCC-30470 Change1
Browse files Browse the repository at this point in the history
- Adds jlog option to helm schema
- Add concept of jlog level

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Nov 29, 2023
1 parent 4e7846d commit abb9f7b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 29 deletions.
2 changes: 1 addition & 1 deletion helm/hpcc/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["OTLP-HTTP", "OTLP-GRCP", "OS", "NONE"],
"enum": ["OTLP-HTTP", "OTLP-GRCP", "OS", "JLog", "NONE"],
"description": "The type of exporter in charge of forwarding span data to target back-end"
}
}
Expand Down
123 changes: 95 additions & 28 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,53 @@ const char * spanKindToString(opentelemetry::trace::SpanKind spanKind)
}
}

enum JLogExportLevel
{
JLogExportLevelNone = 0,
JLogExportLevelMin = 1,
JLogExportLevelDefault = 2,
JLogExportLevelMax = 3
};

class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
{
private:
JLogExportLevel logLevel = JLogExportLevelDefault;
public:

inline JLogExportLevel jlogLevelFromStr(char const * str)
{
if (!isEmptyString(str))
{
if(strnicmp(str, "NONE", 4)==0)
return JLogExportLevelNone;
if(strnicmp(str, "MIN", 3)==0)
return JLogExportLevelMin;
if(strnicmp(str, "DEFAULT", 7)==0)
return JLogExportLevelDefault;
if(strnicmp(str, "MAX", 3)==0)
return JLogExportLevelMax;
}

return JLogExportLevelDefault;
}
JLogSpanExporter() {}

JLogSpanExporter(const char * logLevel)
{
setLogLevel(jlogLevelFromStr(logLevel));
}

JLogSpanExporter(JLogExportLevel logLevel)
{
setLogLevel(logLevel);
}

void setLogLevel(JLogExportLevel level)
{
logLevel = level;
}

/**
* @return Returns a unique pointer to an empty recordable object
*/
Expand Down Expand Up @@ -178,34 +220,43 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
span->GetSpanId().ToLowerBase16(span_id);
span->GetParentSpanId().ToLowerBase16(parent_span_id);

sout << "{"
<< " \"Name\": \"" << span->GetName() << "\","
<< " \"TraceId\": \"" << std::string(trace_id, 32) << "\","
<< " \"SpanId\": \"" << std::string(span_id, 16) << "\","
<< " \"kind\": \"" << spanKindToString(span->GetSpanKind()) << "\","
<< " \"ParentSpanId\": \"" << std::string(parent_span_id, 16) << "\","
<< " \"Start\": " << span->GetStartTime().time_since_epoch().count() << ","
<< " \"Duration\": " << span->GetDuration().count() << ","
<< " \"Description\": \"" << span->GetDescription() << "\","
<< " \"Status\": \"" << statusMap[int(span->GetStatus())] << "\","
<< " \"TraceState\": \"" << span->GetSpanContext().trace_state()->ToHeader() << "\","
<< " \"Attributes\": ";
printAttributes(span->GetAttributes());
sout << ",";
sout << " \"Events\": ";
printEvents(span->GetEvents());
sout << ",";
sout << " \"Links\": ";
printLinks(span->GetLinks());
sout << ",";
sout << " \"Resources\": ";
printResources(span->GetResource());
sout << ",";
sout << " \"InstrumentedLibrary\": \"";
printInstrumentationScope(span->GetInstrumentationScope());
sout << "\" }";
sout << "{"
<< " \"Name\": \"" << span->GetName() << "\","
<< " \"TraceId\": \"" << std::string(trace_id, 32) << "\","
<< " \"SpanId\": \"" << std::string(span_id, 16) << "\","
<< " \"kind\": \"" << spanKindToString(span->GetSpanKind()) << "\","
<< " \"ParentSpanId\": \"" << std::string(parent_span_id, 16) << "\","
<< " \"Start\": " << span->GetStartTime().time_since_epoch().count() << ","
<< " \"Duration\": " << span->GetDuration().count() << ","
<< " \"Attributes\": ";
printAttributes(span->GetAttributes());

if ( logLevel > JLogExportLevelMin)
{
sout << ","
<< " \"Description\": \"" << span->GetDescription() << "\","
<< " \"Status\": \"" << statusMap[int(span->GetStatus())] << "\","
<< " \"TraceState\": \"" << span->GetSpanContext().trace_state()->ToHeader() << "\"";
}

if ( logLevel > JLogExportLevelDefault)
{
sout << ", \"Events\": ";
printEvents(span->GetEvents());
sout << ",";
sout << " \"Links\": ";
printLinks(span->GetLinks());
sout << ",";
sout << " \"Resources\": ";
printResources(span->GetResource());
sout << ",";
sout << " \"InstrumentedLibrary\": \"";
printInstrumentationScope(span->GetInstrumentationScope());
sout << "\"";
}
sout << " }";
}
LOG(MCoperatorTrace, "TraceSpan '%s': %s", span->GetName().data() , sout.str().c_str());
LOG(MCmonitorEvent, "%s",sout.str().c_str());
sout.str("");
sout.clear();
}
Expand Down Expand Up @@ -329,13 +380,19 @@ class JLogSpanExporterFactory
{
public:
/**
* Create a NoopSpanExporter.
* Create a JLogSpanExporter.
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create()
{
return std::unique_ptr<opentelemetry::sdk::trace::SpanExporter>(
new JLogSpanExporter());
}

static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(const char * logLevel)
{
return std::unique_ptr<opentelemetry::sdk::trace::SpanExporter>(
new JLogSpanExporter(logLevel));
}
};

class CHPCCHttpTextMapCarrier : public opentelemetry::context::propagation::TextMapCarrier
Expand Down Expand Up @@ -1110,6 +1167,16 @@ void CTraceManager::initTracerProviderAndGlobalInternals(const IPropertyTree * t
exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
DBGLOG("Exporting traces via OTLP/GRPC to: (%s)", opts.endpoint.c_str());
}
else if (stricmp(exportType.str(), "JLog")==0)
{
StringBuffer logLevel;
if (exportConfig->hasProp("@logLevel"))
exportConfig->getProp("@logLevel", logLevel);

exporter = JLogSpanExporterFactory::Create(logLevel.str());

DBGLOG("Exporting traces via JLOG: Log Level(%s)", logLevel.str());
}
else if (stricmp(exportType.str(), "Prometheus")==0)
DBGLOG("Tracing to Prometheus currently not supported");
else if (stricmp(exportType.str(), "NONE")==0)
Expand Down

0 comments on commit abb9f7b

Please sign in to comment.