@dash0/sdk-web 0.14.1 → 0.16.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.
Files changed (38) hide show
  1. package/README.md +77 -6
  2. package/dist/dash0.iife.js +1 -1
  3. package/dist/dash0.iife.js.map +1 -1
  4. package/dist/dash0.js +1 -1
  5. package/dist/dash0.js.map +1 -1
  6. package/dist/dash0.umd.cjs +1 -1
  7. package/dist/dash0.umd.cjs.map +1 -1
  8. package/dist/modules/api/init.js +30 -0
  9. package/dist/modules/api/init_test.js +102 -6
  10. package/dist/modules/instrumentations/http/fetch.js +47 -5
  11. package/dist/modules/instrumentations/http/fetch_test.js +170 -0
  12. package/dist/modules/instrumentations/http/propagator-integration_test.js +77 -0
  13. package/dist/modules/transport/index.js +1 -3
  14. package/dist/modules/utils/otel/trace-context.js +24 -1
  15. package/dist/modules/utils/otel/trace-context_test.js +40 -0
  16. package/dist/modules/utils/rate-limit.js +1 -5
  17. package/dist/tsconfig.tsbuildinfo +1 -1
  18. package/dist/types/entrypoint/npm-package.d.ts +1 -1
  19. package/dist/types/instrumentations/http/fetch_test.d.ts +1 -0
  20. package/dist/types/instrumentations/http/propagator-integration_test.d.ts +1 -0
  21. package/dist/types/types/options.d.ts +6 -1
  22. package/dist/types/utils/otel/trace-context.d.ts +2 -1
  23. package/dist/types/utils/otel/trace-context_test.d.ts +1 -0
  24. package/dist/types/utils/rate-limit.d.ts +0 -1
  25. package/dist/types/vars.d.ts +11 -0
  26. package/package.json +1 -1
  27. package/src/api/init.ts +34 -0
  28. package/src/api/init_test.ts +130 -9
  29. package/src/entrypoint/npm-package.ts +1 -1
  30. package/src/instrumentations/http/fetch.ts +59 -6
  31. package/src/instrumentations/http/fetch_test.ts +191 -0
  32. package/src/instrumentations/http/propagator-integration_test.ts +93 -0
  33. package/src/transport/index.ts +1 -3
  34. package/src/types/options.ts +7 -1
  35. package/src/utils/otel/trace-context.ts +30 -1
  36. package/src/utils/otel/trace-context_test.ts +59 -0
  37. package/src/utils/rate-limit.ts +2 -12
  38. package/src/vars.ts +14 -0
@@ -0,0 +1,59 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { addXRayTraceContextHttpHeaders } from "./trace-context";
3
+ import { InProgressSpan } from "./span";
4
+
5
+ describe("X-Ray trace context", () => {
6
+ it("should generate X-Ray header with correct format", () => {
7
+ const span = {
8
+ traceId: "4efaaf4d1e8720b39541901950019ee5",
9
+ spanId: "53995c3f42cd8ad8",
10
+ } as InProgressSpan;
11
+
12
+ const headers: Record<string, string> = {};
13
+ const mockAppend = (name: string, value: string) => {
14
+ headers[name] = value;
15
+ };
16
+
17
+ addXRayTraceContextHttpHeaders(mockAppend, {}, span);
18
+
19
+ expect(headers["X-Amzn-Trace-Id"]).toBe(
20
+ "Root=1-4efaaf4d-1e8720b39541901950019ee5;Parent=53995c3f42cd8ad8;Sampled=1"
21
+ );
22
+ });
23
+
24
+ it("should convert W3C trace ID to X-Ray format correctly", () => {
25
+ const span = {
26
+ traceId: "5759e988bd862e3fe1be46a994272793",
27
+ spanId: "53995c3f42cd8ad8",
28
+ } as InProgressSpan;
29
+
30
+ const headers: Record<string, string> = {};
31
+ const mockAppend = (name: string, value: string) => {
32
+ headers[name] = value;
33
+ };
34
+
35
+ addXRayTraceContextHttpHeaders(mockAppend, {}, span);
36
+
37
+ expect(headers["X-Amzn-Trace-Id"]).toBe(
38
+ "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1"
39
+ );
40
+ });
41
+
42
+ it("should handle different span IDs", () => {
43
+ const span = {
44
+ traceId: "4efaaf4d1e8720b39541901950019ee5",
45
+ spanId: "1234567890abcdef",
46
+ } as InProgressSpan;
47
+
48
+ const headers: Record<string, string> = {};
49
+ const mockAppend = (name: string, value: string) => {
50
+ headers[name] = value;
51
+ };
52
+
53
+ addXRayTraceContextHttpHeaders(mockAppend, {}, span);
54
+
55
+ expect(headers["X-Amzn-Trace-Id"]).toBe(
56
+ "Root=1-4efaaf4d-1e8720b39541901950019ee5;Parent=1234567890abcdef;Sampled=1"
57
+ );
58
+ });
59
+ });
@@ -1,15 +1,9 @@
1
1
  import { setInterval } from "./timers";
