Skip to content

Comments

Add OpenTelemetry lib and metric-interfaces#588

Open
maladetska wants to merge 3 commits intoydb-platform:mainfrom
maladetska:METRICS-0
Open

Add OpenTelemetry lib and metric-interfaces#588
maladetska wants to merge 3 commits intoydb-platform:mainfrom
maladetska:METRICS-0

Conversation

@maladetska
Copy link

No description provided.

Comment on lines +7 to +20
void ParseEndpoint(const std::string& endpoint, std::string& host, int& port) {
auto pos = endpoint.find(':');
if (pos != std::string::npos) {
host = endpoint.substr(0, pos);
try {
port = std::stoi(endpoint.substr(pos + 1));
} catch (...) {
port = 2135;
}
} else {
host = endpoint;
port = 2135;
}
}
Copy link
Author

@maladetska maladetska Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это плохо, пока черновой вариант такой

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

может быть, на файлы разбить?

@github-actions
Copy link
Contributor

🌋 SLO Test Results

Status: 🟢 2 workloads tested • All passed

Workload Metrics Regressions Improvements Links
🟢 table-gcc 8 1 0 ReportCheck
🚀 table-clang 8 0 1 ReportCheck

Generated by ydb-slo-action

@maladetska maladetska changed the title init? Add OpenTelemetry lib Feb 24, 2026
Comment on lines +16 to +19
find_package(opentelemetry-cpp QUIET)
if (opentelemetry-cpp_FOUND)
set(YDB_SDK_HAS_OPEN_TELEMETRY ON)
endif()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opentelemetry -- опциональная зависимость

add_subdirectory(util)

if (YDB_SDK_HAS_OPEN_TELEMETRY)
add_subdirectory(open_telemetry EXCLUDE_FROM_ALL)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не будет собираться если на него не сошлются

@maladetska maladetska changed the title Add OpenTelemetry lib Add OpenTelemetry lib and metric-interfaces Feb 24, 2026
Copy link
Collaborator

@Gazizonoki Gazizonoki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется папка open_telemetry в корне не самая удобная штука. Это же плагин к sdk, может сделаем папку plugins(extensions или еще какое-то имя) и туда положим все такие штуки (экспортеры метрик, трейсов, логов для конкретных систем и т. д.)?

И с метриками, оно вообще используется по коду? SDK уже собирает много метрик, в задаче с метриками это и есть главная сложность, как аккуратно перевести все на общий интерфейс и выкинуть library/cpp/monlib уже к черту из внешнего репозитория (это так-то внутренняя штука, вылезла в open-source ydb-cpp-sdk из-за неаккуратности)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как-то намешано все тут. И про метрики, и про спаны

virtual std::shared_ptr<ITracer> GetTracer(const std::string& name) = 0;
};

class IMetricsApi : public IExtensionApi {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IExtensionApi - большое зло. Не очень удачное решение, которое плотно так засело в SDK. Давайте закопаем его. Мне кажется, пользователю будет гораздо удобнее, если экспортер метрик и трейсов будут прям в TDriverConfig задаваться.

Типа

NYdb::TDriver driver(TDriverConfig("grpc://localhost:2136/local")
    .SetMetricExporter(CreateOtelMetricExporter(...))
    .SetTraceExporter(CreateOtelTraceExporter(...))
);
...

Лаконично и понятно пользователю.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А может разделим? Тащить и метрики и трейсы сразу как-то странно, все же разные сущности. Вдруг трейсы пользователю не нужны?


TOtelMetricRegistry::TOtelMetricRegistry(nostd::shared_ptr<metrics::MeterProvider> meterProvider)
: MeterProvider_(std::move(meterProvider))
, Meter_(MeterProvider_->GetMeter("ydb-cpp-sdk", "1.0.0"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему 1.0.0? У ydb-cpp-sdk есть версия, в SLO тестах даже проставляем на meter: https://github.com/ydb-platform/ydb-cpp-sdk/blob/main/tests/slo_workloads/utils/metrics.cpp#L53

return std::make_shared<TOtelUpDownCounterGauge>(std::move(counter), labels);
}

std::shared_ptr<IHistogram> TOtelMetricRegistry::Histogram(const std::string& name, const std::vector<double>& buckets, const TLabels& labels) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buckets потеряли

} // namespace

TQuerySpan::TQuerySpan(std::shared_ptr<NMetrics::ITracer> tracer, const std::string& operationName, const std::string& endpoint) {
if (!tracer) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!tracer) return;
if (!tracer) {
return;
}


TQuerySpan::~TQuerySpan() {
if (Span_) {
Span_->End();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это же поход по сети? А если ошибка, то исключение вылетит?


void ReplyError(TStatus status) override {
TSession session;
if (Span) Span->End(status.GetStatus());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Span) Span->End(status.GetStatus());
if (Span) {
Span->End(status.GetStatus());
}

)
);

if (Span) Span->End(EStatus::SUCCESS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

{
promise.SetValue(future.ExtractValue());
auto val = future.ExtractValue();
if (span) span->End(val.GetStatus());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants