Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-31026 JTrace Coverity issues fix #18155

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "jmisc.hpp"
#include "jtrace.hpp"
#include "lnuid.h"
#include <variant>

namespace context = opentelemetry::context;
namespace nostd = opentelemetry::nostd;
Expand Down Expand Up @@ -275,27 +276,35 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
if (map.size() == 0)
return;

out.appendf(", \"%s\": {", attsContainerName);

bool first = true;
for (const auto &kv : map)
try
{
if (!first)
out.append(",");
else
first = false;
out.appendf(", \"%s\": {", attsContainerName);

std::ostringstream attsOS; //used to exploit OTel convenience functions for printing attribute values
opentelemetry::exporter::ostream_common::print_value(kv.second, attsOS);
std::string val = attsOS.str();
if (val.size() > 0)
bool first = true;
for (const auto &kv : map)
{
StringBuffer encoded;
encodeJSON(encoded, val.c_str());
out.appendf("\"%s\": \"%s\"", kv.first.c_str(), encoded.str());
if (!first)
out.append(",");
else
first = false;

std::ostringstream attsOS; //used to exploit OTel convenience functions for printing attribute values
opentelemetry::exporter::ostream_common::print_value(kv.second, attsOS);
std::string val = attsOS.str();
if (val.size() > 0)
{
StringBuffer encoded;
encodeJSON(encoded, val.c_str());
out.appendf("\"%s\": \"%s\"", kv.first.c_str(), encoded.str());
}
}
out.append(" }");

}
catch(const std::bad_variant_access & e)
{
ERRLOG("Could not export span %s: %s", attsContainerName, e.what());
}
out.append(" }");
}

static void printEvents(StringBuffer & out, const std::vector<opentelemetry::sdk::trace::SpanDataEvent> &events)
Expand Down Expand Up @@ -352,18 +361,16 @@ class JLogSpanExporter final : public opentelemetry::sdk::trace::SpanExporter

static void printResources(StringBuffer & out, const opentelemetry::sdk::resource::Resource &resources)
{
auto attributes = resources.GetAttributes();
if (attributes.size())
printAttributes(out, attributes, "resources");
if (resources.GetAttributes().size())
printAttributes(out, resources.GetAttributes(), "resources");
}

static void printInstrumentationScope(StringBuffer & out,
const opentelemetry::sdk::instrumentationscope::InstrumentationScope &instrumentation_scope)
{
out.appendf(", \"instrumented_library\": \"%s\"", instrumentation_scope.GetName().c_str());
auto version = instrumentation_scope.GetVersion();
if (version.size())
out.appendf("-").append(version.c_str());
if (instrumentation_scope.GetVersion().size())
out.appendf("-").append(instrumentation_scope.GetVersion().c_str());
}

private:
Expand Down
Loading