Skip to content

Commit

Permalink
Update to TS SDK v4.2.0 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-chambers authored Feb 23, 2024
1 parent c7ef1aa commit 86b98e9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This changelog documents the changes between release versions.
## [Unreleased]
Changes to be included in the next upcoming release

- 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

## [1.0.0] - 2024-02-22
### ndc-lambda-sdk
- 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.
Expand Down
42 changes: 38 additions & 4 deletions ndc-lambda-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ndc-lambda-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"url": "git+https://github.com/hasura/ndc-nodejs-lambda.git"
},
"dependencies": {
"@hasura/ndc-sdk-typescript": "^4.1.0",
"@hasura/ndc-sdk-typescript": "^4.2.0",
"@tsconfig/node18": "^18.2.2",
"commander": "^11.1.0",
"cross-spawn": "^7.0.3",
Expand Down
5 changes: 3 additions & 2 deletions ndc-lambda-sdk/src/execution.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EOL } from "os";
import * as sdk from "@hasura/ndc-sdk-typescript"
import opentelemetry, { SpanStatusCode } from '@opentelemetry/api';
import { withActiveSpan } from "@hasura/ndc-sdk-typescript/instrumentation"
import opentelemetry from '@opentelemetry/api';
import pLimit from "p-limit";
import * as schema from "./schema"
import { isArray, mapObjectValues, unreachable, withActiveSpan } from "./util"
import { isArray, mapObjectValues, unreachable } from "./util"

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

Expand Down
39 changes: 0 additions & 39 deletions ndc-lambda-sdk/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,3 @@ export function getFlags(flagsEnum: Record<string, string | number>, value: numb
export function sleep(ms: number): Promise<void> {
return new Promise((r) => setTimeout(r, ms))
}

export function withActiveSpan<TReturn>(tracer: Tracer, name: string, func: (span: Span) => TReturn, attributes?: Attributes): TReturn {
return tracer.startActiveSpan(name, span => {
if (attributes) span.setAttributes(attributes);

const handleError = (err: unknown) => {
if (err instanceof Error || typeof err === "string") {
span.recordException(err);
}
span.setStatus({ code: SpanStatusCode.ERROR });
span.end();
}

try {
const retval = func(span);
// If the function returns a Promise, then wire up the span completion to
// the completion of the promise
if (typeof retval === "object" && retval !== null && 'then' in retval && typeof retval.then === "function") {
return (retval as PromiseLike<unknown>).then(
successVal => {
span.end();
return successVal;
},
errorVal => {
handleError(errorVal);
throw errorVal;
}) as TReturn;
}
// Not a promise, just end the span and return
else {
span.end();
return retval;
}
} catch (e) {
handleError(e);
throw e;
}
});
}

0 comments on commit 86b98e9

Please sign in to comment.