-
-
Notifications
You must be signed in to change notification settings - Fork 467
feat(samples): [Cache Tracing 4] Add cache tracing e2e sample #5175
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
Open
adinauer
wants to merge
8
commits into
feat/cache-tracing-autoconfig
Choose a base branch
from
feat/cache-tracing-sample
base: feat/cache-tracing-autoconfig
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae0f569
feat(samples): [Cache Tracing 4] Add cache tracing e2e sample
adinauer cf3b325
ref(samples): Replace ConcurrentMapCacheManager with Caffeine
adinauer 7c54933
fix dependencies; move to toml
adinauer 1afb20e
Merge branch 'feat/cache-tracing-autoconfig' into feat/cache-tracing-…
adinauer d55c8fa
Merge branch 'feat/cache-tracing-autoconfig' into feat/cache-tracing-…
adinauer 1484b6b
Merge branch 'feat/cache-tracing-autoconfig' into feat/cache-tracing-…
adinauer 19eb28b
Merge branch 'feat/cache-tracing-autoconfig' into feat/cache-tracing-…
adinauer d2c83ac
Merge branch 'feat/cache-tracing-autoconfig' into feat/cache-tracing-…
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...y-samples-spring-boot-4/src/main/java/io/sentry/samples/spring/boot4/CacheController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package io.sentry.samples.spring.boot4; | ||
|
|
||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/cache/") | ||
| public class CacheController { | ||
| private final TodoService todoService; | ||
|
|
||
| public CacheController(TodoService todoService) { | ||
| this.todoService = todoService; | ||
| } | ||
|
|
||
| @GetMapping("{id}") | ||
| Todo get(@PathVariable Long id) { | ||
| return todoService.get(id); | ||
| } | ||
|
|
||
| @PostMapping | ||
| Todo save(@RequestBody Todo todo) { | ||
| return todoService.save(todo); | ||
| } | ||
|
|
||
| @DeleteMapping("{id}") | ||
| void delete(@PathVariable Long id) { | ||
| todoService.delete(id); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...entry-samples-spring-boot-4/src/main/java/io/sentry/samples/spring/boot4/TodoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package io.sentry.samples.spring.boot4; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import org.springframework.cache.annotation.CacheEvict; | ||
| import org.springframework.cache.annotation.CachePut; | ||
| import org.springframework.cache.annotation.Cacheable; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class TodoService { | ||
| private final Map<Long, Todo> store = new ConcurrentHashMap<>(); | ||
|
|
||
| @Cacheable(value = "todos", key = "#id") | ||
| public Todo get(Long id) { | ||
| return store.get(id); | ||
| } | ||
|
|
||
| @CachePut(value = "todos", key = "#todo.id") | ||
| public Todo save(Todo todo) { | ||
| store.put(todo.getId(), todo); | ||
| return todo; | ||
| } | ||
|
|
||
| @CacheEvict(value = "todos", key = "#id") | ||
| public void delete(Long id) { | ||
| store.remove(id); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ples/sentry-samples-spring-boot-4/src/test/kotlin/io/sentry/systemtest/CacheSystemTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package io.sentry.systemtest | ||
|
|
||
| import io.sentry.systemtest.util.TestHelper | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import org.junit.Before | ||
|
|
||
| class CacheSystemTest { | ||
| lateinit var testHelper: TestHelper | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| testHelper = TestHelper("http://localhost:8080") | ||
| testHelper.reset() | ||
| } | ||
|
|
||
| @Test | ||
| fun `cache put and get produce spans`() { | ||
| val restClient = testHelper.restClient | ||
|
|
||
| // Save a todo (triggers @CachePut -> cache.put span) | ||
| val todo = Todo(1L, "test-todo", false) | ||
| restClient.saveCachedTodo(todo) | ||
| assertEquals(200, restClient.lastKnownStatusCode) | ||
|
|
||
| testHelper.ensureTransactionReceived { transaction, _ -> | ||
| testHelper.doesTransactionContainSpanWithOp(transaction, "cache.put") | ||
| } | ||
|
|
||
| testHelper.reset() | ||
|
|
||
| // Get the todo (triggers @Cacheable -> cache.get span, should be a hit) | ||
| restClient.getCachedTodo(1L) | ||
| assertEquals(200, restClient.lastKnownStatusCode) | ||
|
|
||
| testHelper.ensureTransactionReceived { transaction, _ -> | ||
| testHelper.doesTransactionContainSpanWithOp(transaction, "cache.get") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `cache evict produces span`() { | ||
| val restClient = testHelper.restClient | ||
|
|
||
| restClient.deleteCachedTodo(1L) | ||
|
|
||
| testHelper.ensureTransactionReceived { transaction, _ -> | ||
| testHelper.doesTransactionContainSpanWithOp(transaction, "cache.remove") | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.