2
2
 
3
- export function createRateLimiter(opts: {
4
- maxCalls?: number;
5
- maxCallsPerTenMinutes: number;
6
- maxCallsPerTenSeconds: number;
7
- }) {
8
- const maxCalls = opts.maxCalls || 4096;
3
+ export function createRateLimiter(opts: { maxCallsPerTenMinutes: number; maxCallsPerTenSeconds: number }) {
9
4
  const maxCallsPerTenMinutes = opts.maxCallsPerTenMinutes || 128;
10
5
  const maxCallsPerTenSeconds = opts.maxCallsPerTenSeconds || 32;
11
6
 
12
- let totalCalls = 0;
13
7
  let totalCallsInLastTenMinutes = 0;
14
8
  let totalCallsInLastTenSeconds = 0;
15
9
 
@@ -25,10 +19,6 @@ export function createRateLimiter(opts: {
25
19
  }, 1000 * 10);
26
20
 
27
21
  return function isExcessiveUsage() {
28
- return (
29
- ++totalCalls > maxCalls ||
30
- ++totalCallsInLastTenMinutes > maxCallsPerTenMinutes ||
31
- ++totalCallsInLastTenSeconds > maxCallsPerTenSeconds
32
- );
22
+ return ++totalCallsInLastTenMinutes > maxCallsPerTenMinutes || ++totalCallsInLastTenSeconds > maxCallsPerTenSeconds;
33
23
  };
34
24
  }
package/src/vars.ts CHANGED
@@ -3,6 +3,13 @@ import { AnyValue, InstrumentationScope, KeyValue, Resource } from "./types/otlp
3
3
  import { UrlAttributeScrubber } from "./attributes";
4
4
  import { identity } from "./utils";
5
5
 
6
+ export type PropagatorType = "traceparent" | "xray";
7
+
8
+ export type PropagatorConfig = {
9
+ type: PropagatorType;
10
+ match: RegExp[];
11
+ };
12
+
6
13
  export type Endpoint = {
7
14
  /**
8
15
  * OTLP HTTP URL excluding the /v1/* prefix
@@ -108,9 +115,16 @@ export type Vars = {
108
115
  */
109
116
  wrapTimers: boolean;
110
117
 
118
+ /**
119
+ * Configure trace context propagators for different URL patterns.
120
+ * Each propagator defines which header type to send for matching URLs.
121
+ */
122
+ propagators?: PropagatorConfig[];
123
+
111
124
  /**
112
125
  * An array of URL regular expressions
113
126
  * for which trace context headers should be sent across origins by http client instrumentations.
127
+ * @deprecated Use propagators instead
114
128
  */
115
129
  propagateTraceHeadersCorsURLs: RegExp[];
116
130