Skip to content

Commit

Permalink
Add example custom metrics to samples
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Sep 28, 2022
1 parent 018e0db commit f765bcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class MainActivity extends AppCompatActivity {

private int crashCount = 0;
private int screenLoadCount = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -200,8 +201,10 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();
screenLoadCount++;
final ISpan span = Sentry.getSpan();
if (span != null) {
span.setMeasurement("screen_load_count", screenLoadCount);
span.finish(SpanStatus.OK);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.sentry.samples.spring.boot;

import io.sentry.ISpan;
import io.sentry.Sentry;
import io.sentry.spring.tracing.SentrySpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -16,12 +18,19 @@ public class PersonService {
private static final Logger LOGGER = LoggerFactory.getLogger(PersonService.class);

private final JdbcTemplate jdbcTemplate;
private int createCount = 0;

public PersonService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

Person create(Person person) {
createCount++;
final ISpan span = Sentry.getSpan();
if (span != null) {
span.setMeasurement("create_count", createCount);
}

jdbcTemplate.update(
"insert into person (firstName, lastName) values (?, ?)",
person.getFirstName(),
Expand Down

0 comments on commit f765bcf

Please sign in to comment.