Skip to content

Commit

Permalink
core: stdcm: add some telemetry spans
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Jan 22, 2025
1 parent 74a2bcb commit c500060
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import fr.sncf.osrd.utils.LogAggregator
import fr.sncf.osrd.utils.units.Duration
import fr.sncf.osrd.utils.units.TimeDelta
import fr.sncf.osrd.utils.units.seconds
import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.instrumentation.annotations.WithSpan
import java.time.Duration.between
import java.time.ZonedDateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory

val requirementsParserLogger: Logger = LoggerFactory.getLogger("RequirementsParser")

@WithSpan(value = "Parsing train requirements", kind = SpanKind.SERVER)
fun parseTrainsRequirements(
trainsRequirements: Map<Long, TrainRequirementsRequest>,
startTime: ZonedDateTime
Expand Down Expand Up @@ -121,6 +124,7 @@ fun convertWorkScheduleMap(
* Convert work schedules into timetable spacing requirements, without taking work schedule id into
* account.
*/
@WithSpan(value = "Parsing work schedules", kind = SpanKind.SERVER)
fun convertWorkScheduleCollection(
rawInfra: RawSignalingInfra,
workSchedules: Collection<WorkSchedule>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import fr.sncf.osrd.utils.DistanceRangeMap
import fr.sncf.osrd.utils.DistanceRangeMap.RangeMapEntry
import fr.sncf.osrd.utils.distanceRangeMapOf
import fr.sncf.osrd.utils.units.*
import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.instrumentation.annotations.WithSpan
import java.io.File
import java.time.Duration.between
import java.time.Duration.ofMillis
Expand All @@ -62,10 +64,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take {
@Throws(OSRDError::class)
override fun act(req: Request): Response {
// Parse request input
val body = RqPrint(req).printBody()
val request =
stdcmRequestAdapter.fromJson(body)
?: return RsWithStatus(RsText("missing request body"), 400)
val request = readRequest(req) ?: return RsWithStatus(RsText("missing request body"), 400)

val logRequest = System.getenv("LOG_STDCM_REQUESTS")
if (logRequest?.equals("true", ignoreCase = true) == true) {
Expand All @@ -79,7 +78,14 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take {
return run(request)
}

@WithSpan(value = "Reading request content", kind = SpanKind.SERVER)
private fun readRequest(req: Request): STDCMRequestV2? {
val body = RqPrint(req).printBody()
return stdcmRequestAdapter.fromJson(body)
}

/** Process the given parsed request */
@WithSpan(value = "Processing STDCM request", kind = SpanKind.SERVER)
fun run(request: STDCMRequestV2): Response {
val recorder = DiagnosticRecorderImpl(false)
logger.info(
Expand Down Expand Up @@ -227,6 +233,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take {
}
}

@WithSpan(value = "Parsing speed limits", kind = SpanKind.SERVER)
fun buildTemporarySpeedLimitManager(
infra: FullInfra,
speedLimits: Collection<STDCMTemporarySpeedLimit>
Expand Down

0 comments on commit c500060

Please sign in to comment.