@dash0/sdk-web 0.11.2 → 0.12.0

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.
@@ -12,7 +12,6 @@ describe("generateSessionId", () => {
12
12
  vi.spyOn(localStorage, "isSupported", "get").mockReturnValue(true);
13
13
 
14
14
  const sessionId = generateSessionId();
15
- console.log(sessionId);
16
15
  expect(sessionId.startsWith("00")).toBe(true);
17
16
  });
18
17
 
@@ -20,7 +19,6 @@ describe("generateSessionId", () => {
20
19
  vi.spyOn(localStorage, "isSupported", "get").mockReturnValue(false);
21
20
 
22
21
  const sessionId = generateSessionId();
23
- console.log(sessionId);
24
22
  expect(sessionId.startsWith("01")).toBe(true);
25
23
  });
26
24
 
@@ -0,0 +1,9 @@
1
+ import { generateUniqueId, SPAN_ID_BYTES } from "./id";
2
+ import { crc32 } from "./crc32";
3
+
4
+ export function generateSpanId(traceId: string): string {
5
+ const checksum = crc32(traceId);
6
+ const prefix = checksum.toString(16).padStart(8, "0");
7
+
8
+ return `${prefix}${generateUniqueId(SPAN_ID_BYTES - 4)}`;
9
+ }
@@ -0,0 +1,30 @@
1
+ import { describe, expect } from "vitest";
2
+ import { generateSpanId } from "./span-id";
3
+
4
+ describe("generateSpanId", () => {
5
+ it("returns a span ID of the expected length", () => {
6
+ expect(generateSpanId("abcdef1234567890abcdef1234567890")).toHaveLength(16);
7
+ });
8
+
9
+ it("returns the same prefix for the same trace ID", () => {
10
+ const traceId = "abcdef1234567890abcdef1234567890";
11
+ const spanId1 = generateSpanId(traceId);
12
+ const spanId2 = generateSpanId(traceId);
13
+
14
+ expect(spanId1.substring(0, 8)).toBe(spanId2.substring(0, 8));
15
+ expect(spanId1).not.equals(spanId2);
16
+ });
17
+
18
+ it("returns different prefix for span ID for different trace IDs", () => {
19
+ const spanId1 = generateSpanId("abcdef1234567890abcdef1234567890");
20
+ const spanId2 = generateSpanId("1234567890abcdef1234567890abcdef");
21
+
22
+ expect(spanId1.substring(0, 8)).not.equals(spanId2.substring(0, 8));
23
+ expect(spanId1).not.equals(spanId2);
24
+ });
25
+
26
+ it("return a span id with the correct prefix", () => {
27
+ expect(generateSpanId("abcdef1234567890abcdef1234567890").substring(0, 8)).toEqual("3d5a507a");
28
+ expect(generateSpanId("1234567890abcdef1234567890abcdef").substring(0, 8)).toEqual("c24261eb");
29
+ });
30
+ });