Search in sources :

Example 1 with TaggedMetricsServiceInvocationEventHandler

use of com.palantir.tritium.event.metrics.TaggedMetricsServiceInvocationEventHandler in project tritium by palantir.

the class InstrumentationBuilder method withTaggedMetrics.

/**
 * Supplies a TaggedMetricRegistry and a name prefix to be used across service invocations.
 *
 * <p>Uses a {@link TaggedMetricsServiceInvocationEventHandler} object for handling invocations, so metric names
 * are chosen based off of the interface name and invoked method.
 *
 * @param metricRegistry - TaggedMetricsRegistry used for this application.
 * @param prefix - Metrics name prefix to be used
 * @return - InstrumentationBuilder
 */
public InstrumentationBuilder<T, U> withTaggedMetrics(TaggedMetricRegistry metricRegistry, @Nullable String prefix) {
    checkNotNull(metricRegistry, "metricRegistry");
    String serviceName = prefix == null || prefix.isEmpty() ? interfaceClass.getName() : prefix;
    return withHandler(new TaggedMetricsServiceInvocationEventHandler(metricRegistry, serviceName));
}
Also used : TaggedMetricsServiceInvocationEventHandler(com.palantir.tritium.event.metrics.TaggedMetricsServiceInvocationEventHandler)

Example 2 with TaggedMetricsServiceInvocationEventHandler

use of com.palantir.tritium.event.metrics.TaggedMetricsServiceInvocationEventHandler in project tritium by palantir.

the class InstrumentationTest method testStackDepth_notFunctionOfHandlers.

@Test
void testStackDepth_notFunctionOfHandlers() {
    StackTraceSupplier stackTraceSupplier = () -> cleanStackTrace(new Exception().getStackTrace());
    StackTraceSupplier singleHandlerInstrumentedStackSupplier = Instrumentation.builder(StackTraceSupplier.class, stackTraceSupplier).withHandler(new TaggedMetricsServiceInvocationEventHandler(new DefaultTaggedMetricRegistry(), "test0")).build();
    StackTraceSupplier multipleHandlerInstrumentedStackSupplier = Instrumentation.builder(StackTraceSupplier.class, stackTraceSupplier).withHandler(new TaggedMetricsServiceInvocationEventHandler(new DefaultTaggedMetricRegistry(), "test1")).withHandler(new MetricsInvocationEventHandler(new MetricRegistry(), "test2")).build();
    StackTraceElement[] singleHandlerInstrumentedStackTrace = singleHandlerInstrumentedStackSupplier.get();
    StackTraceElement[] multipleHandlerInstrumentedStack = multipleHandlerInstrumentedStackSupplier.get();
    // Tritium frames should not scale with the number of registered InvocationEventHandler instances.
    assertThat(singleHandlerInstrumentedStackTrace).hasSameSizeAs(multipleHandlerInstrumentedStack);
}
Also used : TaggedMetricsServiceInvocationEventHandler(com.palantir.tritium.event.metrics.TaggedMetricsServiceInvocationEventHandler) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) MetricRegistry(com.codahale.metrics.MetricRegistry) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) MetricsInvocationEventHandler(com.palantir.tritium.event.metrics.MetricsInvocationEventHandler) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) Test(org.junit.jupiter.api.Test)

Aggregations

TaggedMetricsServiceInvocationEventHandler (com.palantir.tritium.event.metrics.TaggedMetricsServiceInvocationEventHandler)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)1 MetricsInvocationEventHandler (com.palantir.tritium.event.metrics.MetricsInvocationEventHandler)1 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)1 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)1 Test (org.junit.jupiter.api.Test)1