ChunkRootSpanTest.groovy 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. import static io.opentelemetry.api.trace.SpanKind.INTERNAL
  6. import static java.util.Collections.emptyMap
  7. import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
  8. import org.springframework.batch.core.JobParameter
  9. import org.springframework.context.ConfigurableApplicationContext
  10. import org.springframework.context.annotation.AnnotationConfigApplicationContext
  11. import org.springframework.context.support.ClassPathXmlApplicationContext
  12. abstract class ChunkRootSpanTest extends AgentInstrumentationSpecification {
  13. abstract runJob(String jobName, Map<String, JobParameter> params = emptyMap())
  14. def "should create separate traces for each chunk"() {
  15. when:
  16. runJob("itemsAndTaskletJob")
  17. then:
  18. assertTraces(5) {
  19. def itemStepSpan = null
  20. def taskletStepSpan = null
  21. trace(0, 3) {
  22. itemStepSpan = span(1)
  23. taskletStepSpan = span(2)
  24. span(0) {
  25. name "BatchJob itemsAndTaskletJob"
  26. kind INTERNAL
  27. }
  28. span(1) {
  29. name "BatchJob itemsAndTaskletJob.itemStep"
  30. kind INTERNAL
  31. childOf span(0)
  32. }
  33. span(2) {
  34. name "BatchJob itemsAndTaskletJob.taskletStep"
  35. kind INTERNAL
  36. childOf span(0)
  37. }
  38. }
  39. trace(1, 1) {
  40. span(0) {
  41. name "BatchJob itemsAndTaskletJob.itemStep.Chunk"
  42. kind INTERNAL
  43. hasLink itemStepSpan
  44. }
  45. }
  46. trace(2, 1) {
  47. span(0) {
  48. name "BatchJob itemsAndTaskletJob.itemStep.Chunk"
  49. kind INTERNAL
  50. hasLink itemStepSpan
  51. }
  52. }
  53. trace(3, 1) {
  54. span(0) {
  55. name "BatchJob itemsAndTaskletJob.itemStep.Chunk"
  56. kind INTERNAL
  57. hasLink itemStepSpan
  58. }
  59. }
  60. trace(4, 1) {
  61. span(0) {
  62. name "BatchJob itemsAndTaskletJob.taskletStep.Tasklet"
  63. kind INTERNAL
  64. hasLink taskletStepSpan
  65. }
  66. }
  67. }
  68. }
  69. }
  70. class JavaConfigChunkRootSpanTest extends ChunkRootSpanTest implements ApplicationConfigTrait {
  71. @Override
  72. ConfigurableApplicationContext createApplicationContext() {
  73. new AnnotationConfigApplicationContext(SpringBatchApplication)
  74. }
  75. }
  76. class XmlConfigChunkRootSpanTest extends ChunkRootSpanTest implements ApplicationConfigTrait {
  77. @Override
  78. ConfigurableApplicationContext createApplicationContext() {
  79. new ClassPathXmlApplicationContext("spring-batch.xml")
  80. }
  81. }
  82. class JsrConfigChunkRootSpanTest extends ChunkRootSpanTest implements JavaxBatchConfigTrait {
  83. }