Skip to content

Commit

Permalink
Moving attribute name constants to AttributeNames
Browse files Browse the repository at this point in the history
  • Loading branch information
meiao committed Sep 25, 2023
1 parent 570601d commit 69b54e2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public final class AttributeNames {
public static final String TIMEOUT_CAUSE = "nr.timeoutCause";
public static final String ERROR_EXPECTED = "error.expected";

public static final String COMPONENT = "component";
public static final String HTTP_METHOD = "http.method";
public static final String HTTP_STATUS_CODE = "http.statusCode";
public static final String HTTP_STATUS_TEXT = "http.statusText";

public static final String LOCK_THREAD_NAME = "jvm.lock_thread_name";
public static final String THREAD_NAME = "jvm.thread_name";
public static final String THREAD_ID = "thread.id";

public static final String MESSAGE_REQUEST_PREFIX = "message.parameters.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.newrelic.agent.model.SpanError;
import com.newrelic.agent.model.SpanEvent;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.agent.tracers.DefaultTracer;
import com.newrelic.agent.util.ExternalsUtil;
import com.newrelic.api.agent.DatastoreParameters;
import com.newrelic.api.agent.ExternalParameters;
Expand Down Expand Up @@ -120,9 +119,9 @@ public SpanEventFactory setClmAttributes(Map<String, Object> agentAttributes) {
if (agentAttributes == null || agentAttributes.isEmpty()) {
return this;
}
final Object threadId = agentAttributes.get(DefaultTracer.THREAD_ID_PARAMETER_NAME);
final Object threadId = agentAttributes.get(AttributeNames.THREAD_ID);
if (threadId != null) {
builder.putAgentAttribute(DefaultTracer.THREAD_ID_PARAMETER_NAME, threadId);
builder.putAgentAttribute(AttributeNames.THREAD_ID, threadId);
}
if (agentAttributes.containsKey(AttributeNames.CLM_NAMESPACE) && agentAttributes.containsKey(AttributeNames.CLM_FUNCTION)) {
builder.putAgentAttribute(AttributeNames.CLM_NAMESPACE, agentAttributes.get(AttributeNames.CLM_NAMESPACE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public class DefaultTracer extends AbstractTracer {
public static final int DEFAULT_TRACER_FLAGS = TracerFlags.TRANSACTION_TRACER_SEGMENT
| TracerFlags.GENERATE_SCOPED_METRIC;

private static final String COMPONENT_PARAMETER_NAME = "component";
private static final String HTTP_METHOD_PARAMETER_NAME = "http.method";
public static final String THREAD_ID_PARAMETER_NAME = "thread.id";

private final long startTime;
private final long timestamp;
private long duration;
Expand Down Expand Up @@ -291,7 +287,7 @@ public void performFinishWork(long finishTime, int opcode, Object returnValue) {
}

try {
setAgentAttribute(THREAD_ID_PARAMETER_NAME, getTransactionActivity().getThreadId());
setAgentAttribute(AttributeNames.THREAD_ID, getTransactionActivity().getThreadId());
if (classMethodSignature != null && getTransaction() != null &&
ServiceFactory.getConfigService().getDefaultAgentConfig().getCodeLevelMetricsConfig().isEnabled()) {
String className = classMethodSignature.getClassName();
Expand Down Expand Up @@ -714,9 +710,9 @@ private void recordExternalMetricsHttp(HttpParameters externalParameters) {
String uriStr = uri == null ? ExternalMetrics.UNKNOWN_HOST : uri.toString();

String library = externalParameters.getLibrary();
setAgentAttribute(COMPONENT_PARAMETER_NAME, library);
setAgentAttribute(AttributeNames.COMPONENT, library);
String procedure = externalParameters.getProcedure();
setAgentAttribute(HTTP_METHOD_PARAMETER_NAME, procedure);
setAgentAttribute(AttributeNames.HTTP_METHOD, procedure);

ExternalMetrics.makeExternalComponentTrace(transaction.isWebTransaction(), this, host, library, true,
uriStr, procedure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ public void shouldSetCLMParameters() {
Map<String, Object> agentAttributes = ImmutableMap.of(
AttributeNames.CLM_NAMESPACE, "nr",
AttributeNames.CLM_FUNCTION, "process",
DefaultTracer.THREAD_ID_PARAMETER_NAME, 666
AttributeNames.THREAD_ID, 666
);

SpanEvent target = spanEventFactory.setClmAttributes(agentAttributes).build();

assertEquals("nr", target.getAgentAttributes().get(AttributeNames.CLM_NAMESPACE));
assertEquals("process", target.getAgentAttributes().get(AttributeNames.CLM_FUNCTION));
assertEquals(666, target.getAgentAttributes().get(DefaultTracer.THREAD_ID_PARAMETER_NAME));
assertEquals(666, target.getAgentAttributes().get(AttributeNames.THREAD_ID));
}

@Test
Expand Down

0 comments on commit 69b54e2

Please sign in to comment.