Skip to content

Commit e5b2015

Browse files
committed
Log OTel init failures instead of silently swallowing them
Add LogExporterError() to exporter_interface.h (same pattern as LogNegativeValue) so otel_exporter.cc can log via elog(WARNING) without including postgres.h directly.
1 parent 3a6976e commit e5b2015

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/export/exporter_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class StatsExporter {
8181

8282
// Allows PG logging of exceptional cases without postgres.h
8383
void LogNegativeValue(const std::string& column_name, int64_t value);
84+
void LogExporterError(const char* context, const char* message);
8485

8586
// Expected usage:
8687
// void ProcessBatch(StatsExporter *exporter) {

src/export/otel_exporter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ bool OTelExporter::EstablishNewConnection() {
440440
logger = log_provider->GetLogger("pg_stat_ch", "pg_stat_ch_logs");
441441

442442
return true;
443-
} catch (const std::exception&) {
443+
} catch (const std::exception& e) {
444+
LogExporterError("OTel init failed", e.what());
444445
return false;
445446
}
446447
}

src/export/stats_exporter.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ void ExportEventStats(const std::vector<PschEvent>& events, StatsExporter* expor
207207

208208
} // namespace
209209

210+
void LogExporterError(const char* context, const char* message) {
211+
elog(WARNING, "pg_stat_ch: %s: %s", context, message);
212+
}
213+
210214
// Used to report negative values, which are not supported by OTel.
211215
void LogNegativeValue(const std::string& column_name, int64_t value) {
212216
static std::chrono::steady_clock::time_point last_log = {};

0 commit comments

Comments
 (0)