
com.newrelic.agent.instrumentation.yaml.PointCutFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of newrelic-agent Show documentation
Show all versions of newrelic-agent Show documentation
Jar required to run with a java application to monitor performance.
The newest version!
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.instrumentation.yaml;
import com.newrelic.agent.Agent;
import com.newrelic.agent.MetricNames;
import com.newrelic.agent.extension.ConfigurationConstruct;
import com.newrelic.agent.instrumentation.classmatchers.ClassMatcher;
import com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher;
import com.newrelic.agent.instrumentation.classmatchers.OrClassMatcher;
import com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher;
import com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher;
import com.newrelic.agent.instrumentation.methodmatchers.InvalidMethodDescriptor;
import com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher;
import com.newrelic.agent.instrumentation.methodmatchers.NoMethodsMatcher;
import com.newrelic.agent.instrumentation.methodmatchers.OrMethodMatcher;
import com.newrelic.agent.tracers.ClassMethodSignature;
import com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat;
import com.newrelic.agent.tracers.metricname.MetricNameFormat;
import com.newrelic.agent.util.Strings;
import org.apache.commons.lang3.StringUtils;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
public class PointCutFactory {
private final String defaultMetricPrefix;
private final ClassLoader classLoader;
private final String extensionName;
public static class ClassMethodNameFormatDescriptor implements MetricNameFormatFactory {
private final String prefix;
public ClassMethodNameFormatDescriptor(final String prefix, boolean dispatcher) {
this.prefix = getMetricPrefix(prefix, dispatcher);
}
@Override
public MetricNameFormat getMetricNameFormat(ClassMethodSignature sig, Object object, Object[] args) {
if (StringUtils.isEmpty(prefix)) {
return new ClassMethodMetricNameFormat(sig, object);
} else {
return new ClassMethodMetricNameFormat(sig, object, prefix);
}
}
private static String getMetricPrefix(String prefix, boolean dispatcher) {
if (dispatcher) {
if (prefix.startsWith(MetricNames.OTHER_TRANSACTION)) {
return prefix;
} else {
return MetricNames.OTHER_TRANSACTION + '/' + prefix;
}
} else {
return prefix;
}
}
}
public PointCutFactory(ClassLoader classLoader, String metricPrefix, String name) {
this.classLoader = classLoader;
defaultMetricPrefix = metricPrefix;
extensionName = name;
}
@SuppressWarnings("unchecked")
public Collection getPointCuts(Object config) throws ParseException {
if (config instanceof List) {
return getPointCuts((List) config);
} else if (config instanceof Map) {
return getPointCuts((Map) config);
}
return Collections.EMPTY_LIST;
}
public ExtensionClassAndMethodMatcher getPointCut(Object obj) throws ParseException {
if (obj instanceof String) {
return getPointCut((String) obj);
} else if (obj instanceof Map) {
return getPointCut((Map) obj);
} else {
throw new RuntimeException(MessageFormat.format("Unknown pointcut type: {0} ({1}", obj,
obj.getClass().getName()));
}
}
public ExtensionClassAndMethodMatcher getPointCut(String string) throws ParseException {
ClassMethodSignature sig = parseClassMethodSignature(string);
if (sig != null) {
return new ExtensionClassAndMethodMatcher(extensionName, null, defaultMetricPrefix, new ExactClassMatcher(
sig.getClassName()), createExactMethodMatcher(sig.getMethodName(), sig.getMethodDesc()), false,
false, false, false, null);
}
throw new RuntimeException("Unable to parse point cut: " + string);
}
private ExtensionClassAndMethodMatcher getPointCut(Map attrs) {
return YmlExtensionPointCutConverter.createExtensionPointCut(attrs, defaultMetricPrefix, classLoader,
extensionName);
}
public List getPointCuts(List list) throws ParseException {
List pcs = new ArrayList<>();
for (Object obj : list) {
pcs.add(getPointCut(obj));
}
return pcs;
}
@SuppressWarnings("unchecked")
public List getPointCuts(Map namesToPointCuts) throws ParseException {
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy