Example #1
0
 public static URL getClassResource(ClassLoader loader, String internalClassName) {
   if (loader == null) {
     loader = ClassLoader.getSystemClassLoader();
   }
   if ((Agent.LOG.isFinestEnabled()) && (internalClassName.endsWith(".class.class"))) {
     Agent.LOG.finest("Invalid resource name " + internalClassName);
   }
   URL url = loader.getResource(getClassResourceName(internalClassName));
   if (url == null) {
     url = BootstrapLoader.get().getBootstrapResource(internalClassName);
   }
   return url;
 }
 private static List<ExtensionClassAndMethodMatcher> convertToEnabledPointCuts(
     final Extension extension,
     final String extensionName,
     final Map<String, MethodMapper> classesToMethods,
     final boolean custom,
     final InstrumentationType type,
     final boolean isAttsEnabled) {
   final List<ExtensionClassAndMethodMatcher> pointCutsOut =
       new ArrayList<ExtensionClassAndMethodMatcher>();
   if (extension != null) {
     final String defaultMetricPrefix =
         createDefaultMetricPrefix(extension.getInstrumentation(), custom);
     final List<Extension.Instrumentation.Pointcut> inCuts =
         extension.getInstrumentation().getPointcut();
     if (inCuts != null && !inCuts.isEmpty()) {
       for (final Extension.Instrumentation.Pointcut cut : inCuts) {
         try {
           final ExtensionClassAndMethodMatcher pc =
               createPointCut(
                   extension,
                   cut,
                   defaultMetricPrefix,
                   extensionName,
                   classesToMethods,
                   custom,
                   type,
                   isAttsEnabled);
           if (pc == null) {
             continue;
           }
           logPointCutCreation(pc);
           pointCutsOut.add(pc);
         } catch (Exception e) {
           final String msg =
               MessageFormat.format(
                   "An error occurred reading in a pointcut in extension {0} : {1}",
                   extensionName, e.toString());
           Agent.LOG.log(Level.SEVERE, msg);
           Agent.LOG.log(Level.FINER, msg, e);
         }
       }
     } else {
       final String msg2 =
           MessageFormat.format("There were no point cuts in the extension {0}.", extensionName);
       Agent.LOG.log(Level.INFO, msg2);
     }
   }
   return pointCutsOut;
 }
Example #3
0
  private static MethodMatcher validateMethodMatcher(ExactMethodMatcher methodMatcher) {
    try {
      methodMatcher.validate();
      return methodMatcher;
    } catch (InvalidMethodDescriptor e) {
      Agent.LOG.log(
          Level.SEVERE,
          MessageFormat.format(
              "The method matcher can not be created, meaning the methods "
                  + "associated with it will not be monitored - {0}",
              new Object[] {e.toString()}));

      Agent.LOG.log(Level.FINER, "Error creating method matcher.", e);
    }
    return new NoMethodsMatcher();
  }
 private static List<ParameterAttributeName> getParameterAttributeNames(
     final List<Extension.Instrumentation.Pointcut.Method> methods) {
   final List<ParameterAttributeName> reportedParams =
       (List<ParameterAttributeName>) Lists.newArrayList();
   for (final Extension.Instrumentation.Pointcut.Method m : methods) {
     if (m.getParameters() != null && m.getParameters().getType() != null) {
       for (int i = 0; i < m.getParameters().getType().size(); ++i) {
         final Extension.Instrumentation.Pointcut.Method.Parameters.Type t =
             m.getParameters().getType().get(i);
         if (t.getAttributeName() != null) {
           try {
             final MethodMatcher methodMatcher =
                 MethodMatcherUtility.createMethodMatcher(
                     "DummyClassName", m, (Map<String, MethodMapper>) Maps.newHashMap(), "");
             final ParameterAttributeName reportedParam =
                 new ParameterAttributeName(i, t.getAttributeName(), methodMatcher);
             reportedParams.add(reportedParam);
           } catch (Exception e) {
             Agent.LOG.log(Level.FINEST, (Throwable) e, e.getMessage(), new Object[0]);
           }
         }
       }
     }
   }
   return reportedParams;
 }
 private static void logPointCutCreation(final ExtensionClassAndMethodMatcher pc) {
   final String msg =
       MessageFormat.format(
           "Extension instrumentation point: {0} {1}",
           pc.getClassMatcher(), pc.getMethodMatcher());
   Agent.LOG.finest(msg);
 }
    private void setTransactionName(Transaction transaction, String wildcardPath) {
      if (transaction.isTransactionNamingEnabled()) {
        TransactionNamingPolicy policy =
            TransactionNamingPolicy.getHigherPriorityTransactionNamingPolicy();
        if (Agent.LOG.isLoggable(Level.FINER)
            && policy.canSetTransactionName(transaction, TransactionNamePriority.FRAMEWORK)) {
          String msg =
              MessageFormat.format(
                  "Setting transaction name to \"{0}\" using Stuts wildcard",
                  new Object[] {wildcardPath});
          Agent.LOG.finer(msg);
        }

        policy.setTransactionName(
            transaction, wildcardPath, "Struts", TransactionNamePriority.FRAMEWORK);
      }
    }
