@@ -82,6 +82,13 @@ func NewBatch(maxSize int, maxAge time.Duration) *Batch {
8282	}
8383}
8484
85+ // Size returns the number of invocations cached in the batch. 
86+ func  (b  * Batch ) Size () int  {
87+ 	b .mu .RLock ()
88+ 	defer  b .mu .RUnlock ()
89+ 	return  len (b .invocations )
90+ }
91+ 
8592// RegisterInvocation registers a new function invocation against its request 
8693// ID. It also updates the caches for currently executing request ID. 
8794func  (b  * Batch ) RegisterInvocation (
@@ -185,6 +192,21 @@ func (b *Batch) OnLambdaLogRuntimeDone(reqID, status string, time time.Time) err
185192	return  b .finalizeInvocation (reqID , status , time )
186193}
187194
195+ // OnPlatformReport should be the last event for a request ID. On receiving the 
196+ // platform.report event the batch will cleanup any datastructure for the request 
197+ // ID. It will return some of the function metadata to allow the caller to enrich 
198+ // the report metrics. 
199+ func  (b  * Batch ) OnPlatformReport (reqID  string ) (string , int64 , time.Time , error ) {
200+ 	b .mu .Lock ()
201+ 	defer  b .mu .Unlock ()
202+ 	inc , ok  :=  b .invocations [reqID ]
203+ 	if  ! ok  {
204+ 		return  "" , 0 , time.Time {}, fmt .Errorf ("invocation for requestID %s does not exist" , reqID )
205+ 	}
206+ 	delete (b .invocations , reqID )
207+ 	return  inc .FunctionARN , inc .DeadlineMs , inc .Timestamp , nil 
208+ }
209+ 
188210// OnShutdown flushes the data for shipping to APM Server by finalizing all 
189211// the invocation in the batch. If we haven't received a platform.runtimeDone 
190212// event for an invocation so far we won't be able to recieve it in time thus 
@@ -201,6 +223,7 @@ func (b *Batch) OnShutdown(status string) error {
201223		if  err  :=  b .finalizeInvocation (inc .RequestID , status , time ); err  !=  nil  {
202224			return  err 
203225		}
226+ 		delete (b .invocations , inc .RequestID )
204227	}
205228	return  nil 
206229}
@@ -257,12 +280,16 @@ func (b *Batch) finalizeInvocation(reqID, status string, time time.Time) error {
257280	if  ! ok  {
258281		return  fmt .Errorf ("invocation for requestID %s does not exist" , reqID )
259282	}
260- 	defer  delete (b .invocations , reqID )
261- 	proxyTxn , err  :=  inc .Finalize (status , time )
283+ 	proxyTxn , err  :=  inc .CreateProxyTxn (status , time )
262284	if  err  !=  nil  {
263285		return  err 
264286	}
265- 	return  b .addData (proxyTxn )
287+ 	err  =  b .addData (proxyTxn )
288+ 	if  err  !=  nil  {
289+ 		return  err 
290+ 	}
291+ 	inc .Finalized  =  true 
292+ 	return  nil 
266293}
267294
268295func  (b  * Batch ) addData (data  []byte ) error  {
0 commit comments