@@ -10,6 +10,7 @@ use tracing::{instrument::Instrumented, Instrument};
10
10
/// a function to flush OpenTelemetry after the end of the invocation.
11
11
pub struct OpenTelemetryLayer < F > {
12
12
flush_fn : F ,
13
+ otel_attribute_trigger : Option < String > ,
13
14
}
14
15
15
16
impl < F > OpenTelemetryLayer < F >
18
19
{
19
20
/// Create a new [OpenTelemetryLayer] with the provided flush function.
20
21
pub fn new ( flush_fn : F ) -> Self {
21
- Self { flush_fn }
22
+ Self {
23
+ flush_fn,
24
+ otel_attribute_trigger : None ,
25
+ }
26
+ }
27
+
28
+ /// Configure the `faas.trigger` attribute of the OpenTelemetry span.
29
+ /// Defaults to `http` if not set.
30
+ /// See https://opentelemetry.io/docs/specs/semconv/attributes-registry/faas/ for the list of possible triggers.
31
+ pub fn with_trigger < T : Into < String > > ( self , trigger : T ) -> Self {
32
+ Self {
33
+ otel_attribute_trigger : Some ( trigger. into ( ) ) ,
34
+ ..self
35
+ }
22
36
}
23
37
}
24
38
33
47
inner,
34
48
flush_fn : self . flush_fn . clone ( ) ,
35
49
coldstart : true ,
50
+ otel_attribute_trigger : self
51
+ . otel_attribute_trigger
52
+ . clone ( )
53
+ . unwrap_or_else ( || "http" . to_string ( ) ) ,
36
54
}
37
55
}
38
56
}
@@ -42,6 +60,7 @@ pub struct OpenTelemetryService<S, F> {
42
60
inner : S ,
43
61
flush_fn : F ,
44
62
coldstart : bool ,
63
+ otel_attribute_trigger : String ,
45
64
}
46
65
47
66
impl < S , F > Service < LambdaInvocation > for OpenTelemetryService < S , F >
61
80
let span = tracing:: info_span!(
62
81
"Lambda function invocation" ,
63
82
"otel.name" = req. context. env_config. function_name,
64
- { traceconv:: FAAS_TRIGGER } = "http" ,
83
+ { traceconv:: FAAS_TRIGGER } = & self . otel_attribute_trigger ,
65
84
{ traceconv:: FAAS_INVOCATION_ID } = req. context. request_id,
66
85
{ traceconv:: FAAS_COLDSTART } = self . coldstart
67
86
) ;
0 commit comments