From 49a4bcc47c6b59ede19deb2435aede4337f1e5ef Mon Sep 17 00:00:00 2001 From: Joao Grassi <5938087+joaopgrassi@users.noreply.github.com> Date: Wed, 25 Sep 2024 05:13:06 +0200 Subject: [PATCH] opentelemetrytracer: avoid exporting when there are no spans (#36313) Commit Message: opentelemetrytracer: avoid exporting when there are no spans Additional Description: Today, the OpenTelemetry tracer exports a OTLP request on each interval, even when there are no spans to be sent. The OTLP is empty, only containing the resource (and its attributes). Risk Level: Low Testing: Manual Docs Changes: N/A Release Notes: N/A Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #35997] [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 <5938087+joaopgrassi@users.noreply.github.com> --- changelogs/current.yaml | 3 +++ source/extensions/tracers/opentelemetry/tracer.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/changelogs/current.yaml b/changelogs/current.yaml index 4ae0bc88ca9a..bb31a9025762 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -189,6 +189,9 @@ bug_fixes: change: | Set token cookies in response regardless of :ref:`forward_bearer_token ` config option. +- area: tracing + change: | + Fixed a bug where the OpenTelemetry tracer exports the OTLP request even when no spans are present. removed_config_or_runtime: # *Normally occurs at the end of the* :ref:`deprecation period ` diff --git a/source/extensions/tracers/opentelemetry/tracer.cc b/source/extensions/tracers/opentelemetry/tracer.cc index 5c755bf873f9..1bfb366ae634 100644 --- a/source/extensions/tracers/opentelemetry/tracer.cc +++ b/source/extensions/tracers/opentelemetry/tracer.cc @@ -163,6 +163,10 @@ void Tracer::enableTimer() { } void Tracer::flushSpans() { + if (span_buffer_.empty()) { + return; + } + ExportTraceServiceRequest request; // A request consists of ResourceSpans. ::opentelemetry::proto::trace::v1::ResourceSpans* resource_span = request.add_resource_spans();