@@ -98,6 +98,8 @@ pub struct HttpServer<F: RuntimeFactors> {
9898 router : Router ,
9999 /// The app being triggered.
100100 trigger_app : Arc < TriggerApp < F > > ,
101+ /// The application name, resolved once for use as the `app_id` telemetry attribute.
102+ app_id : Arc < str > ,
101103 // Component ID -> component trigger config
102104 component_trigger_configs : HashMap < spin_http:: routes:: TriggerLookupKey , HttpTriggerConfig > ,
103105 // Component ID -> handler type
@@ -158,6 +160,12 @@ impl<F: RuntimeFactors> HttpServer<F> {
158160
159161 let trigger_app = Arc :: new ( trigger_app) ;
160162
163+ let app_id: Arc < str > = trigger_app
164+ . app ( )
165+ . get_metadata ( APP_NAME_KEY ) ?
166+ . unwrap_or_else ( || "<unnamed>" . into ( ) )
167+ . into ( ) ;
168+
161169 let component_handler_types = component_trigger_configs
162170 . iter ( )
163171 . filter_map ( |( key, trigger_config) | match key {
@@ -180,6 +188,7 @@ impl<F: RuntimeFactors> HttpServer<F> {
180188 find_free_port,
181189 router,
182190 trigger_app,
191+ app_id,
183192 http1_max_buf_size,
184193 component_trigger_configs,
185194 component_handler_types,
@@ -350,18 +359,12 @@ impl<F: RuntimeFactors> HttpServer<F> {
350359 client_addr : SocketAddr ,
351360 ) -> anyhow:: Result < Response < Body > > {
352361 set_req_uri ( & mut req, server_scheme) ?;
353- let app_id = self
354- . trigger_app
355- . app ( )
356- . get_metadata ( APP_NAME_KEY ) ?
357- . unwrap_or_else ( || "<unnamed>" . into ( ) ) ;
358-
359362 let lookup_key = route_match. lookup_key ( ) ;
360363
361364 spin_telemetry:: metrics:: counter!(
362365 spin. request_count = 1 ,
363366 trigger_type = "http" ,
364- app_id = app_id,
367+ app_id = self . app_id. clone ( ) ,
365368 component_id = lookup_key. to_string( )
366369 ) ;
367370
0 commit comments