Skip to content

Add support for Elasticsearch client span - #801

Merged
grcevski merged 2 commits into
open-telemetry:mainfrom
coralogix:pgn/elasticsearch
Oct 27, 2025
Merged

Add support for Elasticsearch client span#801
grcevski merged 2 commits into
open-telemetry:mainfrom
coralogix:pgn/elasticsearch

Conversation

@pinoOgni

Copy link
Copy Markdown
Contributor

This PR introduces support for Elasticsearch client spans as part of #141.

In this initial implementation, support has been added for the _search operations. Additional operations will be covered in future PRs.

@pinoOgni
pinoOgni requested a review from a team as a code owner October 24, 2025 15:31
@codecov

codecov Bot commented Oct 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.48092% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.79%. Comparing base (829a747) to head (a99cfb9).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ebpf/common/http/elasticsearch.go 42.46% 37 Missing and 5 partials ⚠️
pkg/app/request/span_getters.go 0.00% 20 Missing ⚠️
pkg/app/request/span.go 10.00% 16 Missing and 2 partials ⚠️
pkg/export/otel/tracesgen/tracesgen.go 0.00% 8 Missing and 1 partial ⚠️
pkg/ebpf/common/http_transform.go 20.00% 4 Missing ⚠️
pkg/app/request/metric_attributes.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #801      +/-   ##
==========================================
+ Coverage   55.06%   55.79%   +0.72%     
==========================================
  Files         241      243       +2     
  Lines       20693    20822     +129     
==========================================
+ Hits        11395    11618     +223     
+ Misses       8540     8427     -113     
- Partials      758      777      +19     
Flag Coverage Δ
integration-test 23.27% <2.29%> (-0.16%) ⬇️
integration-test-arm 0.00% <0.00%> (?)
integration-test-vm-${ARCH}-${KERNEL_VERSION} 0.00% <0.00%> (?)
k8s-integration-test 2.85% <0.00%> (+2.85%) ⬆️
oats-test 0.00% <0.00%> (ø)
unittests 47.06% <25.19%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@grcevski grcevski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing!! I added some minor comments around testing certain functions and one bounds check. I'm approving and we are good to merge once these are addressed.

return ""
}
parts := strings.Split(path, "/")
name := parts[len(parts)-1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be careful and check the len(parts) here.

return httptest.NewRequest(method, target, strings.NewReader(body))
}

tests := []struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for various malformed bodies and incomplete queries? It can happen with partial buffers and customers sending wrong requests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @grcevski, I was implementing the required tests and it occurred to me: are we sure we want to consider a request with a malformed body/incomplete request as invalid?

I'm currently checking if the JSON is good or not and for example this "{" is an invalid json, while this "{"query": "not_object"}" is a valid json but not to be a valid request it should be for example like this "{"query":{"match_all":{}}}".
From our point of view it's just a request to an elasticsearch server which will reply with 400 Bad request and we can categorize it as elasticsearch request instead of just http.
What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's a good point! let's keep it as is!

Comment thread pkg/ebpf/common/http_transform.go Outdated
}

if parseCtx != nil && !parseCtx.payloadExtraction.HTTP.GraphQL.Enabled {
if parseCtx != nil && !parseCtx.payloadExtraction.HTTP.GraphQL.Enabled && !parseCtx.payloadExtraction.HTTP.Elasticsearch.Enabled {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind making a helper function like any payload extraction enabled etc.?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Giuseppe Ognibene <giuseppe.ognibene@coralogix.com>
Signed-off-by: Giuseppe Ognibene <giuseppe.ognibene@coralogix.com>
@grcevski
grcevski merged commit 3bdbd6e into open-telemetry:main Oct 27, 2025
51 checks passed
@grcevski

Copy link
Copy Markdown
Contributor

Awesome stuff @pinoOgni !

@pinoOgni
pinoOgni deleted the pgn/elasticsearch branch October 29, 2025 08:49
@MrAlias MrAlias added this to the v0.1.0 milestone Oct 30, 2025
marctc pushed a commit to grafana/opentelemetry-ebpf-instrumentation that referenced this pull request Dec 9, 2025
Great work! Thanks for your contribution!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants