Skip to content

Commit 86b98e9

Browse files
Update to TS SDK v4.2.0 (#14)
1 parent c7ef1aa commit 86b98e9

File tree

5 files changed

+44
-46
lines changed

5 files changed

+44
-46
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This changelog documents the changes between release versions.
77
## [Unreleased]
88
Changes to be included in the next upcoming release
99

10+
- Updated to [NDC TypeScript SDK v4.2.0](https://github.com/hasura/ndc-sdk-typescript/releases/tag/v4.2.0) to include OpenTelemetry improvements. Traced spans should now appear in the Hasura Console
11+
1012
## [1.0.0] - 2024-02-22
1113
### ndc-lambda-sdk
1214
- Support for NDC Spec v0.1.0-rc.15 via the NDC TypeScript SDK v4.1.0 ([#8](https://github.com/hasura/ndc-nodejs-lambda/pull/8), [#10](https://github.com/hasura/ndc-nodejs-lambda/pull/11), [#13](https://github.com/hasura/ndc-nodejs-lambda/pull/13)). This is a breaking change and must be used with the latest Hasura engine.

ndc-lambda-sdk/package-lock.json

Lines changed: 38 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ndc-lambda-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"url": "git+https://github.com/hasura/ndc-nodejs-lambda.git"
3131
},
3232
"dependencies": {
33-
"@hasura/ndc-sdk-typescript": "^4.1.0",
33+
"@hasura/ndc-sdk-typescript": "^4.2.0",
3434
"@tsconfig/node18": "^18.2.2",
3535
"commander": "^11.1.0",
3636
"cross-spawn": "^7.0.3",

ndc-lambda-sdk/src/execution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { EOL } from "os";
22
import * as sdk from "@hasura/ndc-sdk-typescript"
3-
import opentelemetry, { SpanStatusCode } from '@opentelemetry/api';
3+
import { withActiveSpan } from "@hasura/ndc-sdk-typescript/instrumentation"
4+
import opentelemetry from '@opentelemetry/api';
45
import pLimit from "p-limit";
56
import * as schema from "./schema"
6-
import { isArray, mapObjectValues, unreachable, withActiveSpan } from "./util"
7+
import { isArray, mapObjectValues, unreachable } from "./util"
78

89
const tracer = opentelemetry.trace.getTracer("nodejs-lambda-sdk.execution");
910

ndc-lambda-sdk/src/util.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,3 @@ export function getFlags(flagsEnum: Record<string, string | number>, value: numb
3535
export function sleep(ms: number): Promise<void> {
3636
return new Promise((r) => setTimeout(r, ms))
3737
}
38-
39-
export function withActiveSpan<TReturn>(tracer: Tracer, name: string, func: (span: Span) => TReturn, attributes?: Attributes): TReturn {
40-
return tracer.startActiveSpan(name, span => {
41-
if (attributes) span.setAttributes(attributes);
42-
43-
const handleError = (err: unknown) => {
44-
if (err instanceof Error || typeof err === "string") {
45-
span.recordException(err);
46-
}
47-
span.setStatus({ code: SpanStatusCode.ERROR });
48-
span.end();
49-
}
50-
51-
try {
52-
const retval = func(span);
53-
// If the function returns a Promise, then wire up the span completion to
54-
// the completion of the promise
55-
if (typeof retval === "object" && retval !== null && 'then' in retval && typeof retval.then === "function") {
56-
return (retval as PromiseLike<unknown>).then(
57-
successVal => {
58-
span.end();
59-
return successVal;
60-
},
61-
errorVal => {
62-
handleError(errorVal);
63-
throw errorVal;
64-
}) as TReturn;
65-
}
66-
// Not a promise, just end the span and return
67-
else {
68-
span.end();
69-
return retval;
70-
}
71-
} catch (e) {
72-
handleError(e);
73-
throw e;
74-
}
75-
});
76-
}

0 commit comments

Comments
 (0)