Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public static void main(String[] args) throws InterruptedException {

Sentry.addFeatureFlag("my-feature-flag", true);

captureMetrics();

// Sending exception:
Exception exception = new RuntimeException("Some error!");
Sentry.captureException(exception);
Expand Down Expand Up @@ -136,6 +138,12 @@ public static void main(String[] args) throws InterruptedException {
// Sentry.close();
}

private static void captureMetrics() {
Sentry.metrics().count("countMetric");
Sentry.metrics().gauge("gaugeMetric", 5.0);
Sentry.metrics().distribution("distributionMetric", 7.0);
}

private static class SomeEventProcessor implements EventProcessor {
@Override
public SentryEvent process(SentryEvent event, Hint hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,11 @@ class ConsoleApplicationSystemTest {
breadcrumb.message?.contains("Processed by") == true
} == true
}

testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public static void main(String[] args) throws InterruptedException {

Sentry.addFeatureFlag("my-feature-flag", true);

captureMetrics();

// Sending exception:
Exception exception = new RuntimeException("Some error!");
Sentry.captureException(exception);
Expand Down Expand Up @@ -187,6 +189,12 @@ public static void main(String[] args) throws InterruptedException {
// Sentry.close();
}

private static void captureMetrics() {
Sentry.metrics().count("countMetric");
Sentry.metrics().gauge("gaugeMetric", 5.0);
Sentry.metrics().distribution("distributionMetric", 7.0);
}

private static class SomeEventProcessor implements EventProcessor {
@Override
public SentryEvent process(SentryEvent event, Hint hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,11 @@ class ConsoleApplicationSystemTest {
breadcrumb.message?.contains("Processed by") == true
} == true
}

testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.sentry.samples.spring7.web;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/metric/")
public class MetricController {
private static final Logger LOGGER = LoggerFactory.getLogger(MetricController.class);

@GetMapping("count")
String count() {
Sentry.metrics().count("countMetric");
return "count metric increased";
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.sentry.systemtest

import io.sentry.systemtest.util.TestHelper
import kotlin.test.Test
import kotlin.test.assertEquals
import org.junit.Before

class MetricsSystemTest {
lateinit var testHelper: TestHelper

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper.reset()
}

@Test
fun `count metric`() {
val restClient = testHelper.restClient
assertEquals("count metric increased", restClient.getCountMetric())
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
}
}

@Test
fun `gauge metric`() {
val restClient = testHelper.restClient
assertEquals("gauge metric tracked", restClient.getGaugeMetric(14))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "memory.free", "gauge", 14.0)
}
}

@Test
fun `distribution metric`() {
val restClient = testHelper.restClient
assertEquals("distribution metric tracked", restClient.getDistributionMetric(23))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "distributionMetric", "distribution", 23.0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.sentry.samples.spring.boot4;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/metric/")
public class MetricController {
private static final Logger LOGGER = LoggerFactory.getLogger(MetricController.class);

@GetMapping("count")
String count() {
Sentry.metrics().count("countMetric");
return "count metric increased";
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.sentry.systemtest

import io.sentry.systemtest.util.TestHelper
import kotlin.test.Test
import kotlin.test.assertEquals
import org.junit.Before

class MetricsSystemTest {
lateinit var testHelper: TestHelper

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper.reset()
}

@Test
fun `count metric`() {
val restClient = testHelper.restClient
assertEquals("count metric increased", restClient.getCountMetric())
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
}
}

@Test
fun `gauge metric`() {
val restClient = testHelper.restClient
assertEquals("gauge metric tracked", restClient.getGaugeMetric(14))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "memory.free", "gauge", 14.0)
}
}

@Test
fun `distribution metric`() {
val restClient = testHelper.restClient
assertEquals("distribution metric tracked", restClient.getDistributionMetric(23))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "distributionMetric", "distribution", 23.0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.sentry.samples.spring.boot4;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/metric/")
public class MetricController {
private static final Logger LOGGER = LoggerFactory.getLogger(MetricController.class);

@GetMapping("count")
String count() {
Sentry.metrics().count("countMetric");
return "count metric increased";
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.sentry.systemtest

import io.sentry.systemtest.util.TestHelper
import kotlin.test.Test
import kotlin.test.assertEquals
import org.junit.Before

class MetricsSystemTest {
lateinit var testHelper: TestHelper

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper.reset()
}

@Test
fun `count metric`() {
val restClient = testHelper.restClient
assertEquals("count metric increased", restClient.getCountMetric())
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "countMetric", "counter", 1.0)
}
}

@Test
fun `gauge metric`() {
val restClient = testHelper.restClient
assertEquals("gauge metric tracked", restClient.getGaugeMetric(14))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "memory.free", "gauge", 14.0)
}
}

@Test
fun `distribution metric`() {
val restClient = testHelper.restClient
assertEquals("distribution metric tracked", restClient.getDistributionMetric(23))
assertEquals(200, restClient.lastKnownStatusCode)

Thread.sleep(10000)

testHelper.ensureMetricsReceived { event, header ->
testHelper.doesContainMetric(event, "distributionMetric", "distribution", 23.0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.sentry.samples.spring.boot4;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/metric/")
public class MetricController {
private static final Logger LOGGER = LoggerFactory.getLogger(MetricController.class);

@GetMapping("count")
String count() {
Sentry.metrics().count("countMetric");
return "count metric increased";
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
}
Loading
Loading