Skip to content

Commit 3fe0101

Browse files
committed
more debug env vars and logging
1 parent 2cb2cea commit 3fe0101

File tree

7 files changed

+78
-247
lines changed

7 files changed

+78
-247
lines changed

src/yb/rpc/outbound_call.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,17 @@ OutboundCall::OutboundCall(const RemoteMethod& remote_method,
243243
IncrementCounter(rpc_metrics_->outbound_calls_created);
244244
IncrementGauge(rpc_metrics_->outbound_calls_alive);
245245

246-
// Start an OpenTelemetry span for this RPC call
247-
// Only create spans when there's an active parent context to reduce noise
248246
if (OtelTracing::HasActiveContext()) {
249247
otel_span_ = OtelTracing::StartSpan(Format("rpc.client $0", remote_method_.ToString()));
250248
if (otel_span_.IsActive()) {
251-
LOG(INFO) << "[OTEL DEBUG] Created RPC span (child) for call_id=" << call_id_
252-
<< " method=" << remote_method_.ToString();
253249
otel_span_.SetAttribute("rpc.system", "yugabytedb");
254250
otel_span_.SetAttribute("rpc.service", remote_method_.service_name());
255251
otel_span_.SetAttribute("rpc.method", remote_method_.method_name());
256252
otel_span_.SetAttribute("rpc.call_id", static_cast<int64_t>(call_id_));
257253
if (controller_->timeout().Initialized()) {
258-
otel_span_.SetAttribute("rpc.timeout_ms",
259-
static_cast<int64_t>(controller_->timeout().ToMilliseconds()));
254+
otel_span_.SetAttribute("rpc.timeout_ms", controller_->timeout().ToMilliseconds());
260255
}
261256
}
262-
} else {
263-
VLOG(3) << "[OTEL DEBUG] No active context, skipping RPC span creation for call_id=" << call_id_;
264257
}
265258
}
266259

src/yb/util/otel_http_exporter.cc

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ SimpleOtlpHttpSender g_otlp_sender;
3232
} // namespace
3333

3434
SimpleOtlpHttpSender::SimpleOtlpHttpSender()
35-
: service_name_("yugabyte"), enabled_(false) {}
35+
: enabled_(false) {
36+
const char* service_name_env = std::getenv("OTEL_SERVICE_NAME");
37+
service_name_ = (service_name_env && service_name_env[0] != '\0') ? service_name_env : "yugabyte";
38+
}
3639

3740
SimpleOtlpHttpSender::~SimpleOtlpHttpSender() = default;
3841

@@ -56,15 +59,10 @@ bool SimpleOtlpHttpSender::SendSpan(const SimpleSpanData& span) {
5659
}
5760

5861
bool SimpleOtlpHttpSender::SendSpans(const std::vector<SimpleSpanData>& spans) {
59-
if (!IsEnabled()) {
60-
VLOG(2) << "[OTEL] HTTP sender not enabled, skipping export";
62+
if (!IsEnabled() || spans.empty()) {
6163
return true;
6264
}
6365

64-
if (spans.empty()) {
65-
return true; // Nothing to do
66-
}
67-
6866
std::string json_payload = SpansToJson(spans);
6967

7068
LOG(INFO) << "[OTEL] Sending " << spans.size() << " span(s) to " << endpoint_;
@@ -124,7 +122,6 @@ std::string SimpleOtlpHttpSender::JsonEscape(const std::string& str) {
124122
std::string SimpleOtlpHttpSender::SpansToJson(const std::vector<SimpleSpanData>& spans) const {
125123
std::ostringstream json;
126124

127-
// OTLP JSON structure
128125
json << R"({"resourceSpans":[{"resource":{"attributes":[)";
129126
json << R"({"key":"service.name","value":{"stringValue":")" << JsonEscape(service_name_) << R"("}},)";
130127
json << R"({"key":"telemetry.sdk.language","value":{"stringValue":"cpp"}},)";
@@ -153,7 +150,6 @@ std::string SimpleOtlpHttpSender::SpansToJson(const std::vector<SimpleSpanData>&
153150
json << R"("startTimeUnixNano":")" << span.start_time_ns << R"(",)";
154151
json << R"("endTimeUnixNano":")" << span.end_time_ns << R"(",)";
155152

156-
// Attributes
157153
json << R"("attributes":[)";
158154
bool first_attr = true;
159155
for (size_t j = 0; j < span.string_attributes.size(); ++j) {
@@ -170,7 +166,6 @@ std::string SimpleOtlpHttpSender::SpansToJson(const std::vector<SimpleSpanData>&
170166
}
171167
json << "],";
172168

173-
// Status
174169
json << R"("status":{"code":)" << span.status_code;
175170
if (!span.status_message.empty()) {
176171
json << R"(,"message":")" << JsonEscape(span.status_message) << R"(")";
@@ -187,33 +182,29 @@ SimpleOtlpHttpSender& GetGlobalOtlpSender() {
187182
}
188183

189184
void InitGlobalOtlpSenderFromEnv(const std::string& service_name) {
190-
// Read endpoint from OTEL_EXPORTER_OTLP_ENDPOINT environment variable
191185
std::string endpoint;
192186
const char* endpoint_env = std::getenv("OTEL_EXPORTER_OTLP_ENDPOINT");
193-
187+
194188
if (endpoint_env && endpoint_env[0] != '\0') {
195-
// Per OTLP spec, OTEL_EXPORTER_OTLP_ENDPOINT is the base URL
196-
// Append /v1/traces for the traces signal
197189
endpoint = endpoint_env;
198-
// Only append /v1/traces if it's not already part of the URL
199190
if (endpoint.find("/v1/traces") == std::string::npos) {
200-
// Remove trailing slash if present before appending
201191
if (!endpoint.empty() && endpoint.back() == '/') {
202192
endpoint.pop_back();
203193
}
204194
endpoint += "/v1/traces";
205195
}
206196
} else {
207-
// Default endpoint for local development
208197
endpoint = "http://localhost:4318/v1/traces";
209198
}
210-
199+
211200
g_otlp_sender.SetEndpoint(endpoint);
212201
LOG(INFO) << "[OTEL] HTTP exporter endpoint: " << endpoint;
213202

214-
// Set the service name (already resolved by caller)
215-
g_otlp_sender.SetServiceName(service_name);
216-
LOG(INFO) << "[OTEL] HTTP exporter service name: " << service_name;
203+
const char* service_name_env = std::getenv("OTEL_SERVICE_NAME");
204+
std::string resolved_service_name = (service_name_env && service_name_env[0] != '\0')
205+
? service_name_env : "yugabyte";
206+
g_otlp_sender.SetServiceName(resolved_service_name);
207+
LOG(INFO) << "[OTEL] HTTP exporter service name: " << resolved_service_name;
217208
}
218209

219210
} // namespace yb

0 commit comments

Comments
 (0)