Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ public String dbService(final String dbType, final String instanceName) {
if (instanceName != null && Config.get().isDbClientSplitByInstance()) {
return dbClientService(instanceName);
}
final NamingEntry entry = CACHE.computeIfAbsent(dbType, NamingEntry::new);
return entry.getService();
if (dbType == null) {
return null;
}
return CACHE.computeIfAbsent(dbType, NamingEntry::new).getService();
}

public String dbClientService(final String instanceName) {
Expand Down Expand Up @@ -144,11 +146,15 @@ public void onRawStatement(AgentSpan span, String sql) {
}

protected void processDatabaseType(AgentSpan span, String dbType) {
if (dbType == null) {
return;
}

final NamingEntry namingEntry = CACHE.computeIfAbsent(dbType, NamingEntry::new);
span.setTag(DB_TYPE, namingEntry.dbType);
postProcessServiceAndOperationName(span, namingEntry);

if (Config.get().isAppSecRaspEnabled() && dbType != null) {
if (Config.get().isAppSecRaspEnabled()) {
BiConsumer<RequestContext, String> connectDbCallback =
AgentTracer.get()
.getCallbackProvider(RequestContextSlot.APPSEC)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package datadog.trace.bootstrap.instrumentation.decorator;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import org.junit.jupiter.api.Test;

class DatabaseClientDecoratorNullDbTypeTest {

private final AgentSpan span = mock(AgentSpan.class);
private final DatabaseClientDecorator<Object> decorator =
new DatabaseClientDecorator<Object>() {
@Override
protected String[] instrumentationNames() {
return new String[] {"test"};
}

@Override
protected CharSequence spanType() {
return "test-type";
}

@Override
protected CharSequence component() {
return "test-component";
}

@Override
protected String service() {
return "test-service";
}

@Override
protected String dbType() {
return null;
}

@Override
protected String dbUser(Object connection) {
return null;
}

@Override
protected String dbInstance(Object connection) {
return null;
}

@Override
protected CharSequence dbHostname(Object connection) {
return null;
}
};

@Test
void processDatabaseTypeWithNullDbTypeDoesNotThrowOrTag() {
assertDoesNotThrow(() -> decorator.processDatabaseType(span, null));

verify(span, never()).setTag(anyString(), anyString());
}

@Test
void dbServiceWithNullDbTypeReturnsNull() {
assertNull(decorator.dbService(null, null));
}
}