Example #7
0
 public void addJmxMBeanGroup(final String name) {
   if (!this.addedJmx.containsKey(name)) {
     final JmxFrameworkValues jmx = this.getJmxFrameworkValues(name);
     if (null != jmx) {
       final Boolean alreadyAdded = this.addedJmx.putIfAbsent(name, Boolean.TRUE);
       if (null == alreadyAdded || !alreadyAdded) {
         ServiceFactory.getJmxService().addJmxFrameworkValues(jmx);
         Agent.LOG.log(Level.FINE, "Added JMX for {0}", new Object[] {jmx.getPrefix()});
       } else {
         Agent.LOG.log(
             Level.FINE, "Skipped JMX. Already added jmx framework: {0}", new Object[] {name});
       }
     } else {
       Agent.LOG.log(Level.FINE, "Skipped JMX. Unknown jmx framework: {0}", new Object[] {name});
     }
   }
 }
 public ReflectionStyleClassMethodAdapter(
     GenericClassAdapter genericClassAdapter,
     MethodVisitor mv,
     int access,
     Method method,
     int tracerFactoryId) {
   super(genericClassAdapter, mv, access, method);
   this.tracerFactoryId = tracerFactoryId;
   if (Agent.LOG.isFinestEnabled()) {
     Agent.LOG.finest(
         "Using fallback instrumentation on "
             + genericClassAdapter.className
             + "/"
             + methodName
             + methodDesc);
   }
 }
Example #9
0
 public Tracer doGetTracer(
     final Transaction transaction,
     final ClassMethodSignature sig,
     final Object call,
     final Object[] args) {
   try {
     final String endPoint =
         (String)
             call.getClass()
                 .getMethod("getTargetEndpointAddress", (Class<?>[]) new Class[0])
                 .invoke(call, new Object[0]);
     try {
       final URL url = new URL(endPoint);
       final String uri = InstrumentUtils.getURI(url);
       String methodName;
       if (sig == null) {
         methodName = "";
       } else {
         methodName = sig.getMethodName();
       }
       return new XmlRpcTracer(
           (PointCut) this,
           transaction,
           sig,
           call,
           url.getHost(),
           "XmlRpc",
           uri,
           new String[] {methodName});
     } catch (MalformedURLException e) {
       Agent.LOG.log(
           Level.FINE, "Unable to parse the target endpoint address for an XML RPC call", e);
     }
   } catch (Throwable e2) {
     Agent.LOG.log(
         Level.FINE, "Unable to get the target endpoint address for an XML RPC call", e2);
   }
   return null;
 }
    public StrutsActionConfigMatcherTracer(
        Transaction transaction, ClassMethodSignature sig, Object matcher, Object[] args) {
      super(sig, transaction);

      String msg;
      try {
        Object e = args[1];
        msg = (String) Invoker.invoke(e, e.getClass(), "getPath", new Object[0]);
        Agent.LOG.finer("Normalizing path using Struts wildcard");
        this.setTransactionName(transaction, msg);
      } catch (Exception var7) {
        msg =
            MessageFormat.format(
                "Exception in {0} handling {1}: {2}",
                new Object[] {StrutsActionConfigMatcherPointCut.class.getSimpleName(), sig, var7});
        if (Agent.LOG.isLoggable(Level.FINEST)) {
          Agent.LOG.log(Level.FINEST, msg, var7);
        } else {
          Agent.LOG.finer(msg);
        }
      }
    }
 public static List<ExtensionClassAndMethodMatcher> convertToEnabledPointCuts(
     final Collection<Extension> extensions,
     final boolean custom,
     final InstrumentationType type,
     final boolean isAttsEnabled) {
   final List<ExtensionClassAndMethodMatcher> pointCutsOut =
       new ArrayList<ExtensionClassAndMethodMatcher>();
   if (extensions != null) {
     final Map<String, MethodMapper> classesToMethods = new HashMap<String, MethodMapper>();
     for (final Extension ext : extensions) {
       if (ext.isEnabled()) {
         pointCutsOut.addAll(
             convertToEnabledPointCuts(
                 ext, ext.getName(), classesToMethods, custom, type, isAttsEnabled));
       } else {
         Agent.LOG.log(
             Level.WARNING,
             MessageFormat.format(
                 "Extension {0} is not enabled and so will not be instrumented.", ext.getName()));
       }
     }
   }
   return pointCutsOut;
 }