@@ -32,6 +32,7 @@ use crate::{
3232#[ derive( Default ) ]
3333pub struct SpanInferrer {
3434 service_mapping : HashMap < String , String > ,
35+ aws_service_representation_enabled : bool ,
3536 // Span inferred from the Lambda incoming request payload
3637 pub inferred_span : Option < Span > ,
3738 // Nested span inferred from the Lambda incoming request payload
@@ -50,9 +51,13 @@ pub struct SpanInferrer {
5051
5152impl SpanInferrer {
5253 #[ must_use]
53- pub fn new ( service_mapping : HashMap < String , String > ) -> Self {
54+ pub fn new (
55+ service_mapping : HashMap < String , String > ,
56+ aws_service_representation_enabled : bool ,
57+ ) -> Self {
5458 Self {
5559 service_mapping,
60+ aws_service_representation_enabled,
5661 inferred_span : None ,
5762 wrapped_inferred_span : None ,
5863 is_async_span : false ,
@@ -87,19 +92,31 @@ impl SpanInferrer {
8792
8893 if APIGatewayHttpEvent :: is_match ( payload_value) {
8994 if let Some ( t) = APIGatewayHttpEvent :: new ( payload_value. clone ( ) ) {
90- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
95+ t. enrich_span (
96+ & mut inferred_span,
97+ & self . service_mapping ,
98+ self . aws_service_representation_enabled ,
99+ ) ;
91100
92101 trigger = Some ( Box :: new ( t) ) ;
93102 }
94103 } else if APIGatewayRestEvent :: is_match ( payload_value) {
95104 if let Some ( t) = APIGatewayRestEvent :: new ( payload_value. clone ( ) ) {
96- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
105+ t. enrich_span (
106+ & mut inferred_span,
107+ & self . service_mapping ,
108+ self . aws_service_representation_enabled ,
109+ ) ;
97110
98111 trigger = Some ( Box :: new ( t) ) ;
99112 }
100113 } else if APIGatewayWebSocketEvent :: is_match ( payload_value) {
101114 if let Some ( t) = APIGatewayWebSocketEvent :: new ( payload_value. clone ( ) ) {
102- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
115+ t. enrich_span (
116+ & mut inferred_span,
117+ & self . service_mapping ,
118+ self . aws_service_representation_enabled ,
119+ ) ;
103120
104121 trigger = Some ( Box :: new ( t) ) ;
105122 }
@@ -110,19 +127,31 @@ impl SpanInferrer {
110127 }
111128 } else if LambdaFunctionUrlEvent :: is_match ( payload_value) {
112129 if let Some ( t) = LambdaFunctionUrlEvent :: new ( payload_value. clone ( ) ) {
113- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
130+ t. enrich_span (
131+ & mut inferred_span,
132+ & self . service_mapping ,
133+ self . aws_service_representation_enabled ,
134+ ) ;
114135
115136 trigger = Some ( Box :: new ( t) ) ;
116137 }
117138 } else if MSKEvent :: is_match ( payload_value) {
118139 if let Some ( t) = MSKEvent :: new ( payload_value. clone ( ) ) {
119- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
140+ t. enrich_span (
141+ & mut inferred_span,
142+ & self . service_mapping ,
143+ self . aws_service_representation_enabled ,
144+ ) ;
120145
121146 trigger = Some ( Box :: new ( t) ) ;
122147 }
123148 } else if SqsRecord :: is_match ( payload_value) {
124149 if let Some ( t) = SqsRecord :: new ( payload_value. clone ( ) ) {
125- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
150+ t. enrich_span (
151+ & mut inferred_span,
152+ & self . service_mapping ,
153+ self . aws_service_representation_enabled ,
154+ ) ;
126155
127156 self . generated_span_context = extract_trace_context_from_aws_trace_header (
128157 t. attributes . aws_trace_header . clone ( ) ,
@@ -140,7 +169,11 @@ impl SpanInferrer {
140169 sns : sns_entity,
141170 event_subscription_arn : None ,
142171 } ;
143- wt. enrich_span ( & mut wrapped_inferred_span, & self . service_mapping ) ;
172+ wt. enrich_span (
173+ & mut wrapped_inferred_span,
174+ & self . service_mapping ,
175+ self . aws_service_representation_enabled ,
176+ ) ;
144177 inferred_span. meta . extend ( wt. get_tags ( ) ) ;
145178
146179 wrapped_inferred_span. duration =
@@ -155,8 +188,11 @@ impl SpanInferrer {
155188 ..Default :: default ( )
156189 } ;
157190
158- event_bridge_entity
159- . enrich_span ( & mut wrapped_inferred_span, & self . service_mapping ) ;
191+ event_bridge_entity. enrich_span (
192+ & mut wrapped_inferred_span,
193+ & self . service_mapping ,
194+ self . aws_service_representation_enabled ,
195+ ) ;
160196 inferred_span. meta . extend ( event_bridge_entity. get_tags ( ) ) ;
161197
162198 wrapped_inferred_span. duration =
@@ -169,7 +205,11 @@ impl SpanInferrer {
169205 }
170206 } else if SnsRecord :: is_match ( payload_value) {
171207 if let Some ( t) = SnsRecord :: new ( payload_value. clone ( ) ) {
172- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
208+ t. enrich_span (
209+ & mut inferred_span,
210+ & self . service_mapping ,
211+ self . aws_service_representation_enabled ,
212+ ) ;
173213
174214 if let Some ( message) = & t. sns . message {
175215 if let Ok ( event_bridge_wrapper_message) =
@@ -180,8 +220,11 @@ impl SpanInferrer {
180220 ..Default :: default ( )
181221 } ;
182222
183- event_bridge_wrapper_message
184- . enrich_span ( & mut wrapped_inferred_span, & self . service_mapping ) ;
223+ event_bridge_wrapper_message. enrich_span (
224+ & mut wrapped_inferred_span,
225+ & self . service_mapping ,
226+ self . aws_service_representation_enabled ,
227+ ) ;
185228 inferred_span
186229 . meta
187230 . extend ( event_bridge_wrapper_message. get_tags ( ) ) ;
@@ -197,27 +240,43 @@ impl SpanInferrer {
197240 }
198241 } else if DynamoDbRecord :: is_match ( payload_value) {
199242 if let Some ( t) = DynamoDbRecord :: new ( payload_value. clone ( ) ) {
200- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
243+ t. enrich_span (
244+ & mut inferred_span,
245+ & self . service_mapping ,
246+ self . aws_service_representation_enabled ,
247+ ) ;
201248 self . span_pointers = t. get_span_pointers ( ) ;
202249
203250 trigger = Some ( Box :: new ( t) ) ;
204251 }
205252 } else if S3Record :: is_match ( payload_value) {
206253 if let Some ( t) = S3Record :: new ( payload_value. clone ( ) ) {
207- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
254+ t. enrich_span (
255+ & mut inferred_span,
256+ & self . service_mapping ,
257+ self . aws_service_representation_enabled ,
258+ ) ;
208259 self . span_pointers = t. get_span_pointers ( ) ;
209260
210261 trigger = Some ( Box :: new ( t) ) ;
211262 }
212263 } else if EventBridgeEvent :: is_match ( payload_value) {
213264 if let Some ( t) = EventBridgeEvent :: new ( payload_value. clone ( ) ) {
214- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
265+ t. enrich_span (
266+ & mut inferred_span,
267+ & self . service_mapping ,
268+ self . aws_service_representation_enabled ,
269+ ) ;
215270
216271 trigger = Some ( Box :: new ( t) ) ;
217272 }
218273 } else if KinesisRecord :: is_match ( payload_value) {
219274 if let Some ( t) = KinesisRecord :: new ( payload_value. clone ( ) ) {
220- t. enrich_span ( & mut inferred_span, & self . service_mapping ) ;
275+ t. enrich_span (
276+ & mut inferred_span,
277+ & self . service_mapping ,
278+ self . aws_service_representation_enabled ,
279+ ) ;
221280
222281 trigger = Some ( Box :: new ( t) ) ;
223282 }
@@ -282,6 +341,7 @@ impl SpanInferrer {
282341 String :: from ( "peer.service" ) ,
283342 invocation_span. service . clone ( ) ,
284343 ) ;
344+ s. meta . insert ( "span.kind" . to_string ( ) , "server" . to_string ( ) ) ;
285345
286346 if let Some ( ws) = & mut self . wrapped_inferred_span {
287347 ws. trace_id = invocation_span. trace_id ;
0 commit comments