@Advice.OnMethodExit private static void addReflectiveMonitorMethodCall(@Advice.This Object dataSource, @Advice.Return(readOnly = false) Connection connection, @Advice.Enter long startTime) { try { Object[] connectionMonitor = (Object[]) ((ThreadLocal) Dispatcher.getValues().get("org.stagemonitor.jdbc.ConnectionMonitor")).get(); if (connectionMonitor != null) { final Method connectionMonitorMethod = (Method) connectionMonitor[1]; final long duration = System.nanoTime() - startTime; // In JBoss, this method is executed in the context of the module class loader which loads the DataSource // The connectionMonitor is not accessible from this class loader. That's why we have to use reflection. connection = (Connection) connectionMonitorMethod.invoke(connectionMonitor[0], connection, dataSource, duration); } } catch (Exception e) { e.printStackTrace(); } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Return> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot write return value for " + target + " in read-only context"); } else { return new ForReturnValue(target.getType(), annotation.loadSilent()); } } }
@OnMethodExit(onThrowable = Throwable.class) public static void after( @Enter List<Object> hooks, @This(optional = true) Object that, @Origin Method method, @AllArguments Object[] args, @Return(typing = Assigner.Typing.DYNAMIC) Object returned, // support void == null and int == Integer @Thrown Throwable thrown ) { try { // The following code is equivalent to: // Delegator.after(hooks, method, args); // However, the Delegator class will not be available in the context of the instrumented method, // so we must use our agent class loader to load the Delegator class and do the call via reflection. Class<?> delegator = ClassLoaderCache.getInstance().currentClassLoader().loadClass("io.promagent.internal.Delegator"); Method afterMethod = delegator.getMethod("after", List.class, Method.class, Object[].class, Object.class, Throwable.class); afterMethod.invoke(null, hooks, method, args, returned, thrown); } catch (Exception e) { Class<?> clazz = that != null ? that.getClass() : method.getDeclaringClass(); System.err.println("Error executing Prometheus hook on " + clazz.getSimpleName()); e.printStackTrace(); } } }
@SuppressWarnings({"unchecked", "RedundantThrows"}) @Advice.OnMethodExit(onThrowable = Throwable.class) static void onMethodExit( @Advice.Local("exec") MethodExecution.Implementation exec, @Advice.Local("event") MethodEvent event, @Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object returned, @Advice.Thrown(readOnly = false, typing = Assigner.Typing.DYNAMIC) Throwable thrown, @Advice.Enter boolean skipped ) throws Throwable { if (event == null) return; if (!skipped) { event.returned = returned; event.thrown = thrown; } exec._exit.accept(event); //noinspection UnusedAssignment returned = event.returned; //noinspection UnusedAssignment thrown = event.thrown; } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param queryState query state information * @param options query options * @param result intercepted method's execution result * @param preparedStatements QueryProcessor's internal list of prepared statements */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) CQLStatement statement, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result, @Advice.FieldValue(value = "preparedStatements") ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements) { ConnectorImpl.queryProcessorWrapper() .processPrepared(statement, queryState, options, startTime, result, preparedStatements); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param queryState query state information * @param options query options * @param result intercepted method's execution result * @param preparedStatements QueryProcessor's internal list of prepared statements */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) CQLStatement statement, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result, @Advice.FieldValue(value = "preparedStatements") ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements) { ConnectorImpl.queryProcessorWrapper() .processPrepared(statement, queryState, options, startTime, result, preparedStatements); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param queryState query state information * @param options query options * @param result intercepted method's execution result * @param preparedStatements QueryProcessor's internal list of prepared statements */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) CQLStatement statement, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result, @Advice.FieldValue(value = "preparedStatements") ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements) { ConnectorImpl.queryProcessorWrapper() .processPrepared(statement, queryState, options, startTime, result, preparedStatements); } }
@Advice.OnMethodExit static void $$_hibernate_getDirtyAttributes( @Advice.This ExtendedSelfDirtinessTracker self, @Advice.Return(readOnly = false) String[] returned, @Advice.FieldValue(value = EnhancerConstants.TRACKER_FIELD_NAME, readOnly = false) DirtyTracker $$_hibernate_tracker, @Advice.FieldValue(value = EnhancerConstants.TRACKER_COLLECTION_NAME, readOnly = false) CollectionTracker $$_hibernate_collectionTracker) { if ( $$_hibernate_collectionTracker == null ) { returned = ( $$_hibernate_tracker == null ) ? new String[0] : $$_hibernate_tracker.get(); } else { if ( $$_hibernate_tracker == null ) { $$_hibernate_tracker = new SimpleFieldTracker(); } self.$$_hibernate_getCollectionFieldDirtyNames( $$_hibernate_tracker ); returned = $$_hibernate_tracker.get(); } } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param queryState query state information * @param options query options * @param result intercepted method's execution result * @param preparedStatements QueryProcessor's internal list of prepared statements */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) CQLStatement statement, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result, @Advice.FieldValue(value = "preparedStatements") ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements) { ConnectorImpl.queryProcessorWrapper() .processPrepared(statement, queryState, options, startTime, result, preparedStatements); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param queryString CQL query string * @param queryState query state information * @param options query options * @param result intercepted method's execution result */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) String queryString, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result) { ConnectorImpl.queryProcessorWrapper() .process(queryString, queryState, options, startTime, result); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param queryString CQL query string * @param queryState query state information * @param options query options * @param result intercepted method's execution result */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) String queryString, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result) { ConnectorImpl.queryProcessorWrapper() .process(queryString, queryState, options, startTime, result); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param queryString CQL query string * @param queryState query state information * @param options query options * @param result intercepted method's execution result */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) String queryString, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result) { ConnectorImpl.queryProcessorWrapper() .process(queryString, queryState, options, startTime, result); } }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param queryString CQL query string * @param queryState query state information * @param options query options * @param result intercepted method's execution result */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) String queryString, @Advice.Argument(1) QueryState queryState, @Advice.Argument(2) QueryOptions options, @Advice.Return ResultMessage result) { ConnectorImpl.queryProcessorWrapper() .process(queryString, queryState, options, startTime, result); } }
@Advice.OnMethodExit static void $$_hibernate_areCollectionFieldsDirty( @Advice.Return(readOnly = false) boolean returned, @FieldName String fieldName, @FieldValue Map<?, ?> map, @Advice.FieldValue(EnhancerConstants.TRACKER_COLLECTION_NAME) CollectionTracker $$_hibernate_collectionTracker) { if ( !returned && $$_hibernate_collectionTracker != null ) { if ( map == null && $$_hibernate_collectionTracker.getSize( fieldName ) != -1 ) { returned = true; } else if ( map != null && $$_hibernate_collectionTracker.getSize( fieldName ) != map.size() ) { returned = true; } } } }
@Advice.OnMethodExit static void $$_hibernate_areCollectionFieldsDirty( @Advice.Return(readOnly = false) boolean returned, @FieldName String fieldName, @FieldValue Collection<?> collection, @Advice.FieldValue(EnhancerConstants.TRACKER_COLLECTION_NAME) CollectionTracker $$_hibernate_collectionTracker) { if ( !returned && $$_hibernate_collectionTracker != null ) { if ( collection == null && $$_hibernate_collectionTracker.getSize( fieldName ) != -1 ) { returned = true; } else if ( collection != null && $$_hibernate_collectionTracker.getSize( fieldName ) != collection.size() ) { returned = true; } } } }
@Advice.OnMethodExit private static void addReflectiveMonitorMethodCall(@Advice.This Object dataSource, @Advice.Return(readOnly = false) Connection connection, @Advice.Enter long startTime) { try { Object[] connectionMonitor = (Object[]) ((ThreadLocal) Dispatcher.getValues().get("org.stagemonitor.jdbc.ConnectionMonitor")).get(); if (connectionMonitor != null) { final Method connectionMonitorMethod = (Method) connectionMonitor[1]; final long duration = System.nanoTime() - startTime; // In JBoss, this method is executed in the context of the module class loader which loads the DataSource // The connectionMonitor is not accessible from this class loader. That's why we have to use reflection. connection = (Connection) connectionMonitorMethod.invoke(connectionMonitor[0], connection, dataSource, duration); } } catch (Exception e) { e.printStackTrace(); } }
@Advice.OnMethodExit public static void onMethodExit(@Advice.Return(readOnly = false) int returnValue) { returnValue = 42; }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param result CQL result future */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) Statement statement, @Advice.Return ResultSetFuture result) { ConnectorImpl.executeStatementWrapper().processStatement(statement, startTime, result); } }
@Advice.OnMethodExit public static void onMethodExit(@Advice.Return(readOnly = false) String returnValue) { returnValue = "intercepted"; }
@Advice.OnMethodExit public static void afterGetHandler(@Advice.Return Object handler) { SpringMvcRequestNameDeterminerTransformer.setRequestNameByHandler(handler); }