1 |
|
2 |
|
3 |
|
4 | import { Exception, RetryContext, TraceContext } from '@azure/functions';
|
5 | import { RpcException, RpcRetryContext, RpcTraceContext } from '@azure/functions-core';
|
6 | import { copyPropIfDefined, nonNullProp } from '../utils/nonNull';
|
7 |
|
8 | export function fromRpcRetryContext(retryContext: RpcRetryContext | null | undefined): RetryContext | undefined {
|
9 | if (!retryContext) {
|
10 | return undefined;
|
11 | } else {
|
12 | const result: RetryContext = {
|
13 | retryCount: nonNullProp(retryContext, 'retryCount'),
|
14 | maxRetryCount: nonNullProp(retryContext, 'maxRetryCount'),
|
15 | };
|
16 | if (retryContext.exception) {
|
17 | result.exception = fromRpcException(retryContext.exception);
|
18 | }
|
19 | return result;
|
20 | }
|
21 | }
|
22 |
|
23 | function fromRpcException(exception: RpcException): Exception {
|
24 | const result: Exception = {};
|
25 | copyPropIfDefined(exception, result, 'message');
|
26 | copyPropIfDefined(exception, result, 'source');
|
27 | copyPropIfDefined(exception, result, 'stackTrace');
|
28 | return result;
|
29 | }
|
30 |
|
31 | export function fromRpcTraceContext(traceContext: RpcTraceContext | null | undefined): TraceContext | undefined {
|
32 | if (!traceContext) {
|
33 | return undefined;
|
34 | } else {
|
35 | const result: TraceContext = {};
|
36 | copyPropIfDefined(traceContext, result, 'traceParent');
|
37 | copyPropIfDefined(traceContext, result, 'traceState');
|
38 | if (traceContext.attributes) {
|
39 | result.attributes = traceContext.attributes;
|
40 | }
|
41 | return result;
|
42 | }
|
43 | }
|