Skip to content

Commit 4ae0721

Browse files
committed
Lagt på spans
1 parent a047f9e commit 4ae0721

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/repository/BestillingRepository.kt

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.paw.arbeidssoekerregisteret.repository
22

3+
import io.opentelemetry.instrumentation.annotations.WithSpan
34
import no.nav.paw.arbeidssoekerregisteret.model.BestillingRow
45
import no.nav.paw.arbeidssoekerregisteret.model.BestillingStatus
56
import no.nav.paw.arbeidssoekerregisteret.model.BestillingerTable
@@ -19,13 +20,15 @@ import java.util.*
1920

2021
class BestillingRepository {
2122

23+
@WithSpan("findAll")
2224
fun findAll(paging: Paging = Paging.none()): List<BestillingRow> = transaction {
2325
BestillingerTable.selectAll()
2426
.orderBy(BestillingerTable.insertedTimestamp, paging.order.asSortOrder())
2527
.offset(paging.offset).limit(paging.size)
2628
.map { it.asBestillingRow() }
2729
}
2830

31+
@WithSpan("findAll")
2932
fun findByStatus(
3033
status: BestillingStatus,
3134
paging: Paging = Paging.none()
@@ -37,13 +40,15 @@ class BestillingRepository {
3740
.map { it.asBestillingRow() }
3841
}
3942

43+
@WithSpan("findByBestillingId")
4044
fun findByBestillingId(bestillingId: UUID): BestillingRow? = transaction {
4145
BestillingerTable.selectAll()
4246
.where { BestillingerTable.bestillingId eq bestillingId }
4347
.map { it.asBestillingRow() }
4448
.singleOrNull()
4549
}
4650

51+
@WithSpan("insert")
4752
fun insert(bestilling: InsertBestillingRow): Int = transaction {
4853
BestillingerTable.insert {
4954
it[bestillingId] = bestilling.bestillingId
@@ -53,6 +58,7 @@ class BestillingRepository {
5358
}.insertedCount
5459
}
5560

61+
@WithSpan("update")
5662
fun update(bestilling: UpdateBestillingRow): Int = transaction {
5763
BestillingerTable.update({
5864
BestillingerTable.bestillingId eq bestilling.bestillingId
@@ -62,6 +68,7 @@ class BestillingRepository {
6268
}
6369
}
6470

71+
@WithSpan("deleteByBestillingId")
6572
fun deleteByBestillingId(bestillingId: UUID): Int = transaction {
6673
BestillingerTable.deleteWhere { BestillingerTable.bestillingId eq bestillingId }
6774
}

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/repository/BestiltVarselRepository.kt

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.paw.arbeidssoekerregisteret.repository
22

3+
import io.opentelemetry.instrumentation.annotations.WithSpan
34
import no.nav.paw.arbeidssoekerregisteret.model.BestiltVarselRow
45
import no.nav.paw.arbeidssoekerregisteret.model.BestiltVarselStatus
56
import no.nav.paw.arbeidssoekerregisteret.model.BestilteVarslerTable
@@ -20,20 +21,23 @@ import java.util.*
2021

2122
class BestiltVarselRepository {
2223

24+
@WithSpan("findAll")
2325
fun findAll(paging: Paging = Paging.none()): List<BestiltVarselRow> = transaction {
2426
BestilteVarslerTable.selectAll()
2527
.orderBy(BestilteVarslerTable.insertedTimestamp, paging.order.asSortOrder())
2628
.offset(paging.offset).limit(paging.size)
2729
.map { it.asBestiltVarselRow() }
2830
}
2931

32+
@WithSpan("findByVarselId")
3033
fun findByVarselId(varselId: UUID): BestiltVarselRow? = transaction {
3134
BestilteVarslerTable.selectAll()
3235
.where { BestilteVarslerTable.varselId eq varselId }
3336
.map { it.asBestiltVarselRow() }
3437
.firstOrNull()
3538
}
3639

40+
@WithSpan("findByBestillingId")
3741
fun findByBestillingId(
3842
bestillingId: UUID,
3943
paging: Paging = Paging.none(),
@@ -45,6 +49,7 @@ class BestiltVarselRepository {
4549
.map { it.asBestiltVarselRow() }
4650
}
4751

52+
@WithSpan("insert")
4853
fun insert(varsel: InsertBestiltVarselRow): Int = transaction {
4954
BestilteVarslerTable.insert {
5055
it[bestillingId] = varsel.bestillingId
@@ -56,6 +61,7 @@ class BestiltVarselRepository {
5661
}.insertedCount
5762
}
5863

64+
@WithSpan("update")
5965
fun update(varsel: UpdateBestiltVarselRow): Int = transaction {
6066
BestilteVarslerTable.update({
6167
BestilteVarslerTable.varselId eq varsel.varselId
@@ -65,20 +71,24 @@ class BestiltVarselRepository {
6571
}
6672
}
6773

74+
@WithSpan("deleteByBestillingId")
6875
fun deleteByBestillingId(bestillingId: UUID): Int = transaction {
6976
BestilteVarslerTable.deleteWhere { BestilteVarslerTable.bestillingId eq bestillingId }
7077
}
7178

79+
@WithSpan("deleteByVarselId")
7280
fun deleteByVarselId(varselId: UUID): Int = transaction {
7381
BestilteVarslerTable.deleteWhere { BestilteVarslerTable.varselId eq varselId }
7482
}
7583

84+
@WithSpan("countByBestillingId")
7685
fun countByBestillingId(bestillingId: UUID): Long = transaction {
7786
BestilteVarslerTable.selectAll()
7887
.where { BestilteVarslerTable.bestillingId eq bestillingId }
7988
.count()
8089
}
8190

91+
@WithSpan("countByBestillingIdAndStatus")
8292
fun countByBestillingIdAndStatus(
8393
bestillingId: UUID,
8494
status: BestiltVarselStatus
@@ -88,6 +98,7 @@ class BestiltVarselRepository {
8898
.count()
8999
}
90100

101+
@WithSpan("insertAktivePerioder")
91102
fun insertAktivePerioder(bestillingId: UUID) = transaction {
92103
val status = BestiltVarselStatus.VENTER.name
93104
exec(

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/repository/EksterntVarselRepository.kt

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.paw.arbeidssoekerregisteret.repository
22

3+
import io.opentelemetry.instrumentation.annotations.WithSpan
34
import no.nav.paw.arbeidssoekerregisteret.model.EksterneVarslerTable
45
import no.nav.paw.arbeidssoekerregisteret.model.EksterntVarselRow
56
import no.nav.paw.arbeidssoekerregisteret.model.InsertEksterntVarselRow
@@ -16,20 +17,23 @@ import java.util.*
1617

1718
class EksterntVarselRepository {
1819

20+
@WithSpan("findAll")
1921
fun findAll(paging: Paging = Paging.none()): List<EksterntVarselRow> = transaction {
2022
EksterneVarslerTable.selectAll()
2123
.orderBy(EksterneVarslerTable.hendelseTimestamp, paging.order.asSortOrder())
2224
.offset(paging.offset).limit(paging.size)
2325
.map { it.asEksterntVarselRow() }
2426
}
2527

28+
@WithSpan("findByVarselId")
2629
fun findByVarselId(varselId: UUID): EksterntVarselRow? = transaction {
2730
EksterneVarslerTable.selectAll()
2831
.where { EksterneVarslerTable.varselId eq varselId }
2932
.map { it.asEksterntVarselRow() }
3033
.firstOrNull()
3134
}
3235

36+
@WithSpan("insert")
3337
fun insert(varsel: InsertEksterntVarselRow): Int = transaction {
3438
EksterneVarslerTable.insert {
3539
it[varselId] = varsel.varselId
@@ -41,6 +45,7 @@ class EksterntVarselRepository {
4145
}.insertedCount
4246
}
4347

48+
@WithSpan("update")
4449
fun update(varsel: UpdateEksterntVarselRow): Int = transaction {
4550
EksterneVarslerTable.update({
4651
EksterneVarslerTable.varselId eq varsel.varselId

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/repository/PeriodeRepository.kt

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.paw.arbeidssoekerregisteret.repository
22

3+
import io.opentelemetry.instrumentation.annotations.WithSpan
34
import no.nav.paw.arbeidssoekerregisteret.model.InsertPeriodeRow
45
import no.nav.paw.arbeidssoekerregisteret.model.Paging
56
import no.nav.paw.arbeidssoekerregisteret.model.PeriodeRow
@@ -18,20 +19,23 @@ import java.util.*
1819

1920
class PeriodeRepository {
2021

22+
@WithSpan("findAll")
2123
fun findAll(paging: Paging = Paging.none()): List<PeriodeRow> = transaction {
2224
PerioderTable.selectAll()
2325
.orderBy(PerioderTable.startetTimestamp, paging.order.asSortOrder())
2426
.offset(paging.offset).limit(paging.size)
2527
.map { it.asPeriodeRow() }
2628
}
2729

30+
@WithSpan("findByPeriodeId")
2831
fun findByPeriodeId(periodeId: UUID): PeriodeRow? = transaction {
2932
PerioderTable.selectAll()
3033
.where { PerioderTable.periodeId eq periodeId }
3134
.map { it.asPeriodeRow() }
3235
.singleOrNull()
3336
}
3437

38+
@WithSpan("insert")
3539
fun insert(periode: InsertPeriodeRow): Int = transaction {
3640
PerioderTable.insert {
3741
it[periodeId] = periode.periodeId
@@ -42,6 +46,7 @@ class PeriodeRepository {
4246
}.insertedCount
4347
}
4448

49+
@WithSpan("update")
4550
fun update(periode: UpdatePeriodeRow): Int = transaction {
4651
PerioderTable.update({
4752
PerioderTable.periodeId eq periode.periodeId
@@ -52,6 +57,7 @@ class PeriodeRepository {
5257
}
5358
}
5459

60+
@WithSpan("deleteByPeriodeId")
5561
fun deleteByPeriodeId(periodeId: UUID): Int = transaction {
5662
PerioderTable.deleteWhere { PerioderTable.periodeId eq periodeId }
5763
}

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/repository/VarselRepository.kt

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.paw.arbeidssoekerregisteret.repository
22

3+
import io.opentelemetry.instrumentation.annotations.WithSpan
34
import no.nav.paw.arbeidssoekerregisteret.model.EksterneVarslerTable
45
import no.nav.paw.arbeidssoekerregisteret.model.InsertVarselRow
56
import no.nav.paw.arbeidssoekerregisteret.model.Paging
@@ -22,6 +23,7 @@ import java.util.*
2223

2324
class VarselRepository {
2425

26+
@WithSpan("findAll")
2527
fun findAll(paging: Paging = Paging.none()): List<VarselRow> = transaction {
2628
VarslerTable.join(EksterneVarslerTable, JoinType.LEFT, VarslerTable.varselId, EksterneVarslerTable.varselId)
2729
.selectAll()
@@ -30,6 +32,7 @@ class VarselRepository {
3032
.map { it.asVarselRow() }
3133
}
3234

35+
@WithSpan("findByVarselId")
3336
fun findByVarselId(varselId: UUID): VarselRow? = transaction {
3437
VarslerTable.join(EksterneVarslerTable, JoinType.LEFT, VarslerTable.varselId, EksterneVarslerTable.varselId)
3538
.selectAll()
@@ -38,6 +41,7 @@ class VarselRepository {
3841
.firstOrNull()
3942
}
4043

44+
@WithSpan("findByPeriodeId")
4145
fun findByPeriodeId(
4246
periodeId: UUID,
4347
paging: Paging = Paging.none(),
@@ -50,6 +54,7 @@ class VarselRepository {
5054
.map { it.asVarselRow() }
5155
}
5256

57+
@WithSpan("findByPeriodeIdAndVarselKilde")
5358
fun findByPeriodeIdAndVarselKilde(
5459
periodeId: UUID,
5560
varselKilde: VarselKilde,
@@ -63,6 +68,7 @@ class VarselRepository {
6368
.map { it.asVarselRow() }
6469
}
6570

71+
@WithSpan("insert")
6672
fun insert(varsel: InsertVarselRow): Int = transaction {
6773
VarslerTable.insert {
6874
it[periodeId] = varsel.periodeId
@@ -76,6 +82,7 @@ class VarselRepository {
7682
}.insertedCount
7783
}
7884

85+
@WithSpan("update")
7986
fun update(varsel: UpdateVarselRow): Int = transaction {
8087
VarslerTable.update({
8188
VarslerTable.varselId eq varsel.varselId
@@ -87,13 +94,15 @@ class VarselRepository {
8794
}
8895
}
8996

97+
@WithSpan("deleteByPeriodeIdAndVarselKilde")
9098
fun deleteByPeriodeIdAndVarselKilde(
9199
periodeId: UUID,
92100
varselKilde: VarselKilde
93101
): Int = transaction {
94102
VarslerTable.deleteWhere { (VarslerTable.periodeId eq periodeId) and (VarslerTable.varselKilde eq varselKilde) }
95103
}
96104

105+
@WithSpan("deleteByVarselId")
97106
fun deleteByVarselId(varselId: UUID): Int = transaction {
98107
VarslerTable.deleteWhere { VarslerTable.varselId eq varselId }
99108
}

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/service/BestillingService.kt

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.nav.paw.arbeidssoekerregisteret.service
22

33
import io.micrometer.core.instrument.MeterRegistry
4+
import io.opentelemetry.instrumentation.annotations.WithSpan
45
import no.nav.paw.arbeidssoekerregisteret.api.models.BestillingResponse
56
import no.nav.paw.arbeidssoekerregisteret.config.ApplicationConfig
67
import no.nav.paw.arbeidssoekerregisteret.config.ServerConfig
@@ -38,6 +39,7 @@ class BestillingService(
3839
) {
3940
private val logger = buildApplicationLogger
4041

42+
@WithSpan("hentBestilling")
4143
fun hentBestilling(bestillingId: UUID): BestillingResponse = transaction {
4244
val bestilling = bestillingRepository.findByBestillingId(bestillingId)
4345
?: throw BestillingIkkeFunnetException("Bestilling ikke funnet")
@@ -47,13 +49,15 @@ class BestillingService(
4749
bestilling.asResponse(totalCount, sendtCount, feiletCount)
4850
}
4951

52+
@WithSpan("opprettBestilling")
5053
fun opprettBestilling(bestiller: String): BestillingResponse = transaction {
5154
val bestillingId = UUID.randomUUID()
5255
bestillingRepository.insert(InsertBestillingRow(bestillingId, bestiller))
5356
bestillingRepository.findByBestillingId(bestillingId)?.asResponse(0, 0, 0)
5457
?: throw BestillingIkkeFunnetException("Bestilling ikke funnet")
5558
}
5659

60+
@WithSpan("bekreftBestilling")
5761
fun bekreftBestilling(bestillingId: UUID): BestillingResponse = transaction {
5862
val bestilling = bestillingRepository.findByBestillingId(bestillingId)
5963
?: throw BestillingIkkeFunnetException("Bestilling ikke funnet")
@@ -64,6 +68,7 @@ class BestillingService(
6468
hentBestilling(bestillingId)
6569
}
6670

71+
@WithSpan("prosesserBestillinger")
6772
fun prosesserBestillinger() = transaction {
6873
val bestillinger = bestillingRepository.findByStatus(BestillingStatus.BEKREFTET)
6974
if (bestillinger.isEmpty()) {
@@ -80,6 +85,7 @@ class BestillingService(
8085
}
8186
}
8287

88+
@WithSpan("prosesserBestilling")
8389
private fun prosesserBestilling(bestilling: BestillingRow) {
8490
val varslinger = bestiltVarselRepository.findByBestillingId(bestilling.bestillingId)
8591
logger.info(
@@ -106,6 +112,7 @@ class BestillingService(
106112
bestillingRepository.update(UpdateBestillingRow(bestilling.bestillingId, status))
107113
}
108114

115+
@WithSpan("prosesserBestiltVarsel")
109116
private fun prosesserBestiltVarsel(varsel: BestiltVarselRow): BestiltVarselRow {
110117
try {
111118
logger.debug("Prosesserer manuelt varsel {}", varsel.varselId)

apps/min-side-varsler/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/service/VarselService.kt

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.nav.paw.arbeidssoekerregisteret.service
22

33
import io.micrometer.core.instrument.MeterRegistry
4+
import io.opentelemetry.instrumentation.annotations.WithSpan
45
import no.nav.paw.arbeidssoekerregisteret.api.models.VarselResponse
56
import no.nav.paw.arbeidssoekerregisteret.config.ApplicationConfig
67
import no.nav.paw.arbeidssoekerregisteret.exception.PeriodeIkkeFunnetException
@@ -44,17 +45,20 @@ class VarselService(
4445
) {
4546
private val logger = buildLogger
4647

48+
@WithSpan("hentVarsel")
4749
fun hentVarsel(varselId: UUID): VarselResponse = transaction {
4850
varselRepository.findByVarselId(varselId)?.asResponse() ?: throw VarselIkkeFunnetException("Varsel ikke funnet")
4951
}
5052

53+
@WithSpan("finnVarsler")
5154
fun finnVarsler(
5255
periodeId: UUID,
5356
paging: Paging = Paging.none()
5457
): List<VarselResponse> = transaction {
5558
varselRepository.findByPeriodeId(periodeId, paging).map { it.asResponse() }
5659
}
5760

61+
@WithSpan("mottaPeriode")
5862
fun mottaPeriode(periode: Periode): List<VarselMelding> = transaction {
5963
try {
6064
val eventName = if (periode.avsluttet == null) "periode.startet" else "periode.avsluttet"
@@ -119,6 +123,7 @@ class VarselService(
119123
}
120124
}
121125

126+
@WithSpan("mottaBekreftelseHendelse")
122127
fun mottaBekreftelseHendelse(value: Pair<Periode?, BekreftelseHendelse?>): List<VarselMelding> = transaction {
123128
try {
124129
val (periode, hendelse) = value
@@ -242,6 +247,7 @@ class VarselService(
242247
}
243248
}
244249

250+
@WithSpan("mottaVarselHendelse")
245251
fun mottaVarselHendelse(hendelse: VarselHendelse) = transaction {
246252
try {
247253
val eventName = "varsel.${hendelse.eventName.value}"

0 commit comments

Comments
 (0)