-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EL Expression is not working with @Metrics annotation #20
Comments
What exception do you have? Note that you need to add an EL implementation as dependency, e.g., There is a unit test that cover that use case so I would expect it to work: https://github.com/astefanutti/metrics-aspectj/blob/ec21a065e5accf7a34489a3ec5dcc10ebcd4689b/envs/el/src/test/java/io/astefanutti/metrics/aspectj/el/TimedMethodWithRegistryFromBeanPropertyTest.java. |
Thanks for a prompt reply! Here is the exception I get when I do
|
You need to have a getter method declared in your class for it to be a valid bean property, see: Line 31 in ec21a06
|
I have a public `@metrics(registry = "${ this.registry }") public TimedMethodImplicit(MetricRegistry reg) { public MetricRegistry getRegistry(){return this.registry;} @timed(name = "randomTimeTask") |
Could you try with the |
Have you been able to work this out? |
No its not working |
In gradle example Instead of using registry name I chose to use EL Expression ${this.registry} and program started throwing exceptions. Below is the code:
`package com;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import com.codahale.metrics.SharedMetricRegistries;
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Timer;
import com.codahale.metrics.annotation.Timed;
import javax.el.ELProcessor;
import io.astefanutti.metrics.aspectj.Metrics;
// ~minimal App using metrics-aspectj
public class App {
}
// this interface is not strictly necessary, but was added to make the toggling
// of explicit profiling easier.
//
// the class TimedMethodImplicit matches the ease of implementation for metrics
// that is documented and made possible by metrics-aspectj.
interface ITimedMethod {
public void randomTimeTask() throws InterruptedException;
}
class TimedMethod implements ITimedMethod {
// to use the same metric registry when explicitly (read: cross-cuttingly)
// profiling the App as well as when implicitly (read: aspect-oriented-ly)
// profiling the App, here for the explicit case, get or create
// (read: ~singleton) the metric registry using the same name as is used for
// the implicit case. FYI the default name for the implicit case is
// "metrics-registry".
private static final MetricRegistry metrics =
SharedMetricRegistries.getOrCreate("reg");
}
@metrics(registry = "${ this.registry }")
class TimedMethodImplicit implements ITimedMethod {
private final Random rand = new Random();
private final MetricRegistry registry;
}
@metrics(registry = "reg")
class TimedMethodNop implements ITimedMethod {
@timed
public void randomTimeTask() throws InterruptedException { }
}
class TimedMethodExplicit implements ITimedMethod {
private final MetricRegistry metrics;
private final Timer timer;
}
`
The text was updated successfully, but these errors were encountered: