diff --git a/include/xrpl/telemetry/Telemetry.h b/include/xrpl/telemetry/Telemetry.h index b237f4a621..c6febd5f84 100644 --- a/include/xrpl/telemetry/Telemetry.h +++ b/include/xrpl/telemetry/Telemetry.h @@ -108,6 +108,23 @@ public: virtual ~Telemetry() = default; + /** Update the service instance ID (OTel resource attribute + `service.instance.id`). + + Must be called before start(). The node public key is not available + when Telemetry is constructed (during the ApplicationImp member + initializer list), so this setter allows Application::setup() to + inject the identity once nodeIdentity_ is known. + + @param id The node's base58-encoded public key or custom identifier. + */ + virtual void + setServiceInstanceId(std::string const& id) + { + // Default no-op for NullTelemetry implementations. + (void)id; + } + /** Initialize the tracing pipeline (exporter, processor, provider). Call after construction. */ diff --git a/src/libxrpl/telemetry/Telemetry.cpp b/src/libxrpl/telemetry/Telemetry.cpp index f2d6fa39ed..53b7f91655 100644 --- a/src/libxrpl/telemetry/Telemetry.cpp +++ b/src/libxrpl/telemetry/Telemetry.cpp @@ -122,8 +122,11 @@ public: */ class TelemetryImpl : public Telemetry { - /** Configuration from the [telemetry] config section. */ - Setup const setup_; + /** Configuration from the [telemetry] config section. + Non-const so setServiceInstanceId() can update the instance ID + before start() creates the OTel resource. + */ + Setup setup_; /** Journal used for log output during start/stop. */ beast::Journal const journal_; @@ -140,6 +143,12 @@ public: { } + void + setServiceInstanceId(std::string const& id) override + { + setup_.serviceInstanceId = id; + } + void start() override { diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index c9cd91a478..c9d5a2369d 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -263,7 +263,7 @@ public: telemetry::make_Telemetry( telemetry::setup_Telemetry( config_->section("telemetry"), - "", // nodePublicKey not yet available at this point + "", // Updated later via setServiceInstanceId() BuildInfo::getVersionString()), logs_->journal("Telemetry"))) @@ -1274,6 +1274,12 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) nodeIdentity_ = getNodeIdentity(*this, cmdline); + // Now that the node identity is known, inject it into the telemetry + // resource attributes. The Telemetry object was constructed with an + // empty serviceInstanceId because nodeIdentity_ is not available in + // the ApplicationImp member initializer list. + telemetry_->setServiceInstanceId(toBase58(TokenType::NodePublic, nodeIdentity_->first)); + if (!cluster_->load(config().section(SECTION_CLUSTER_NODES))) { JLOG(m_journal.fatal()) << "Invalid entry in cluster configuration.";