Search in sources :

Example 1 with ExternalParameters

use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.

the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.

// Async reporting - overload for OperationsFuture
private void reportDatastoreMetricsAsync(String op, OperationFuture<?> future) {
    String host = null;
    Integer port = null;
    try {
        MemcachedNode memcachedNode = MemcachedUtil.OPERATION_NODE.get();
        if (memcachedNode != null) {
            SocketAddress address = memcachedNode.getSocketAddress();
            if (address instanceof InetSocketAddress) {
                InetSocketAddress nodeAddress = (InetSocketAddress) address;
                host = nodeAddress.getHostName();
                port = nodeAddress.getPort();
            }
        }
    } catch (Throwable t) {
        AgentBridge.getAgent().getLogger().log(Level.FINER, t, "Unable to capture host/port for memcached operation");
    } finally {
        MemcachedUtil.OPERATION_NODE.set(null);
    }
    final Segment segment = AgentBridge.getAgent().getTransaction().createAndStartTracedActivity();
    if (segment != null) {
        ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
        segment.reportAsExternal(params);
        if (future.isDone()) {
            segment.endAsync();
        } else {
            future.addListener(new OperationCompletionListener(segment));
        }
    }
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) InetSocketAddress(java.net.InetSocketAddress) MemcachedNode(net.spy.memcached.MemcachedNode) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Segment(com.newrelic.api.agent.Segment)

Example 2 with ExternalParameters

use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.

the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.

/**
 *  Async reporting - overload for GetFuture
 *
 *  Create traced activity and call reportAsExternal on the traced activitiy TracedMethod.
 *
 *  Callers of this helper should not have an @Trace.
 *
 * @param op Operation to report
 * @param future Future to add listener to.
 */
private void reportDatastoreMetricsAsync(String op, GetFuture<?> future) {
    String host = null;
    Integer port = null;
    try {
        MemcachedNode memcachedNode = MemcachedUtil.OPERATION_NODE.get();
        if (memcachedNode != null) {
            SocketAddress address = memcachedNode.getSocketAddress();
            if (address instanceof InetSocketAddress) {
                InetSocketAddress nodeAddress = (InetSocketAddress) address;
                host = nodeAddress.getHostName();
                port = nodeAddress.getPort();
            }
        }
    } catch (Throwable t) {
        AgentBridge.getAgent().getLogger().log(Level.FINER, t, "Unable to capture host/port for memcached operation");
    } finally {
        MemcachedUtil.OPERATION_NODE.set(null);
    }
    if (AgentBridge.getAgent().getTransaction(false) != null) {
        final Segment segment = NewRelic.getAgent().getTransaction().startSegment(op);
        ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
        segment.reportAsExternal(params);
        if (future.isDone()) {
            segment.endAsync();
        } else {
            future.addListener(new GetCompletionListener(segment));
        }
    }
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) InetSocketAddress(java.net.InetSocketAddress) MemcachedNode(net.spy.memcached.MemcachedNode) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Segment(com.newrelic.api.agent.Segment)

Example 3 with ExternalParameters

use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.

the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.

/**
 *  Async reporting - overload for BulkFuture
 *
 *  Create traced activity and call reportAsExternal on the traced activitiy TracedMethod.
 *
 *  Callers of this helper should not have an @Trace.
 *
 * @param op Operation to report
 * @param future Future to add listener to.
 */
private void reportDatastoreMetricsAsync(String op, BulkFuture<?> future) {
    String host = null;
    Integer port = null;
    // This is where we would normally grab the host and port for the instance metrics from the MemcachedNode
    // instrumentation. But for a bulk operation like this one, this would be incorrect, because the bulk operation
    // can send off a whole bunch of operations to multiple memcached servers, while this logic is only capable of
    // capturing instance information for one of them. Tracked by JAVA-2640.
    // Let's clear the thread local despite the fact that we didn't use it.
    MemcachedUtil.OPERATION_NODE.set(null);
    if (AgentBridge.getAgent().getTransaction(false) != null) {
        final Segment segment = NewRelic.getAgent().getTransaction().startSegment(op);
        ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
        segment.reportAsExternal(params);
        if (future.isDone()) {
            segment.endAsync();
        } else {
            future.addListener(new BulkGetCompletionListener(segment));
        }
    }
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) Segment(com.newrelic.api.agent.Segment)

Example 4 with ExternalParameters

use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testNoPortSupportabilityMetrics.

@Test
public void testNoPortSupportabilityMetrics() {
    DefaultTracer tracer = prepareTracer();
    String product = "Product";
    ExternalParameters parameters = DatastoreParameters.product(product).collection("Collection").operation("operation").instance("myHost", 12345).databaseName("databaseName").build();
    tracer.reportAsExternal(parameters);
    tracer.finish(0, null);
    checkUnknownDatastoreSupportabilityMetrics("Product", 0, 0, 0);
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) Test(org.junit.Test)

Example 5 with ExternalParameters

use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method testAllSupportabilityMetrics.

@Test
public void testAllSupportabilityMetrics() {
    DefaultTracer tracer = prepareTracer();
    String unknownPort = null;
    String unknownHost = null;
    String product = "Product";
    ExternalParameters parameters = DatastoreParameters.product(product).collection("Collection").operation("operation").instance(unknownHost, unknownPort).noDatabaseName().build();
    tracer.reportAsExternal(parameters);
    tracer.finish(0, null);
    checkUnknownDatastoreSupportabilityMetrics("Product", 1, 1, 1);
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) Test(org.junit.Test)

Aggregations

ExternalParameters (com.newrelic.api.agent.ExternalParameters)23 Test (org.junit.Test)12 AgentConfig (com.newrelic.agent.config.AgentConfig)8 TokenNullCheckClassVisitor (com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessors.TokenNullCheckClassVisitor)8 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)8 SlowQueryDatastoreParameters (com.newrelic.api.agent.SlowQueryDatastoreParameters)8 SlowQueryWithInputDatastoreParameters (com.newrelic.api.agent.SlowQueryWithInputDatastoreParameters)8 HashMap (java.util.HashMap)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 ClassVisitor (org.objectweb.asm.ClassVisitor)8 ClassNode (org.objectweb.asm.tree.ClassNode)8 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)8 Trace (com.newrelic.api.agent.Trace)7 URISyntaxException (java.net.URISyntaxException)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 Tracer (com.newrelic.agent.tracers.Tracer)3 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)3 Segment (com.newrelic.api.agent.Segment)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2