2020-10-22 16:47:20 +00:00
|
|
|
#include "OpenTelemetrySpanLog.h"
|
2020-08-20 20:59:40 +00:00
|
|
|
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
2020-09-30 16:16:33 +00:00
|
|
|
#include <DataTypes/DataTypeDateTime64.h>
|
2020-08-20 20:59:40 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2021-01-22 05:16:13 +00:00
|
|
|
#include <DataTypes/DataTypeMap.h>
|
2020-08-20 20:59:40 +00:00
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
2023-03-12 13:30:29 +00:00
|
|
|
#include <DataTypes/DataTypeEnum.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2020-08-20 20:59:40 +00:00
|
|
|
|
2023-03-06 14:53:58 +00:00
|
|
|
#include <base/hex.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
2022-07-04 15:52:06 +00:00
|
|
|
#include <Core/Field.h>
|
2021-05-04 22:42:14 +00:00
|
|
|
|
|
|
|
|
2020-08-20 20:59:40 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
NamesAndTypesList OpenTelemetrySpanLogElement::getNamesAndTypes()
|
2020-08-20 20:59:40 +00:00
|
|
|
{
|
2023-03-12 13:30:29 +00:00
|
|
|
auto span_kind_type = std::make_shared<DataTypeEnum8>(
|
|
|
|
DataTypeEnum8::Values
|
|
|
|
{
|
|
|
|
{"INTERNAL", static_cast<Int8>(OpenTelemetry::INTERNAL)},
|
|
|
|
{"SERVER", static_cast<Int8>(OpenTelemetry::SERVER)},
|
|
|
|
{"CLIENT", static_cast<Int8>(OpenTelemetry::CLIENT)},
|
|
|
|
{"PRODUCER", static_cast<Int8>(OpenTelemetry::PRODUCER)},
|
|
|
|
{"CONSUMER", static_cast<Int8>(OpenTelemetry::CONSUMER)}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-08-20 20:59:40 +00:00
|
|
|
return {
|
2021-06-28 11:42:21 +00:00
|
|
|
{"trace_id", std::make_shared<DataTypeUUID>()},
|
|
|
|
{"span_id", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"parent_span_id", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"operation_name", std::make_shared<DataTypeString>()},
|
2023-03-12 13:30:29 +00:00
|
|
|
{"kind", std::move(span_kind_type)},
|
2020-11-19 16:55:56 +00:00
|
|
|
// DateTime64 is really unwieldy -- there is no "normal" way to convert
|
|
|
|
// it to an UInt64 count of microseconds, except:
|
|
|
|
// 1) reinterpretAsUInt64(reinterpretAsFixedString(date)), which just
|
|
|
|
// doesn't look sane;
|
|
|
|
// 2) things like toUInt64(toDecimal64(date, 6) * 1000000) that are also
|
|
|
|
// excessively verbose -- why do I have to write scale '6' again, and
|
|
|
|
// write out 6 zeros? -- and also don't work because of overflow.
|
|
|
|
// Also subtraction of two DateTime64 points doesn't work, so you can't
|
|
|
|
// get duration.
|
|
|
|
// It is much less hassle to just use UInt64 of microseconds.
|
2021-06-28 11:42:21 +00:00
|
|
|
{"start_time_us", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"finish_time_us", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"finish_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"attribute", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>())},
|
2020-08-20 20:59:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
NamesAndAliases OpenTelemetrySpanLogElement::getNamesAndAliases()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{"attribute.names", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "mapKeys(attribute)"},
|
2022-05-16 22:28:36 +00:00
|
|
|
{"attribute.values", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "mapValues(attribute)"}
|
2021-06-28 11:42:21 +00:00
|
|
|
};
|
|
|
|
}
|
2020-11-19 15:52:11 +00:00
|
|
|
|
2020-08-20 20:59:40 +00:00
|
|
|
void OpenTelemetrySpanLogElement::appendToBlock(MutableColumns & columns) const
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
2021-05-04 22:42:14 +00:00
|
|
|
columns[i++]->insert(trace_id);
|
2020-08-20 20:59:40 +00:00
|
|
|
columns[i++]->insert(span_id);
|
|
|
|
columns[i++]->insert(parent_span_id);
|
|
|
|
columns[i++]->insert(operation_name);
|
2023-03-12 13:30:29 +00:00
|
|
|
columns[i++]->insert(kind);
|
2020-09-30 16:16:33 +00:00
|
|
|
columns[i++]->insert(start_time_us);
|
|
|
|
columns[i++]->insert(finish_time_us);
|
2020-04-17 13:26:44 +00:00
|
|
|
columns[i++]->insert(DateLUT::instance().toDayNum(finish_time_us / 1000000).toUnderType());
|
2020-11-10 05:50:32 +00:00
|
|
|
// The user might add some ints values, and we will have Int Field, and the
|
|
|
|
// insert will fail because the column requires Strings. Convert the fields
|
|
|
|
// here, because it's hard to remember to convert them in all other places.
|
2022-07-04 14:07:29 +00:00
|
|
|
columns[i++]->insert(attributes);
|
2020-08-20 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|