Skip to content

Opensearch transport query sanitization#15634

Merged
trask merged 25 commits intoopen-telemetry:mainfrom
mznet:opensearch-transport-query-sanitization
Mar 13, 2026
Merged

Opensearch transport query sanitization#15634
trask merged 25 commits intoopen-telemetry:mainfrom
mznet:opensearch-transport-query-sanitization

Conversation

@mznet
Copy link
Copy Markdown
Contributor

@mznet mznet commented Dec 13, 2025

Since extracting query body can impact application performance, I made it optional with otel.instrumentation.elasticsearch.capture-search-query. Not sure if adding this config is okay though.

close #15466

@mznet mznet requested a review from a team as a code owner December 13, 2025 10:33
Comment thread instrumentation/opensearch/opensearch-java-3.0/javaagent/build.gradle.kts Outdated
Comment thread instrumentation/opensearch/README.md Outdated
| System property | Type | Default | Description |
|-----------------------------------------------------------------|---------| ------- |------------------------------------------------------|
| `otel.instrumentation.opensearch.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental span attributes. |
| `otel.instrumentation.opensearch.capture-search-query` | Boolean | `false` | Enable the capture of sanitized search query bodies. |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if it's worth mentioning that this will likely impact performance in some way due to the serialization?

Suggested change
| `otel.instrumentation.opensearch.capture-search-query` | Boolean | `false` | Enable the capture of sanitized search query bodies. |
| `otel.instrumentation.opensearch.capture-search-query` | Boolean | `false` | Enable the capture of sanitized search query bodies. **Note**: Enabling this feature adds overhead for JSON serialization and parsing on search 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.

@jaydeluca I think so. This feature can add overhead to search requests. The overhead is expected to be slight, but could be unexpected on systems that use a lot of search requests. It's better to clarify this.

@mznet mznet requested a review from jaydeluca December 17, 2025 04:01
Comment thread instrumentation/opensearch/opensearch-java-3.0/javaagent/build.gradle.kts Outdated
@mznet
Copy link
Copy Markdown
Contributor Author

mznet commented Dec 24, 2025

The build failed due to a link validation check on armeria.dev, which is returning 404 not found(line/armeria#6560)

@mznet mznet requested a review from laurit December 24, 2025 03:13
@minwoox
Copy link
Copy Markdown

minwoox commented Dec 24, 2025

armeria.dev is back online. We apologize for the inconvenience. 🙇

@mznet mznet requested a review from breedx-splk January 7, 2026 04:38
@mznet mznet requested a review from laurit January 8, 2026 13:42
Comment on lines +37 to +44
if (request instanceof GenericSerializable) {
// GenericSerializable writes directly to output stream, cannot sanitize
// This path is typically not used for search queries
ByteArrayOutputStream baos = new ByteArrayOutputStream();
((GenericSerializable) request).serialize(baos);
String body = baos.toString(UTF_8);
return body.isEmpty() ? null : body;
}
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.

none of the tests seem to use this part

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.

@laurit since the type of request is checked to be either SearchRequest or MsearchRequest before calling extractSanitized, so the request can't be an instance of GenericSerializable. it was not a dead code before, but it became the dead code after some modification. it should be removed.

Comment thread instrumentation/opensearch/README.md Outdated
| System property | Type | Default | Description |
| -------------------------------------------------------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `otel.instrumentation.opensearch.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental span attributes. |
| `otel.instrumentation.opensearch.capture-search-query` | Boolean | `false` | Enable the capture of sanitized search query bodies. **Note**: Enabling this feature adds overhead for JSON serialization and parsing on search requests. |
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.

Since capturing the query is now simpler than in the initial version I'm wondering whether we should add the performance note at all. Perhaps we should enable this by default?
cc @trask

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems reasonable, it's definitely useful data

@laurit laurit added this to the v2.26.0 milestone Feb 26, 2026
@trask trask merged commit 6e1f950 into open-telemetry:main Mar 13, 2026
93 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Mar 13, 2026

Thank you for your contribution @mznet! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

Expose OpenSearch search body to its span db.query.text

6 participants