Skip to content

Commit

Permalink
opentelemetrytracer: Log (debug) the number of exported spans (#37828)
Browse files Browse the repository at this point in the history
Commit Message: Log (debug) the number of exported spans 

Additional Description: 

Adds a debug log message containing the number of (about to be) exported
spans. This is helpful in troubleshooting for cases where the
configuration looks "correct" but no spans are seen in the tracing
back-end. The stats sink could be used, but that only exports via
OTLP/gRPC which is not always possible.
Risk Level: Low
Testing: Manual and Unit tests
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

---------

Signed-off-by: Joao Grassi <[email protected]>
  • Loading branch information
joaopgrassi authored Jan 6, 2025
1 parent b0d58be commit 959950f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void OpenTelemetryGrpcTraceExporter::onFailure(Grpc::Status::GrpcStatus status,
bool OpenTelemetryGrpcTraceExporter::log(const ExportTraceServiceRequest& request) {
client_->send(service_method_, request, *this, Tracing::NullSpan::instance(),
Http::AsyncClient::RequestOptions());
OpenTelemetryTraceExporter::logExportedSpans(request);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ bool OpenTelemetryHttpTraceExporter::log(const ExportTraceServiceRequest& reques
Http::AsyncClient::Request* in_flight_request =
thread_local_cluster->httpAsyncClient().send(std::move(message), *this, options);

OpenTelemetryTraceExporter::logExportedSpans(request);

if (in_flight_request == nullptr) {
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions source/extensions/tracers/opentelemetry/trace_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ class OpenTelemetryTraceExporter : public Logger::Loggable<Logger::Id::tracing>
* @return false When sending the request failed.
*/
virtual bool log(const ExportTraceServiceRequest& request) = 0;

/**
* @brief Logs as debug the number of exported spans.
*
* @param request The protobuf-encoded OTLP trace request.
*/
void logExportedSpans(const ExportTraceServiceRequest& request) {
if (request.resource_spans(0).has_resource()) {
if (request.resource_spans(0).scope_spans(0).has_scope()) {
ENVOY_LOG(debug, "Number of exported spans: {}",
request.resource_spans(0).scope_spans(0).spans_size());
}
}
}
};

using OpenTelemetryTraceExporterPtr = std::unique_ptr<OpenTelemetryTraceExporter>;
Expand Down

0 comments on commit 959950f

Please sign in to comment.