Skip to content

Commit

Permalink
Increase Size of db.statement Attribute in Span Events (#1851)
Browse files Browse the repository at this point in the history
* increased size of DB_STATEMENT_TRUNCATE_LENGTH

* updated tests to accommodate the increase in DB_STATEMENT_TRUNCATE_LENGTH
  • Loading branch information
deleonenriqueta authored Apr 12, 2024
1 parent 9f932ef commit 402ecf2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SpanEventFactory {

private static final Joiner TRACE_STATE_VENDOR_JOINER = Joiner.on(",");
// Truncate `db.statement` at 2000 characters
private static final int DB_STATEMENT_TRUNCATE_LENGTH = 2000;
private static final int DB_STATEMENT_TRUNCATE_LENGTH = 4095;
private static final int MAX_EVENT_ATTRIBUTE_STRING_LENGTH = 4095;

public static final Supplier<Long> DEFAULT_SYSTEM_TIMESTAMP_SUPPLIER = System::currentTimeMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public void addressShouldBeSet() {
}

@Test
public void shouldTruncate3KDBStatementTo2K() {
char[] data = new char[3000];
String threeKStatement = new String(data);
public void shouldTruncate5KDBStatementTo4K() {
char[] data = new char[5000];
String fiveKStatement = new String(data);

SpanEvent target = spanEventFactory.setDatabaseStatement(threeKStatement).build();
SpanEvent target = spanEventFactory.setDatabaseStatement(fiveKStatement).build();

assertEquals(2000,
assertEquals(4095,
target.getAgentAttributes().get("db.statement").toString().length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public void testSpanEventDatastoreTruncation() throws SQLException {
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();

String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 4000);
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 5000);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, connection, "MySQL", "mysql");
tracer.finish(Opcodes.ARETURN, new DummyResultSet());

Expand All @@ -503,7 +503,7 @@ public void testSpanEventDatastoreTruncation() throws SQLException {
assertEquals("MySQL", spanEvent.getAgentAttributes().get("db.system"));
assertEquals("dbserver.nerd.us", spanEvent.getAgentAttributes().get("peer.hostname"));
assertEquals("dbserver.nerd.us:9945", spanEvent.getAgentAttributes().get("peer.address"));
assertEquals(2000, spanEvent.getAgentAttributes().get("db.statement").toString().length());
assertEquals(4095, spanEvent.getAgentAttributes().get("db.statement").toString().length());
assertTrue(spanEvent.getAgentAttributes().get("db.statement").toString().endsWith("a..."));
assertEquals("books", spanEvent.getAgentAttributes().get("db.collection"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public void testSpanEventDatastoreTruncation() throws SQLException {
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();

String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 4000);
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 5000);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, connection, "MySQL", "mysql");
tracer.finish(Opcodes.ARETURN, new DummyResultSet());

Expand All @@ -676,7 +676,7 @@ public void testSpanEventDatastoreTruncation() throws SQLException {
assertEquals("MySQL", spanEvent.getAgentAttributes().get("db.system"));
assertEquals("dbserver.nerd.us", spanEvent.getAgentAttributes().get("peer.hostname"));
assertEquals("dbserver.nerd.us:9945", spanEvent.getAgentAttributes().get("peer.address"));
assertEquals(2000, spanEvent.getAgentAttributes().get("db.statement").toString().length());
assertEquals(4095, spanEvent.getAgentAttributes().get("db.statement").toString().length());
assertTrue(spanEvent.getAgentAttributes().get("db.statement").toString().endsWith("a..."));
assertEquals("books", spanEvent.getAgentAttributes().get("db.collection"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
Expand Down

0 comments on commit 402ecf2

Please sign in to comment.