@@ -45,17 +45,18 @@ const initialQueueSize = 5
4545const scopeName = "github.com/open-telemetry/opentelemetry-lambda/collector/receiver/telemetryapi"
4646
4747type telemetryAPIReceiver struct {
48- httpServer * http.Server
49- logger * zap.Logger
50- queue * queue.Queue // queue is a synchronous queue and is used to put the received log events to be dispatched later
51- nextTraces consumer.Traces
52- nextLogs consumer.Logs
53- lastPlatformStartTime string
54- lastPlatformEndTime string
55- extensionID string
56- port int
57- types []telemetryapi.EventType
58- resource pcommon.Resource
48+ httpServer * http.Server
49+ logger * zap.Logger
50+ queue * queue.Queue // queue is a synchronous queue and is used to put the received log events to be dispatched later
51+ nextTraces consumer.Traces
52+ nextLogs consumer.Logs
53+ lastPlatformStartTime string
54+ lastPlatformEndTime string
55+ extensionID string
56+ port int
57+ types []telemetryapi.EventType
58+ resource pcommon.Resource
59+ currentFaasInvocationID string
5960}
6061
6162func (r * telemetryAPIReceiver ) Start (ctx context.Context , host component.Host ) error {
@@ -217,16 +218,31 @@ func (r *telemetryAPIReceiver) createLogs(slice []event) (plog.Logs, error) {
217218 }
218219 if requestId , ok := record ["requestId" ].(string ); ok {
219220 logRecord .Attributes ().PutStr (semconv .AttributeFaaSInvocationID , requestId )
221+ } else if r .currentFaasInvocationID != "" {
222+ logRecord .Attributes ().PutStr (semconv .AttributeFaaSInvocationID , r .currentFaasInvocationID )
220223 }
221224 if line , ok := record ["message" ].(string ); ok {
222225 logRecord .Body ().SetStr (line )
223226 }
224227 } else {
228+ if r .currentFaasInvocationID != "" {
229+ logRecord .Attributes ().PutStr (semconv .AttributeFaaSInvocationID , r .currentFaasInvocationID )
230+ }
225231 // in plain text https://docs.aws.amazon.com/lambda/latest/dg/telemetry-schema-reference.html#telemetry-api-function
226232 if line , ok := el .Record .(string ); ok {
227233 logRecord .Body ().SetStr (line )
228234 }
229235 }
236+ } else { // platform events, if subscribed to
237+ if el .Type == string (telemetryapi .PlatformStart ) {
238+ if record , ok := el .Record .(map [string ]interface {}); ok {
239+ if requestId , ok := record ["requestId" ].(string ); ok {
240+ r .currentFaasInvocationID = requestId
241+ }
242+ }
243+ } else if el .Type == string (telemetryapi .PlatformRuntimeDone ) {
244+ r .currentFaasInvocationID = ""
245+ }
230246 }
231247 }
232248 return log , nil
0 commit comments