Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompositeSpanExporter should not call spanExporter if there are no spans to send #221

Closed
corecanarias opened this issue Apr 3, 2023 · 3 comments · Fixed by #224
Closed
Labels
bug A general bug
Milestone

Comments

@corecanarias
Copy link
Contributor

I'm using a springboot 3 app and configured a SpanExportingPredicate to filter some traces based on business logic. Due to this logic, there are scenarios where the CompositeSpanExporter.export() method is being invoked. However, since the configured predicates may produce empty changedSpanData, there are cases where spanExporter.export(changedSpanData) is called with no data.

This results in errors for some OpenTelemetry providers, such as Honeycomb.io. To prevent such errors and avoid some additional empty requests, it would be beneficial to avoid these empty calls altogether.

My current workaround is to override the CompositeSpanExporter and check if there are spans before calling the exporter:

    public CompletableResultCode export(Collection<SpanData> spans) {
        List<SpanData> changedSpanData = spans.stream().filter(this::shouldProcess).map(spanData -> {
            FinishedSpan finishedSpan = OtelFinishedSpan.fromOtel(spanData);
            for (SpanFilter spanFilter : spanFilters) {
                finishedSpan = spanFilter.map(finishedSpan);
            }
            return OtelFinishedSpan.toOtel(finishedSpan);
        }).collect(Collectors.toList());

        // Skip everything if no spans are left
        if (changedSpanData.isEmpty()) {
            return CompletableResultCode.ofSuccess();
        }

        List<CompletableResultCode> results = new ArrayList<>();
        changedSpanData.forEach(spanData -> {
            this.reporters.forEach(reporter -> {
                try {
                    reporter.report(OtelFinishedSpan.fromOtel(spanData));
                    results.add(CompletableResultCode.ofSuccess());
                }
                catch (Exception ex) {
                    results.add(CompletableResultCode.ofFailure());
                }
            });
        });
        this.exporters.forEach(spanExporter -> results.add(spanExporter.export(changedSpanData)));
        return CompletableResultCode.ofAll(results);
    }
@shakuzen
Copy link
Member

shakuzen commented Apr 3, 2023

Thank you for letting us know about this. Would you be interested in making a pull request to change the behavior?

@marcingrzejszczak marcingrzejszczak added the bug A general bug label Apr 3, 2023
@corecanarias
Copy link
Contributor Author

Hi @shakuzen,
Yes, definitely I'll be happy to do it :D Give me some time and I'll send something 👍

@shakuzen shakuzen linked a pull request Apr 5, 2023 that will close this issue
@shakuzen shakuzen added this to the 1.0.4 milestone Apr 5, 2023
@shakuzen
Copy link
Member

shakuzen commented Apr 5, 2023

Fixed by #224

@shakuzen shakuzen closed this as completed Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants