@squiz/db-lib 1.69.0 → 1.71.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/db-lib",
3
- "version": "1.69.0",
3
+ "version": "1.71.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -35,6 +35,7 @@
35
35
  "@aws-sdk/client-dynamodb": "^3.632.0",
36
36
  "@aws-sdk/client-secrets-manager": "3.614.0",
37
37
  "@aws-sdk/lib-dynamodb": "^3.632.0",
38
+ "@opentelemetry/api": "^1.6.0",
38
39
  "@squiz/dx-common-lib": "^1.66.4",
39
40
  "@squiz/dx-logger-lib": "^1.64.0",
40
41
  "dotenv": "16.0.3",
@@ -774,7 +774,6 @@ describe('AbstractRepository', () => {
774
774
  TransactItems: [
775
775
  {
776
776
  Delete: {
777
- ConditionExpression: 'attribute_exists(pk)',
778
777
  Key: {
779
778
  pk: 'test_item#foo',
780
779
  sk: '#meta',
@@ -307,6 +307,8 @@ export abstract class AbstractDynamoDbRepository<SHAPE extends object, DATA_CLAS
307
307
  };
308
308
 
309
309
  if (transaction.id?.length) {
310
+ // For transaction block, don't worry if the item being deleted does not exist
311
+ delete deleteCommandInput.ConditionExpression;
310
312
  // this command will be executed together with
311
313
  // other db write commands in the "transaction block"
312
314
  this.dbManager.addWriteTransactionItem(transaction.id, {
@@ -1,6 +1,9 @@
1
1
  import { DynamoDBDocument, TransactWriteCommandInput } from '@aws-sdk/lib-dynamodb';
2
2
  import { randomUUID } from 'crypto';
3
3
  import { TransactionError } from '../error/TransactionError';
4
+ import { trace } from '@opentelemetry/api';
5
+
6
+ const tracer = trace.getTracer('db-lib:DynamoDbManager');
4
7
 
5
8
  export type Transaction = {
6
9
  id?: string;
@@ -46,11 +49,28 @@ export class DynamoDbManager<TRepositories> {
46
49
  if (this.transactionItems[transactionId] === undefined) {
47
50
  throw new TransactionError(`No items in transaction '${transactionId}' to execute`);
48
51
  }
52
+ if (!this.transactionItems[transactionId].length) {
53
+ return;
54
+ }
49
55
 
50
- return await this.client.transactWrite({
51
- ClientRequestToken: transactionId,
52
- TransactItems: this.transactionItems[transactionId],
53
- });
56
+ return tracer.startActiveSpan(
57
+ 'executeTransaction',
58
+ {
59
+ attributes: {
60
+ 'transactionItems.length': this.transactionItems[transactionId].length,
61
+ },
62
+ },
63
+ async (span) => {
64
+ try {
65
+ return await this.client.transactWrite({
66
+ ClientRequestToken: transactionId,
67
+ TransactItems: this.transactionItems[transactionId],
68
+ });
69
+ } finally {
70
+ span.end();
71
+ }
72
+ },
73
+ );
54
74
  }
55
75
 
56
76
  private startTransaction(transactionId: string) {