diff --git a/changelogs/current.yaml b/changelogs/current.yaml index 9ecf0d6e48ce..d9aab1c27536 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -8,6 +8,9 @@ minor_behavior_changes: bug_fixes: # *Changes expected to improve the state of the world and are unlikely to have negative effects* +- 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 544c37ef96bf..b748745f2f85 100644 --- a/source/extensions/tracers/opentelemetry/tracer.cc +++ b/source/extensions/tracers/opentelemetry/tracer.cc @@ -144,6 +144,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();