33"""
44
55from fastapi import APIRouter
6+ from opentelemetry import trace
67
78from lib .views .flight import (
89 FlightSummary ,
2728 },
2829)
2930
31+ tracer = trace .get_tracer (__name__ )
32+
3033
3134@router .post ("/" )
3235async def create_flight (
@@ -38,9 +41,10 @@ async def create_flight(
3841 ## Args
3942 ``` Flight object as JSON ```
4043 """
41- return await FlightController (
42- flight , rocket_option = rocket_option , motor_kind = motor_kind
43- ).create_flight ()
44+ with tracer .start_as_current_span ("create_flight" ):
45+ return await FlightController (
46+ flight , rocket_option = rocket_option , motor_kind = motor_kind
47+ ).create_flight ()
4448
4549
4650@router .get ("/{flight_id}" )
@@ -51,7 +55,8 @@ async def read_flight(flight_id: str) -> Flight:
5155 ## Args
5256 ``` flight_id: Flight ID hash ```
5357 """
54- return await FlightController .get_flight_by_id (flight_id )
58+ with tracer .start_as_current_span ("read_flight" ):
59+ return await FlightController .get_flight_by_id (flight_id )
5560
5661
5762@router .get ("/rocketpy/{flight_id}" )
@@ -62,7 +67,10 @@ async def read_rocketpy_flight(flight_id: str) -> FlightPickle:
6267 ## Args
6368 ``` flight_id: Flight ID hash. ```
6469 """
65- return await FlightController .get_rocketpy_flight_as_jsonpickle (flight_id )
70+ with tracer .start_as_current_span ("read_rocketpy_flight" ):
71+ return await FlightController .get_rocketpy_flight_as_jsonpickle (
72+ flight_id
73+ )
6674
6775
6876@router .put ("/{flight_id}/env" )
@@ -76,7 +84,10 @@ async def update_flight_env(flight_id: str, env: Env) -> FlightUpdated:
7684 env: env object as JSON
7785 ```
7886 """
79- return await FlightController .update_env_by_flight_id (flight_id , env = env )
87+ with tracer .start_as_current_span ("update_flight_env" ):
88+ return await FlightController .update_env_by_flight_id (
89+ flight_id , env = env
90+ )
8091
8192
8293@router .put ("/{flight_id}/rocket" )
@@ -95,12 +106,13 @@ async def update_flight_rocket(
95106 rocket: Rocket object as JSON
96107 ```
97108 """
98- return await FlightController .update_rocket_by_flight_id (
99- flight_id ,
100- rocket = rocket ,
101- rocket_option = rocket_option ,
102- motor_kind = motor_kind ,
103- )
109+ with tracer .start_as_current_span ("update_flight_rocket" ):
110+ return await FlightController .update_rocket_by_flight_id (
111+ flight_id ,
112+ rocket = rocket ,
113+ rocket_option = rocket_option ,
114+ motor_kind = motor_kind ,
115+ )
104116
105117
106118@router .put ("/{flight_id}" )
@@ -119,9 +131,10 @@ async def update_flight(
119131 flight: Flight object as JSON
120132 ```
121133 """
122- return await FlightController (
123- flight , rocket_option = rocket_option , motor_kind = motor_kind
124- ).update_flight_by_id (flight_id )
134+ with tracer .start_as_current_span ("update_flight" ):
135+ return await FlightController (
136+ flight , rocket_option = rocket_option , motor_kind = motor_kind
137+ ).update_flight_by_id (flight_id )
125138
126139
127140@router .delete ("/{flight_id}" )
@@ -132,7 +145,8 @@ async def delete_flight(flight_id: str) -> FlightDeleted:
132145 ## Args
133146 ``` flight_id: Flight ID hash ```
134147 """
135- return await FlightController .delete_flight_by_id (flight_id )
148+ with tracer .start_as_current_span ("delete_flight" ):
149+ return await FlightController .delete_flight_by_id (flight_id )
136150
137151
138152@router .get ("/{flight_id}/simulate" )
@@ -143,4 +157,5 @@ async def simulate_flight(flight_id: str) -> FlightSummary:
143157 ## Args
144158 ``` flight_id: Flight ID hash ```
145159 """
146- return await FlightController .simulate_flight (flight_id )
160+ with tracer .start_as_current_span ("simulate_flight" ):
161+ return await FlightController .simulate_flight (flight_id )
0 commit comments