Skip to content

Commit

Permalink
Fixed populating NR APM TracedMethod info in linking metadata. (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-ap committed Nov 23, 2023
1 parent 258949e commit 0146237
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ private JavaAgentEventBean setGenericProperties(AbstractOperation objectBean, Ja
eventBean.setUserAPIInfo(operation.getUserClassEntity().getUserClassElement().getLineNumber(),
operation.getUserClassEntity().getUserClassElement().getClassName(),
operation.getUserClassEntity().getUserClassElement().getMethodName());
eventBean.getLinkingMetadata().put(NR_APM_TRACE_ID, securityMetaData.getCustomAttribute(NR_APM_TRACE_ID, String.class));
eventBean.getLinkingMetadata().put(NR_APM_SPAN_ID, securityMetaData.getCustomAttribute(NR_APM_SPAN_ID, String.class));
return eventBean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import com.newrelic.agent.security.intcodeagent.logging.IAgentConstants;
import com.newrelic.agent.security.intcodeagent.models.javaagent.EventStats;
import com.newrelic.agent.security.intcodeagent.models.javaagent.ExitEventBean;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TraceMetadata;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.agent.security.util.AgentUsageMetric;
import com.newrelic.agent.security.util.IUtilConstants;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
Expand All @@ -21,6 +24,9 @@
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

import static com.newrelic.agent.security.intcodeagent.logging.IAgentConstants.NR_APM_SPAN_ID;
import static com.newrelic.agent.security.intcodeagent.logging.IAgentConstants.NR_APM_TRACE_ID;

public class DispatcherPool {

/**
Expand Down Expand Up @@ -207,13 +213,24 @@ public void dispatchEvent(AbstractOperation operation, SecurityMetaData security
.registerEventForProcessedCC(parentId, operation.getExecutionId());
}
}

// Update NR Trace info
TraceMetadata traceMetadata = NewRelic.getAgent().getTraceMetadata();
securityMetaData.addCustomAttribute(NR_APM_TRACE_ID, traceMetadata.getTraceId());
securityMetaData.addCustomAttribute(NR_APM_SPAN_ID, traceMetadata.getSpanId());
this.executor.submit(new Dispatcher(operation, new SecurityMetaData(securityMetaData)));
}

public void dispatchExitEvent(ExitEventBean exitEventBean) {
if (executor.isShutdown()) {
return;
}

// Update NR Trace info
SecurityMetaData securityMetaData = NewRelicSecurity.getAgent().getSecurityMetaData();
TraceMetadata traceMetadata = NewRelic.getAgent().getTraceMetadata();
securityMetaData.addCustomAttribute(NR_APM_TRACE_ID, traceMetadata.getTraceId());
securityMetaData.addCustomAttribute(NR_APM_SPAN_ID, traceMetadata.getSpanId());
this.executor.submit(new Dispatcher(exitEventBean));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,7 @@ public interface IAgentConstants {
"Last 5 Heath Checks:\n" +
"${last-5-hc}";
String PROCESS_BINARY = "process-binary";

String NR_APM_TRACE_ID = "trace.id";
String NR_APM_SPAN_ID = "span.id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.newrelic.agent.security.intcodeagent.logging.IAgentConstants.*;
Expand Down Expand Up @@ -70,7 +71,7 @@ public AgentBasicInfo() {
setBuildNumber(AgentInfo.getInstance().getBuildInfo().getBuildNumber());
setGroupName(AgentConfig.getInstance().getGroupName());
setNodeId(AgentInfo.getInstance().getLinkingMetadata().getOrDefault(INRSettingsKey.NR_ENTITY_GUID, StringUtils.EMPTY));
setLinkingMetadata(AgentInfo.getInstance().getLinkingMetadata());
setLinkingMetadata(new HashMap<>(AgentInfo.getInstance().getLinkingMetadata()));
if (this instanceof ApplicationInfoBean) {
setJsonName(JSON_NAME_APPLICATION_INFO_BEAN);
} else if (this instanceof JavaAgentEventBean) {
Expand Down

0 comments on commit 0146237

Please sign in to comment.