Skip to content

Commit

Permalink
opentelemetrytracer: avoid exporting when there are no spans (#36313)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joaopgrassi authored and phlax committed Oct 1, 2024
1 parent 6cc845a commit 80650b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <deprecated>`
Expand Down
4 changes: 4 additions & 0 deletions source/extensions/tracers/opentelemetry/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 80650b7

Please sign in to comment.