Skip to content

Commit

Permalink
Add metrics API example to spring boot demo app (#3253)
Browse files Browse the repository at this point in the history
* Add metrics timing example to spring boot demo app

* Extend metrics sample code to other backend projects
  • Loading branch information
markushi committed Mar 8, 2024
1 parent 8fba9ca commit f5e1b97
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ Person create(Person person) {
span.setMeasurement("create_count", createCount);
}

jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
person.getLastName());
Sentry.metrics()
.timing(
"person.insert",
() -> {
jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
person.getLastName());
});

return person;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sentry.debug=true
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enable-metrics=true
sentry.enablePrettySerializationOutput=false
in-app-includes="io.sentry.samples"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public class PersonService {
Mono<Person> create(Person person) {
return Mono.delay(Duration.ofMillis(100))
.publishOn(Schedulers.boundedElastic())
.doOnNext(__ -> Sentry.captureMessage("Creating person"))
.doOnNext(
__ -> {
Sentry.metrics()
.timing(
"person.insert",
() -> {
Sentry.captureMessage("Creating person");
});
})
.map(__ -> person);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ sentry.logging.minimum-breadcrumb-level=debug
sentry.reactive.thread-local-accessor-enabled=true
sentry.enable-tracing=true
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enable-metrics=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public class PersonService {
Mono<Person> create(Person person) {
return Mono.delay(Duration.ofMillis(100))
.publishOn(Schedulers.boundedElastic())
.doOnNext(__ -> Sentry.captureMessage("Creating person"))
.doOnNext(
__ ->
Sentry.metrics()
.timing(
"person.insert",
() -> {
Sentry.captureMessage("Creating person");
}))
.map(__ -> person);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ spring.graphql.graphiql.enabled=true
spring.graphql.websocket.path=/graphql
spring.graphql.schema.printer.enabled=true
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enable-metrics=true
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ Person create(Person person) {
span.setMeasurement("create_count", createCount);
}

jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
person.getLastName());
Sentry.metrics()
.timing(
"person.insert",
() -> {
jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
person.getLastName());
});
return person;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sentry.ignored-checkins=ignored_monitor_slug_1,ignored_monitor_slug_2
sentry.debug=true
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enable-metrics=true
in-app-includes="io.sentry.samples"

# Database configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.jakarta.web;

import io.sentry.Sentry;
import io.sentry.spring.jakarta.tracing.SentrySpan;
import java.util.Map;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -29,10 +30,16 @@ Person find(Long id) {

@SentrySpan
Person create(Person person) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
Sentry.metrics()
.timing(
"person.insert",
() -> {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignored
}
});
return person;
}
}

0 comments on commit f5e1b97

Please sign in to comment.