generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
02c42b3
commit 0a5f52e
Showing
48 changed files
with
170 additions
and
109 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
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
51 changes: 51 additions & 0 deletions
51
...ng/src/main/kotlin/uk/gov/justice/digital/hmpps/telemetry/TelemetryMessagingExtensions.kt
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,51 @@ | ||
package uk.gov.justice.digital.hmpps.telemetry | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.api.trace.SpanKind | ||
import io.opentelemetry.context.Context | ||
import io.opentelemetry.context.propagation.TextMapGetter | ||
import org.springframework.messaging.MessageHeaders | ||
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent | ||
import uk.gov.justice.digital.hmpps.message.MessageAttributes | ||
import uk.gov.justice.digital.hmpps.message.Notification | ||
|
||
object TelemetryMessagingExtensions { | ||
fun MessageHeaders.withSpanContext(): MessageHeaders { | ||
val map = this.toMutableMap() | ||
val context = Context.current().with(Span.current()) | ||
GlobalOpenTelemetry.getPropagators().textMapPropagator | ||
.inject(context, map) { carrier, key, value -> carrier!![key] = value } | ||
return MessageHeaders(map) | ||
} | ||
|
||
fun MessageAttributes.extractSpanContext(): Context { | ||
val getter = object : TextMapGetter<MessageAttributes> { | ||
override fun keys(carrier: MessageAttributes) = carrier.keys | ||
override fun get(carrier: MessageAttributes?, key: String) = carrier?.get(key)?.value | ||
} | ||
return GlobalOpenTelemetry.getPropagators().textMapPropagator.extract(Context.current(), this, getter) | ||
} | ||
|
||
fun Context.startSpan(scopeName: String, spanName: String, spanKind: SpanKind = SpanKind.INTERNAL): Span { | ||
val tracer = GlobalOpenTelemetry.getTracer(scopeName) | ||
return tracer.spanBuilder(spanName).setParent(this).setSpanKind(spanKind).startSpan() | ||
} | ||
|
||
fun TelemetryService.hmppsEventReceived(hmppsEvent: HmppsDomainEvent) { | ||
trackEvent( | ||
"NotificationReceived", | ||
mapOf("eventType" to hmppsEvent.eventType) + | ||
(hmppsEvent.detailUrl?.let { mapOf("detailUrl" to it) } ?: mapOf()) + | ||
(hmppsEvent.personReference.identifiers.associate { Pair(it.type, it.value) }) | ||
) | ||
} | ||
|
||
fun <T> TelemetryService.notificationReceived(notification: Notification<T>) { | ||
if (notification.message is HmppsDomainEvent) { | ||
hmppsEventReceived(notification.message) | ||
} else { | ||
trackEvent("NotificationReceived", notification.eventType?.let { mapOf("eventType" to it) } ?: mapOf()) | ||
} | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/telemetry/TelemetryService.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.