Skip to content
Open
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 @@ -53,6 +53,7 @@ class LogboekInterceptor {

val annotation = context.method.getAnnotation(Logboek::class.java)
val name = annotation.name
require(name.isNotEmpty()) { "Span name is required by the LDV standard" }
val processingActivityId = annotation.processingActivityId

val span = handler.startSpan(name, traceContext)
Expand All @@ -68,10 +69,10 @@ class LogboekInterceptor {
if (headers.getHeaderString("traceparent") != null) {
//todo hoe krijgen we de url, bijv. header. Hier is het team van LDV nog mee bezig.
//todo How do we get the url, ex. header. This is still being worked on by the LDV team.
span.setAttribute(
"dpl.core.foreign_operation.processor",
headers.getHeaderString("traceparent-processor")
)
val processor = headers.getHeaderString("traceparent-processor")
?: headers.getHeaderString("Origin")
?: "onbekend"
span.setAttribute("dpl.core.foreign_operation.processor", processor)
}

logboekContext.processingActivityId = processingActivityId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ internal class LogboekInterceptorTest {
private class AnnotatedMethods {
@Logboek(name = "test-span", processingActivityId = "https://register.example.org/activiteiten/activity-123")
fun testMethod() {}

@Logboek(processingActivityId = "https://register.example.org/activiteiten/activity-123")
fun emptyNameMethod() {}
}

private fun getAnnotatedMethod(): Method {
return AnnotatedMethods::class.java.getDeclaredMethod("testMethod")
}

private fun getEmptyNameMethod(): Method {
return AnnotatedMethods::class.java.getDeclaredMethod("emptyNameMethod")
}

@Nested
@DisplayName("log interceptor method")
inner class LogMethodTests {
Expand Down Expand Up @@ -166,6 +173,18 @@ internal class LogboekInterceptorTest {
verify { mockSpan.end() }
}

@Test
fun `Throws when span name is empty`() {
// given
val mockMethod = getEmptyNameMethod()
every { mockInvocationContext.method } returns mockMethod

// when / then
assertThrows<IllegalArgumentException> {
interceptor.log(mockInvocationContext)
}
}

@Test
fun `Returns null when method returns null`() {
// given
Expand Down Expand Up @@ -201,6 +220,40 @@ internal class LogboekInterceptorTest {
verify { mockSpan.setAttribute("dpl.core.foreign_operation.processor", "http://processor.example.com") }
}

@Test
fun `Falls back to Origin header when traceparent-processor absent`() {
// given
val mockMethod = getAnnotatedMethod()
every { mockInvocationContext.method } returns mockMethod
every { mockInvocationContext.proceed() } returns "result"
every { mockHeaders.getHeaderString("traceparent") } returns "00-trace-id-span-id-01"
every { mockHeaders.getHeaderString("traceparent-processor") } returns null
every { mockHeaders.getHeaderString("Origin") } returns "https://api.andere-organisatie.nl"

// when
interceptor.log(mockInvocationContext)

// then
verify { mockSpan.setAttribute("dpl.core.foreign_operation.processor", "https://api.andere-organisatie.nl") }
}

@Test
fun `Falls back to onbekend when both headers absent`() {
// given
val mockMethod = getAnnotatedMethod()
every { mockInvocationContext.method } returns mockMethod
every { mockInvocationContext.proceed() } returns "result"
every { mockHeaders.getHeaderString("traceparent") } returns "00-trace-id-span-id-01"
every { mockHeaders.getHeaderString("traceparent-processor") } returns null
every { mockHeaders.getHeaderString("Origin") } returns null

// when
interceptor.log(mockInvocationContext)

// then
verify { mockSpan.setAttribute("dpl.core.foreign_operation.processor", "onbekend") }
}

@Test
fun `Does not set foreign operation attributes when traceparent header absent`() {
// given
Expand Down
Loading