|
77 | 77 | "Lambda function invocation", |
78 | 78 | "otel.name" = req.context.env_config.function_name, |
79 | 79 | "otel.kind" = field::Empty, |
| 80 | + { attribute::FAAS_NAME } = req.context.env_config.function_name, |
80 | 81 | { attribute::FAAS_TRIGGER } = &self.otel_attribute_trigger, |
81 | 82 | { attribute::FAAS_INVOCATION_ID } = req.context.request_id, |
82 | 83 | { attribute::FAAS_COLDSTART } = self.coldstart, |
|
87 | 88 | "Lambda function invocation", |
88 | 89 | "otel.name" = req.context.env_config.function_name, |
89 | 90 | "otel.kind" = field::Empty, |
| 91 | + { attribute::FAAS_NAME } = req.context.env_config.function_name, |
90 | 92 | { attribute::FAAS_TRIGGER } = &self.otel_attribute_trigger, |
91 | 93 | { attribute::FAAS_INVOCATION_ID } = req.context.request_id, |
92 | 94 | { attribute::FAAS_COLDSTART } = self.coldstart |
@@ -171,3 +173,57 @@ impl Display for OpenTelemetryFaasTrigger { |
171 | 173 | } |
172 | 174 | } |
173 | 175 | } |
| 176 | + |
| 177 | +#[cfg(test)] |
| 178 | +mod tests { |
| 179 | + use super::*; |
| 180 | + use crate::{Config, Context}; |
| 181 | + use lambda_runtime_api_client::BoxError; |
| 182 | + use std::sync::Arc; |
| 183 | + use tower::service_fn; |
| 184 | + use tracing_capture::{CaptureLayer, SharedStorage}; |
| 185 | + use tracing_subscriber::layer::SubscriberExt; |
| 186 | + |
| 187 | + fn invocation_with_function_name(function_name: &str) -> LambdaInvocation { |
| 188 | + let (parts, _) = http::Response::new(()).into_parts(); |
| 189 | + LambdaInvocation { |
| 190 | + parts, |
| 191 | + body: bytes::Bytes::new(), |
| 192 | + context: Context { |
| 193 | + env_config: Arc::new(Config { |
| 194 | + function_name: function_name.to_owned(), |
| 195 | + ..Default::default() |
| 196 | + }), |
| 197 | + ..Default::default() |
| 198 | + }, |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + #[tokio::test] |
| 203 | + async fn should_record_faas_name_from_the_function_configuration() { |
| 204 | + // given |
| 205 | + let storage = SharedStorage::default(); |
| 206 | + let subscriber = tracing_subscriber::registry().with(CaptureLayer::new(&storage)); |
| 207 | + let _guard = tracing::subscriber::set_default(subscriber); |
| 208 | + let inner = service_fn(|_req: LambdaInvocation| async { Ok::<(), BoxError>(()) }); |
| 209 | + let mut service = OpenTelemetryLayer::new(|| {}).layer(inner); |
| 210 | + |
| 211 | + // when |
| 212 | + service |
| 213 | + .call(invocation_with_function_name("my-function")) |
| 214 | + .await |
| 215 | + .expect("invocation should succeed"); |
| 216 | + |
| 217 | + // then |
| 218 | + let storage = storage.lock(); |
| 219 | + let span = storage |
| 220 | + .all_spans() |
| 221 | + .find(|span| span.metadata().name() == "Lambda function invocation") |
| 222 | + .expect("otel span should be recorded"); |
| 223 | + let faas_name = span.value("faas.name").expect("faas.name attribute should be recorded"); |
| 224 | + assert_eq!( |
| 225 | + *faas_name, "my-function", |
| 226 | + "faas.name should match the function's configured name" |
| 227 | + ); |
| 228 | + } |
| 229 | +} |
0 commit comments