Skip to content

Commit 363b4d4

Browse files
committed
add getExecutionId() back as req.executionId is not accessible to event driven functions.
1 parent 19a3a4c commit 363b4d4

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

docs/generated/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export interface EventFunctionWithCallback {
5858
(data: {}, context: Context, callback: Function): any;
5959
}
6060

61+
// @public
62+
export const getExecutionId: () => string | undefined;
63+
6164
// @public
6265
export type HandlerFunction<T = unknown, U = unknown> = HttpFunction | EventFunction | EventFunctionWithCallback | CloudEventFunction<T> | CloudEventFunctionWithCallback<T> | TypedFunction<T, U>;
6366

src/async_local_storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ export function getCurrentContext(): ExecutionContext | undefined {
4646
}
4747
return asyncLocalStorage.getStore();
4848
}
49+
50+
export const getCurrentExecutionId = (): string | undefined => {
51+
return getCurrentContext()?.executionId;
52+
};

src/function_registry.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
JsonInvocationFormat,
2121
} from './functions';
2222
import {SignatureType} from './types';
23+
import {getCurrentExecutionId} from './async_local_storage';
2324

2425
interface RegisteredFunction<T, U> {
2526
signatureType: SignatureType;
@@ -65,6 +66,14 @@ export const isValidFunctionName = (functionName: string): boolean => {
6566
return regex.test(functionName);
6667
};
6768

69+
/**
70+
* Gets the request-specific execution id
71+
* @public
72+
*/
73+
export const getExecutionId = (): string | undefined => {
74+
return getCurrentExecutionId();
75+
};
76+
6877
/**
6978
* Get a declaratively registered function
7079
* @param functionName the name with which the function was registered

src/functions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface Request extends ExpressRequest {
3232
* A buffer which provides access to the request's raw HTTP body.
3333
*/
3434
rawBody?: Buffer;
35+
/**
36+
* Request-specified execution id.
37+
*/
3538
executionId?: string;
3639
traceId?: string;
3740
spanId?: string;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export * from './functions';
2020
/**
2121
* @public
2222
*/
23-
export {http, cloudEvent, typed} from './function_registry';
23+
export {http, cloudEvent, typed, getExecutionId} from './function_registry';

0 commit comments

Comments
 (0)