-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opentelemetry-spring-boot-starterで事足りるっぽい。ただJVMのメトリクスを取るにはmicrometer-…
…registry-otlpが必要っぽいかな?
- Loading branch information
1 parent
609b86b
commit 8a85050
Showing
5 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
package com.example; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.stream.IntStream; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import io.opentelemetry.instrumentation.annotations.WithSpan; | ||
|
||
@Component | ||
public class Dice { | ||
|
||
@WithSpan | ||
public List<Integer> rollTheDice(int rolls) { | ||
return IntStream.range(0, rolls).map(a -> rollOnce()).boxed().toList(); | ||
} | ||
|
||
private int rollOnce() { | ||
return ThreadLocalRandom.current().nextInt(1, 7); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
telemetry-example/src/main/java/com/example/DiceController.java
This file contains 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,33 @@ | ||
package com.example; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class DiceController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private final Dice dice; | ||
|
||
public DiceController(Dice dice) { | ||
this.dice = dice; | ||
} | ||
|
||
@GetMapping("/rolldice") | ||
public List<Integer> rolldice(@RequestParam(required = false) String player, | ||
@RequestParam int rolls) { | ||
List<Integer> result = dice.rollTheDice(rolls); | ||
if (player != null) { | ||
logger.info("{} is rolling the dice: {}", player, result); | ||
} else { | ||
logger.info("Anonymous player is rolling the dice: {}", result); | ||
} | ||
return result; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
spring.application.name=telemetry-example | ||
|
||
management.tracing.sampling.probability=1.0 | ||
# management.otlp.metrics.export.url=http://localhost:4318/v1/metrics | ||
management.otlp.tracing.endpoint=http://localhost:4318/v1/traces | ||
otel.exporter.otlp.traces.endpoint=http://localhost:4318/v1/traces | ||
otel.exporter.otlp.metrics.endpoint=http://localhost:4318/v1/metrics | ||
otel.exporter.otlp.logs.endpoint=http://localhost:4318/v1/logs |