@squiz/db-lib 1.69.0 → 1.70.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.70.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",
@@ -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;
@@ -47,10 +50,24 @@ export class DynamoDbManager<TRepositories> {
47
50
  throw new TransactionError(`No items in transaction '${transactionId}' to execute`);
48
51
  }
49
52
 
50
- return await this.client.transactWrite({
51
- ClientRequestToken: transactionId,
52
- TransactItems: this.transactionItems[transactionId],
53
- });
53
+ return tracer.startActiveSpan(
54
+ 'executeTransaction',
55
+ {
56
+ attributes: {
57
+ 'transactionItems.length': this.transactionItems[transactionId].length,
58
+ },
59
+ },
60
+ async (span) => {
61
+ try {
62
+ return await this.client.transactWrite({
63
+ ClientRequestToken: transactionId,
64
+ TransactItems: this.transactionItems[transactionId],
65
+ });
66
+ } finally {
67
+ span.end();
68
+ }
69
+ },
70
+ );
54
71
  }
55
72
 
56
73
  private startTransaction(transactionId: string) {