Skip to content

Commit

Permalink
Added Jetty reference doc (#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jan 19, 2024
1 parent c3e51b6 commit 4848e4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ asciidoc:
include-java: 'example$docs-src/test/java/io/micrometer/docs'
include-resources: 'example$docs-src/test/resources'
include-core-test-java: 'example$core-test'
include-micrometer-test-java: 'example$micrometer-test'
1 change: 1 addition & 0 deletions docs/modules/ROOT/examples/micrometer-test
17 changes: 16 additions & 1 deletion docs/modules/ROOT/pages/reference/jetty.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[[overview]]
= Eclipse Jetty and Jersey Instrumentation

Micrometer supports binding metrics to `Jetty` through `Connection.Listener`.

You can collect metrics from `Jetty` by adding `JettyConnectionMetrics` as follows:
Expand All @@ -23,4 +26,16 @@ resourceConfig.register(new MetricsApplicationEventListener(
"http.server.requests",
true));
ServletContainer servletContainer = new ServletContainer(resourceConfig);
----
----

[[overview-observation]]
== Eclipse Observation Jersey Instrumentation

Below you can find an example of how to instrument Jersey with https://docs.micrometer.io/micrometer/reference/observation.html[Micrometer Observation]. That means that depending on your Observation Handler configuration you instrument once, and can have multiple benefits out of it (e.g. metrics, distributed tracing).

[source,java,subs=+attributes]
-----
// Setting up instrumentation
include::{include-micrometer-test-java}/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java[tags=setup, indent=0]
include::{include-micrometer-test-java}/io/micrometer/core/instrument/JerseyServerTimingInstrumentationVerificationTests.java[tags=setup_2, indent=0]
-----
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ protected URI startInstrumentedWithMetricsServer() throws Exception {
@Nullable
@Override
protected URI startInstrumentedWithObservationsServer() throws Exception {
jerseyTest = jerseyWithListener(new ObservationApplicationEventListener(getObservationRegistry(), timerName()));
jerseyTest = jerseyWithListener(
// tag::setup[]
new ObservationApplicationEventListener(getObservationRegistry(), timerName())
// end::setup[]
);
return setupUri(jerseyTest);
}

Expand All @@ -57,8 +61,10 @@ private JerseyTest jerseyWithListener(Object listener) {
return new JerseyTest() {
@Override
protected Application configure() {
// tag::setup_2[]
ResourceConfig config = new ResourceConfig();
config.register(listener);
// end::setup_2[]
config.register(TestResource.class);
return config;
}
Expand Down

0 comments on commit 4848e4d

Please sign in to comment.