Skip to content

Conversation

@mznet
Copy link
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 on lines +30 to +34
if (request.getBody() == null) {
return request.getMethod() + " " + request.getOperation();
} else {
return request.getBody();
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (request.getBody() == null) {
return request.getMethod() + " " + request.getOperation();
} else {
return request.getBody();
}
if (request.getBody() == null) {
return request.getMethod() + " " + request.getOperation();
}
return request.getBody();

import org.opensearch.client.json.NdJsonpSerializable;
import org.opensearch.client.transport.GenericSerializable;

public class OpenSearchBodyExtractor {
Copy link
Member

Choose a reason for hiding this comment

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

Public classes should be declared final where possible (ref)

Suggested change
public class OpenSearchBodyExtractor {
public final class OpenSearchBodyExtractor {

import java.util.Map;
import java.util.logging.Logger;

public class OpenSearchBodySanitizer {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class OpenSearchBodySanitizer {
public final class OpenSearchBodySanitizer {

Comment on lines +12 to +15
/**
* Splits multiple queries separated by semicolons. Single Responsibility: Only responsible for
* query separation logic.
*/
Copy link
Member

Choose a reason for hiding this comment

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

i dont think is right?

Suggested change
/**
* Splits multiple queries separated by semicolons. Single Responsibility: Only responsible for
* query separation logic.
*/
/**
* Splits and joins queries for newline-delimited JSON (nd-json) format.
* Splits input by newlines and joins output with semicolons for display.
*/

testImplementation("software.amazon.awssdk:identity-spi:2.26.0")
testImplementation("software.amazon.awssdk:apache-client:2.26.0")
testImplementation("software.amazon.awssdk:netty-nio-client:2.26.0")
testImplementation("software.amazon.awssdk:netty-nio-client:2.26.0")
Copy link
Member

Choose a reason for hiding this comment

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

duplicate

Suggested change
testImplementation("software.amazon.awssdk:netty-nio-client:2.26.0")

Comment on lines +35 to +45
public static OpenSearchBodySanitizer create() {
return new OpenSearchBodySanitizer(DEFAULT_OBJECT_MAPPER);
}

public static OpenSearchBodySanitizer create(ObjectMapper objectMapper) {
return new OpenSearchBodySanitizer(objectMapper);
}

public static OpenSearchBodySanitizer getDefault() {
return DEFAULT_INSTANCE;
}
Copy link
Member

Choose a reason for hiding this comment

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

this all looks to be unused, is it needed?

Suggested change
public static OpenSearchBodySanitizer create() {
return new OpenSearchBodySanitizer(DEFAULT_OBJECT_MAPPER);
}
public static OpenSearchBodySanitizer create(ObjectMapper objectMapper) {
return new OpenSearchBodySanitizer(objectMapper);
}
public static OpenSearchBodySanitizer getDefault() {
return DEFAULT_INSTANCE;
}

if (request instanceof NdJsonpSerializable) {
writeNdJson(mapper, (NdJsonpSerializable) request, baos);
} else if (request instanceof GenericSerializable) {
ContentType.parse(((GenericSerializable) request).serialize(baos));
Copy link
Member

Choose a reason for hiding this comment

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

is the ContentType.parse needed here? could it just be ((GenericSerializable) request).serialize(baos); ?

server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.JSON_UTF_8, searchResponseJson));
}

void setupForMsearchResponse() {
Copy link
Member

Choose a reason for hiding this comment

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

this is unused

| 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
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. |

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

2 participants