@merkl/api 0.10.150 → 0.10.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,43 @@
1
- import { REDIS_READ_TIMEOUT, REDIS_RETRIES, redisClient } from "../../../cache/redis";
1
+ import { REDIS_READ_TIMEOUT, REDIS_RETRIES, REDIS_WRITE_TIMEOUT, redisClient } from "../../../cache/redis";
2
+ import { record } from "@elysiajs/opentelemetry";
2
3
  import { withRetry, withTimeout } from "@sdk";
3
4
  export class CacheRepository {
4
5
  static async set(ttl, key, value) {
5
- await redisClient.set(key, value, { EX: ttl });
6
+ await record("redis.set", async (span) => {
7
+ span.setAttribute("db.system", "redis");
8
+ span.setAttribute("net.transport", "ip_tcp");
9
+ span.setAttribute("db.statement", `set ${key} ${value} ${ttl}`);
10
+ const startTime = Date.now();
11
+ try {
12
+ const result = await withRetry(withTimeout, [redisClient.set(key, value, { EX: ttl }), REDIS_WRITE_TIMEOUT], REDIS_RETRIES);
13
+ span.setAttribute("db.redis.response_time", Date.now() - startTime);
14
+ return result;
15
+ }
16
+ catch (error) {
17
+ span.setStatus({ code: 2 }); // OpenTelemetry StatusCode.ERROR
18
+ span.setAttribute("error.message", error.message);
19
+ span.recordException(error);
20
+ throw error;
21
+ }
22
+ });
6
23
  }
7
24
  static async get(key) {
8
- return await withRetry(withTimeout, [redisClient.get(key), REDIS_READ_TIMEOUT], REDIS_RETRIES);
25
+ return await record("redis.get", async (span) => {
26
+ span.setAttribute("db.system", "redis");
27
+ span.setAttribute("net.transport", "ip_tcp");
28
+ span.setAttribute("db.statement", `get ${key}`);
29
+ const startTime = Date.now();
30
+ try {
31
+ const result = await withRetry(withTimeout, [redisClient.get(key), REDIS_READ_TIMEOUT], REDIS_RETRIES);
32
+ span.setAttribute("db.redis.response_time", Date.now() - startTime);
33
+ return result;
34
+ }
35
+ catch (error) {
36
+ span.setStatus({ code: 2 }); // OpenTelemetry StatusCode.ERROR
37
+ span.setAttribute("error.message", error.message);
38
+ span.recordException(error);
39
+ throw error;
40
+ }
41
+ });
9
42
  }
10
43
  }