use of com.newrelic.agent.Transaction in project newrelic-java-agent by newrelic.
the class InstrumentationImpl method oldCreateSqlTracer.
// This code path is similar to the 3.16.1 and earlier tracer creation path. It is retained for use by legacy
// async instrumentation, including NAPS (Netty, Akka, Play, Scala) and async servlet instrumentation.
private ExitTracer oldCreateSqlTracer(TransactionActivity txa, Object invocationTarget, int signatureId, String metricName, int flags) {
if (txa == null) {
AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
if (tokenAndRefCount != null && tokenAndRefCount.token != null) {
// Fast path for scala instrumentation (and potentially others in the future)
Transaction tx = Transaction.getTransaction(false);
if (tx == null) {
if (tokenAndRefCount.token.getTransaction() instanceof Transaction) {
tx = (Transaction) tokenAndRefCount.token.getTransaction();
} else {
return null;
}
}
txa = TransactionActivity.create(tx, Integer.MAX_VALUE);
flags = flags | TracerFlags.ASYNC;
ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
Tracer tracer;
if (TracerFlags.isRoot(flags)) {
// Dispatcher || Async
tracer = new OtherRootSqlTracer(txa, sig, invocationTarget, mnf, flags);
} else if (overSegmentLimit(txa)) {
logger.log(Level.FINEST, "Transaction has exceeded tracer segment limit. Returning ultralight sql tracer.");
return UltraLightTracer.createClampedSegment(txa, sig);
} else {
tracer = new DefaultSqlTracer(txa, sig, invocationTarget, mnf, flags);
}
txa.tracerStarted(tracer);
Tracer initiatingTracer = (Tracer) tokenAndRefCount.tracedMethod.getAndSet(tracer);
tx.startFastAsyncWork(txa, initiatingTracer);
return tracer;
} else if (TracerFlags.isAsync(flags)) {
txa = TransactionActivity.create(null, Integer.MAX_VALUE);
return startTracer(txa, invocationTarget, signatureId, metricName, flags);
}
}
// Avoid creating tracers for NoOpTransaction, etc.
com.newrelic.agent.Transaction transaction = com.newrelic.agent.Transaction.getTransaction(TracerFlags.isDispatcher(flags));
if (transaction == null) {
return null;
}
try {
if (!TracerFlags.isDispatcher(flags) && !transaction.isStarted()) {
// if we're not in a transaction and this isn't a dispatcher tracer, bail before we create objects
return null;
}
if (transaction.getTransactionActivity().isLeaf()) {
return null;
}
ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
return transaction.getTransactionState().getSqlTracer(transaction, invocationTarget, sig, metricName, flags);
} catch (Throwable t) {
logger.log(Level.FINEST, t, "createTracer({0}, {1}, {2}, {3})", invocationTarget, signatureId, metricName, flags);
return null;
}
}
use of com.newrelic.agent.Transaction in project newrelic-java-agent by newrelic.
the class InvocationPoint method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if (ignoreApdex) {
Transaction transaction = Transaction.getTransaction(false);
if (transaction != null) {
Dispatcher dispatcher = transaction.getDispatcher();
if (dispatcher != null) {
dispatcher.setIgnoreApdex(true);
if (Agent.LOG.isLoggable(Level.FINER)) {
String msg = MessageFormat.format("Set Ignore apdex to \"{0}\"", true);
Agent.LOG.log(Level.FINER, msg, new Exception());
}
}
}
}
Object t = tracerService.getTracer(tracerFactory, classMethodSignature, args[0], (Object[]) args[1]);
return t;
} catch (Throwable t) {
Agent.LOG.log(Level.FINEST, "Tracer invocation error", t);
}
return null;
}
use of com.newrelic.agent.Transaction in project newrelic-java-agent by newrelic.
the class AbstractTracer method nameTransaction.
@Override
public void nameTransaction(TransactionNamePriority priority) {
try {
ClassMethodSignature classMethodSignature = getClassMethodSignature();
Object invocationTarget = getInvocationTarget();
String className = invocationTarget == null ? classMethodSignature.getClassName() : invocationTarget.getClass().getName();
String txName = className + "/" + classMethodSignature.getMethodName();
Agent.LOG.log(Level.FINER, "Setting transaction name using instrumented class and method: {0}", txName);
Transaction tx = transactionActivity.getTransaction();
tx.setTransactionName(priority, false, customPrefix, txName);
} catch (Throwable t) {
Agent.LOG.log(Level.FINEST, "nameTransaction", t);
}
}
use of com.newrelic.agent.Transaction in project newrelic-java-agent by newrelic.
the class DefaultSqlTracer method doFinish.
@Override
protected void doFinish(Throwable throwable) {
super.doFinish(throwable);
// if an error is thrown, stick the sql up in the transaction parameters so that it'll show up in the traced
// error
Object sql = getSql();
if (sql != null) {
Transaction transaction = getTransaction();
if (transaction != null) {
if (getRecordSql().equals(RecordSql.raw)) {
// Store the raw query string
getTransaction().getIntrinsicAttributes().put(SQL_PARAMETER_NAME, sql.toString());
} else if (getRecordSql().equals(RecordSql.obfuscated)) {
String appName = getTransaction().getApplicationName();
SqlQueryConverter converter = new SqlQueryConverter(appName, getDatabaseVendor());
String obfuscatedQueryString = converter.toObfuscatedQueryString(sql.toString());
// Store the obfuscated query string
getTransaction().getIntrinsicAttributes().put(SQL_PARAMETER_NAME, obfuscatedQueryString);
}
}
}
}
use of com.newrelic.agent.Transaction in project newrelic-java-agent by newrelic.
the class DefaultSqlTracer method doFinish.
@Override
protected void doFinish(int opcode, Object returnValue) {
super.doFinish(opcode, returnValue);
Transaction transaction = getTransaction();
if (transaction != null) {
TransactionTracerConfig transactionTracerConfig = transaction.getTransactionTracerConfig();
double explainThresholdInNanos = transactionTracerConfig.getExplainThresholdInNanos();
// The string equality check here is intentional, both values are interned Strings
if (SqlObfuscator.RAW_SETTING == transactionTracerConfig.getRecordSql() || getDuration() > explainThresholdInNanos) {
// we have to copy the parameters because they will be cleared later
Object[] sqlParameters = params == null ? null : new Object[params.length];
if (sqlParameters != null) {
System.arraycopy(params, 0, sqlParameters, 0, params.length);
params = sqlParameters;
}
}
if (isTransactionSegment() && captureSql()) {
this.sqlObject = getSql();
}
parseStatement(returnValue, transaction.getRPMService().getConnectionTimestamp());
if (isTransactionSegment() && sql != null) {
if (transactionTracerConfig.isExplainEnabled()) {
captureExplain(parsedDatabaseStatement, explainThresholdInNanos, transactionTracerConfig);
} else {
if (Agent.isDebugEnabled()) {
String msg = MessageFormat.format("Statement exceeded threshold?: {0}", getDuration() > explainThresholdInNanos);
Agent.LOG.finer(msg);
}
}
}
}
}
Aggregations