Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: stdcm: add some telemetry spans #10482

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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 @@ -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
Loading