@ogcio/o11y-sdk-node 0.4.2 → 0.6.1

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 (140) hide show
  1. package/dist/sdk-core/index.d.ts +1 -0
  2. package/dist/sdk-core/index.js +1 -0
  3. package/dist/sdk-core/lib/index.d.ts +2 -0
  4. package/dist/sdk-core/lib/index.js +2 -0
  5. package/dist/sdk-core/lib/redaction/basic-redactor.d.ts +7 -0
  6. package/dist/sdk-core/lib/redaction/basic-redactor.js +18 -0
  7. package/dist/sdk-core/lib/redaction/email-redactor.d.ts +8 -0
  8. package/dist/sdk-core/lib/redaction/email-redactor.js +17 -0
  9. package/dist/sdk-core/lib/redaction/index.d.ts +9 -0
  10. package/dist/sdk-core/lib/redaction/index.js +4 -0
  11. package/dist/sdk-core/lib/redaction/ip-redactor.d.ts +9 -0
  12. package/dist/sdk-core/lib/redaction/ip-redactor.js +23 -0
  13. package/dist/sdk-core/lib/redaction/ppsn-redactor.d.ts +8 -0
  14. package/dist/sdk-core/lib/redaction/ppsn-redactor.js +17 -0
  15. package/dist/sdk-core/lib/utils/data-structures.d.ts +15 -0
  16. package/dist/{lib/internals/redaction/pii-detection.js → sdk-core/lib/utils/data-structures.js} +4 -27
  17. package/dist/sdk-core/lib/utils/index.d.ts +2 -0
  18. package/dist/sdk-core/lib/utils/index.js +2 -0
  19. package/dist/sdk-core/lib/utils/string-decoding.d.ts +7 -0
  20. package/dist/sdk-core/lib/utils/string-decoding.js +22 -0
  21. package/dist/{index.d.ts → sdk-node/index.d.ts} +1 -0
  22. package/dist/{index.js → sdk-node/index.js} +1 -0
  23. package/dist/{lib → sdk-node/lib}/config-manager.d.ts +1 -1
  24. package/dist/sdk-node/lib/exporter/console.d.ts +3 -0
  25. package/dist/sdk-node/lib/exporter/grpc.d.ts +3 -0
  26. package/dist/sdk-node/lib/exporter/http.d.ts +3 -0
  27. package/dist/{lib → sdk-node/lib}/exporter/index.d.ts +2 -2
  28. package/dist/{lib → sdk-node/lib}/exporter/pii-exporter-decorator.d.ts +5 -5
  29. package/dist/{lib → sdk-node/lib}/exporter/pii-exporter-decorator.js +6 -2
  30. package/dist/sdk-node/lib/exporter/processor-config.d.ts +7 -0
  31. package/dist/{lib → sdk-node/lib}/exporter/processor-config.js +4 -0
  32. package/dist/{lib → sdk-node/lib}/index.d.ts +11 -0
  33. package/dist/{lib → sdk-node/lib}/instrumentation.node.js +1 -1
  34. package/dist/sdk-node/lib/internals/redaction/redactors/email.d.ts +8 -0
  35. package/dist/sdk-node/lib/internals/redaction/redactors/email.js +19 -0
  36. package/dist/sdk-node/lib/internals/redaction/redactors/index.d.ts +16 -0
  37. package/dist/sdk-node/lib/internals/redaction/redactors/index.js +13 -0
  38. package/dist/sdk-node/lib/internals/redaction/redactors/ip.d.ts +8 -0
  39. package/dist/sdk-node/lib/internals/redaction/redactors/ip.js +20 -0
  40. package/dist/sdk-node/lib/internals/redaction/redactors/ppsn.d.ts +8 -0
  41. package/dist/sdk-node/lib/internals/redaction/redactors/ppsn.js +18 -0
  42. package/dist/{lib → sdk-node/lib}/metrics.d.ts +1 -1
  43. package/dist/{lib → sdk-node/lib}/processor/enrich-logger-processor.d.ts +3 -3
  44. package/dist/{lib → sdk-node/lib}/processor/enrich-span-processor.d.ts +3 -3
  45. package/dist/sdk-node/lib/processor/nextjs-logger-processor.d.ts +7 -0
  46. package/dist/sdk-node/lib/processor/nextjs-logger-processor.js +30 -0
  47. package/dist/sdk-node/lib/processor/nextjs-span-processor.d.ts +8 -0
  48. package/dist/sdk-node/lib/processor/nextjs-span-processor.js +25 -0
  49. package/dist/{lib → sdk-node/lib}/resource.d.ts +2 -2
  50. package/dist/{lib → sdk-node/lib}/traces.d.ts +1 -1
  51. package/dist/{lib → sdk-node/lib}/traces.js +1 -1
  52. package/dist/{lib → sdk-node/lib}/url-sampler.d.ts +3 -3
  53. package/dist/{lib → sdk-node/lib}/utils.d.ts +1 -1
  54. package/dist/sdk-node/package.json +62 -0
  55. package/package.json +28 -25
  56. package/CHANGELOG.md +0 -233
  57. package/dist/lib/exporter/console.d.ts +0 -3
  58. package/dist/lib/exporter/grpc.d.ts +0 -3
  59. package/dist/lib/exporter/http.d.ts +0 -3
  60. package/dist/lib/exporter/processor-config.d.ts +0 -5
  61. package/dist/lib/internals/redaction/pii-detection.d.ts +0 -25
  62. package/dist/lib/internals/redaction/redactors/email.d.ts +0 -8
  63. package/dist/lib/internals/redaction/redactors/email.js +0 -48
  64. package/dist/lib/internals/redaction/redactors/index.d.ts +0 -4
  65. package/dist/lib/internals/redaction/redactors/index.js +0 -6
  66. package/dist/lib/internals/redaction/redactors/ip.d.ts +0 -10
  67. package/dist/lib/internals/redaction/redactors/ip.js +0 -54
  68. package/dist/lib/internals/shared-metrics.d.ts +0 -7
  69. package/dist/lib/internals/shared-metrics.js +0 -18
  70. package/dist/package.json +0 -59
  71. package/dist/vitest.config.d.ts +0 -2
  72. package/dist/vitest.config.js +0 -45
  73. package/index.ts +0 -9
  74. package/lib/config-manager.ts +0 -12
  75. package/lib/exporter/console.ts +0 -33
  76. package/lib/exporter/grpc.ts +0 -65
  77. package/lib/exporter/http.ts +0 -56
  78. package/lib/exporter/index.ts +0 -9
  79. package/lib/exporter/pii-exporter-decorator.ts +0 -187
  80. package/lib/exporter/processor-config.ts +0 -23
  81. package/lib/index.ts +0 -118
  82. package/lib/instrumentation.node.ts +0 -115
  83. package/lib/internals/hooks.ts +0 -14
  84. package/lib/internals/redaction/pii-detection.ts +0 -113
  85. package/lib/internals/redaction/redactors/email.ts +0 -58
  86. package/lib/internals/redaction/redactors/index.ts +0 -12
  87. package/lib/internals/redaction/redactors/ip.ts +0 -68
  88. package/lib/internals/shared-metrics.ts +0 -34
  89. package/lib/metrics.ts +0 -75
  90. package/lib/processor/enrich-logger-processor.ts +0 -34
  91. package/lib/processor/enrich-span-processor.ts +0 -39
  92. package/lib/resource.ts +0 -30
  93. package/lib/traces.ts +0 -78
  94. package/lib/url-sampler.ts +0 -52
  95. package/lib/utils.ts +0 -22
  96. package/test/config-manager.test.ts +0 -34
  97. package/test/exporter/pii-exporter-decorator.test.ts +0 -88
  98. package/test/index.test.ts +0 -70
  99. package/test/integration/README.md +0 -74
  100. package/test/integration/docker-utils.sh +0 -214
  101. package/test/integration/main.sh +0 -52
  102. package/test/integration/teardown.sh +0 -7
  103. package/test/integration/test_fastify-o11y-pii-enabled/http-tracing.integration.test.ts +0 -56
  104. package/test/integration/test_fastify-o11y-pii-enabled/pii.integration.test.ts +0 -68
  105. package/test/integration/test_fastify-o11y-pii-enabled/run.sh +0 -42
  106. package/test/integration/test_without-o11y/run.sh +0 -30
  107. package/test/integration/test_without-o11y/verify-status.integration.test.ts +0 -32
  108. package/test/internals/hooks.test.ts +0 -45
  109. package/test/internals/pii-detection.test.ts +0 -265
  110. package/test/internals/redactors/email.test.ts +0 -81
  111. package/test/internals/redactors/ip.test.ts +0 -93
  112. package/test/internals/shared-metrics.test.ts +0 -34
  113. package/test/metrics.test.ts +0 -142
  114. package/test/node-config.test.ts +0 -190
  115. package/test/processor/enrich-logger-processor.test.ts +0 -58
  116. package/test/processor/enrich-span-processor.test.ts +0 -52
  117. package/test/resource.test.ts +0 -33
  118. package/test/traces/active-span.test.ts +0 -26
  119. package/test/traces/with-span.test.ts +0 -356
  120. package/test/url-sampler.test.ts +0 -215
  121. package/test/utils/alloy-log-parser.ts +0 -53
  122. package/test/utils/mock-signals.ts +0 -144
  123. package/test/validation.test.ts +0 -103
  124. package/tsconfig.json +0 -15
  125. package/vitest.config.ts +0 -46
  126. /package/dist/{lib → sdk-node/lib}/config-manager.js +0 -0
  127. /package/dist/{lib → sdk-node/lib}/exporter/console.js +0 -0
  128. /package/dist/{lib → sdk-node/lib}/exporter/grpc.js +0 -0
  129. /package/dist/{lib → sdk-node/lib}/exporter/http.js +0 -0
  130. /package/dist/{lib → sdk-node/lib}/exporter/index.js +0 -0
  131. /package/dist/{lib → sdk-node/lib}/index.js +0 -0
  132. /package/dist/{lib → sdk-node/lib}/instrumentation.node.d.ts +0 -0
  133. /package/dist/{lib → sdk-node/lib}/internals/hooks.d.ts +0 -0
  134. /package/dist/{lib → sdk-node/lib}/internals/hooks.js +0 -0
  135. /package/dist/{lib → sdk-node/lib}/metrics.js +0 -0
  136. /package/dist/{lib → sdk-node/lib}/processor/enrich-logger-processor.js +0 -0
  137. /package/dist/{lib → sdk-node/lib}/processor/enrich-span-processor.js +0 -0
  138. /package/dist/{lib → sdk-node/lib}/resource.js +0 -0
  139. /package/dist/{lib → sdk-node/lib}/url-sampler.js +0 -0
  140. /package/dist/{lib → sdk-node/lib}/utils.js +0 -0
@@ -1,93 +0,0 @@
1
- import {
2
- describe,
3
- expect,
4
- it,
5
- vi,
6
- beforeEach,
7
- beforeAll,
8
- afterAll,
9
- } from "vitest";
10
-
11
- import * as sharedMetrics from "../../../lib/internals/shared-metrics.js";
12
- import { ipRedactor } from "../../../lib/internals/redaction/redactors/ip";
13
-
14
- describe("IP Redaction utils", () => {
15
- describe("tracks metrics", () => {
16
- const mockMetricAdd = vi.fn();
17
-
18
- beforeEach(() => {
19
- vi.restoreAllMocks();
20
- vi.spyOn(sharedMetrics, "_getPIICounterRedactionMetric").mockReturnValue({
21
- add: mockMetricAdd,
22
- });
23
- });
24
-
25
- it("redacts plain PII and tracks redaction with metric", () => {
26
- const input = "255.255.255.255";
27
- const output = ipRedactor(input, "log", "string");
28
-
29
- expect(output).toBe("[REDACTED IPV4]");
30
- expect(mockMetricAdd).toHaveBeenCalledWith(
31
- 1,
32
- expect.objectContaining({
33
- pii_format: "string",
34
- pii_type: "IPv4",
35
- redaction_source: "log",
36
- }),
37
- );
38
- });
39
-
40
- it("handles strings without PII unchanged", () => {
41
- const input = "hello world";
42
- const output = ipRedactor(input, "log", "string");
43
-
44
- expect(output).toBe("hello world");
45
- expect(mockMetricAdd).not.toHaveBeenCalled();
46
- });
47
- });
48
-
49
- describe("Redacts IPv4 and IPv6", () => {
50
- beforeAll(() => {
51
- vi.spyOn(sharedMetrics, "_getPIICounterRedactionMetric").mockReturnValue({
52
- add: vi.fn(),
53
- });
54
- });
55
-
56
- afterAll(() => {
57
- vi.restoreAllMocks();
58
- });
59
-
60
- it.each`
61
- value | expectedRedactedValue
62
- ${"hello world"} | ${"hello world"}
63
- ${"hello 127.0.0.1"} | ${"hello [REDACTED IPV4]"}
64
- ${"127.0.0.1, hello!"} | ${"[REDACTED IPV4], hello!"}
65
- ${"127.0.0.1,127.0.0.1"} | ${"[REDACTED IPV4],[REDACTED IPV4]"}
66
- ${"127.0.0.1127.0.0.1"} | ${"127.0.0.1127.0.0.1"}
67
- ${"256.1.1.1"} | ${"256.1.1.1"}
68
- ${"0.0.0.0!"} | ${"[REDACTED IPV4]!"}
69
- ${"text0.0.0.0"} | ${"text[REDACTED IPV4]"}
70
- ${"%A00.0.0.0"} | ${"[REDACTED IPV4]"}
71
- ${"0.0.0.0%20"} | ${"[REDACTED IPV4]"}
72
- ${"0.0.text0.0"} | ${"0.0.text0.0"}
73
- ${"2001:0db8::1"} | ${"[REDACTED IPV6]"}
74
- ${"::1"} | ${"[REDACTED IPV6]"}
75
- ${"%20::1"} | ${"[REDACTED IPV6]"}
76
- ${"::1%A0"} | ${"[REDACTED IPV6]"}
77
- ${"text::1"} | ${"text[REDACTED IPV6]"}
78
- ${"::1text"} | ${"[REDACTED IPV6]text"}
79
- ${"sentence ending with f::1"} | ${"sentence ending with [REDACTED IPV6]"}
80
- ${"sentence ending with :::1"} | ${"sentence ending with :::1"}
81
- ${"2001:0DB8:85A3:0000:0000:8A2E:0370:7334::1"} | ${"2001:0DB8:85A3:0000:0000:8A2E:0370:7334::1"}
82
- ${"2001:0DB8:85A3:0000:text:8A2E:0370:7334"} | ${"2001:0DB8:85A3:0000:text:8A2E:0370:7334"}
83
- ${"2001:0db8::12001:0db8::1"} | ${"2001:0db8::12001:0db8::1"}
84
- ${"2001:0db8::1,2001:0db8::1"} | ${"[REDACTED IPV6],[REDACTED IPV6]"}
85
- `(
86
- "returns $expectedRedactedValue for value '$value'",
87
- async ({ value, expectedRedactedValue }: Record<string, string>) => {
88
- const result = ipRedactor(value, "log", "string");
89
- expect(result).toBe(expectedRedactedValue);
90
- },
91
- );
92
- });
93
- });
@@ -1,34 +0,0 @@
1
- vi.mock("../../lib/metrics", () => {
2
- return {
3
- getMetric: vi.fn(),
4
- };
5
- });
6
-
7
- import { describe, it, expect, vi, beforeEach } from "vitest";
8
- import { _getPIICounterRedactionMetric } from "../../lib/internals/shared-metrics.js";
9
- import { getMetric } from "../../lib/metrics"; // Get the mocked function
10
-
11
- describe("shared metrics", () => {
12
- const mockMetric = { add: vi.fn() };
13
-
14
- beforeEach(() => {
15
- vi.resetModules(); // Clear module-level cache
16
- vi.restoreAllMocks();
17
- (getMetric as vi.Mock).mockClear(); // clear call history
18
- (getMetric as vi.Mock).mockReturnValue(mockMetric);
19
- });
20
-
21
- it("calls getMetric with correct arguments and caches result", () => {
22
- const metric1 = _getPIICounterRedactionMetric();
23
- const metric2 = _getPIICounterRedactionMetric();
24
-
25
- expect(getMetric).toHaveBeenCalledOnce();
26
- expect(getMetric).toHaveBeenCalledWith("counter", {
27
- meterName: "o11y",
28
- metricName: "o11y_pii_redaction",
29
- });
30
-
31
- expect(metric1).toBe(mockMetric);
32
- expect(metric2).toBe(mockMetric); // should be cached
33
- });
34
- });
@@ -1,142 +0,0 @@
1
- import { describe, test, expect, vi, beforeEach, assert } from "vitest";
2
- import { getMetric, MetricsParams } from "../lib/metrics";
3
-
4
- const mockMeter = {
5
- createGauge: vi.fn(),
6
- createHistogram: vi.fn(),
7
- createCounter: vi.fn(),
8
- createUpDownCounter: vi.fn(),
9
- createObservableCounter: vi.fn(),
10
- createObservableUpDownCounter: vi.fn(),
11
- createObservableGauge: vi.fn(),
12
- };
13
-
14
- vi.mock("@opentelemetry/api", async () => {
15
- const { createNoopMeter } = await import("@opentelemetry/api");
16
-
17
- return {
18
- metrics: {
19
- getMeter: vi.fn(() => mockMeter),
20
- },
21
- createNoopMeter: createNoopMeter,
22
- };
23
- });
24
-
25
- describe("MetricsFactoryMap", () => {
26
- beforeEach(() => {
27
- vi.clearAllMocks();
28
- });
29
-
30
- const validMetricParams: MetricsParams = {
31
- metricName: "test-metric",
32
- meterName: "test-meter",
33
- options: { description: "A test metric" },
34
- };
35
-
36
- test("should call createGauge when type is 'gauge'", () => {
37
- mockMeter.createGauge.mockReturnValue("mocked-gauge");
38
-
39
- const result = getMetric("gauge", validMetricParams);
40
-
41
- expect(result).toBe("mocked-gauge");
42
- expect(mockMeter.createGauge).toHaveBeenCalledWith(
43
- validMetricParams.metricName,
44
- validMetricParams.options,
45
- );
46
- });
47
-
48
- test("should call createHistogram when type is 'histogram'", () => {
49
- mockMeter.createHistogram.mockReturnValue("mocked-histogram");
50
-
51
- const result = getMetric("histogram", validMetricParams);
52
-
53
- expect(result).toBe("mocked-histogram");
54
- expect(mockMeter.createHistogram).toHaveBeenCalledWith(
55
- validMetricParams.metricName,
56
- validMetricParams.options,
57
- );
58
- });
59
-
60
- test("should call createCounter when type is 'counter'", () => {
61
- mockMeter.createCounter.mockReturnValue("mocked-counter");
62
-
63
- const result = getMetric("counter", validMetricParams);
64
-
65
- expect(result).toBe("mocked-counter");
66
- expect(mockMeter.createCounter).toHaveBeenCalledWith(
67
- validMetricParams.metricName,
68
- validMetricParams.options,
69
- );
70
- });
71
-
72
- test("should call createUpDownCounter when type is 'updowncounter'", () => {
73
- mockMeter.createUpDownCounter.mockReturnValue("mocked-updowncounter");
74
-
75
- const result = getMetric("updowncounter", validMetricParams);
76
-
77
- expect(result).toBe("mocked-updowncounter");
78
- expect(mockMeter.createUpDownCounter).toHaveBeenCalledWith(
79
- validMetricParams.metricName,
80
- validMetricParams.options,
81
- );
82
- });
83
-
84
- test("should call createObservableCounter when type is 'async-counter'", () => {
85
- mockMeter.createObservableCounter.mockReturnValue("mocked-async-counter");
86
-
87
- const result = getMetric("async-counter", validMetricParams);
88
-
89
- expect(result).toBe("mocked-async-counter");
90
- expect(mockMeter.createObservableCounter).toHaveBeenCalledWith(
91
- validMetricParams.metricName,
92
- validMetricParams.options,
93
- );
94
- });
95
-
96
- test("should call createObservableUpDownCounter when type is 'async-updowncounter'", () => {
97
- mockMeter.createObservableUpDownCounter.mockReturnValue(
98
- "mocked-async-updowncounter",
99
- );
100
-
101
- const result = getMetric("async-updowncounter", validMetricParams);
102
-
103
- expect(result).toBe("mocked-async-updowncounter");
104
- expect(mockMeter.createObservableUpDownCounter).toHaveBeenCalledWith(
105
- validMetricParams.metricName,
106
- validMetricParams.options,
107
- );
108
- });
109
-
110
- test("should call createObservableGauge when type is 'async-gauge'", () => {
111
- mockMeter.createObservableGauge.mockReturnValue("mocked-async-gauge");
112
-
113
- const result = getMetric("async-gauge", validMetricParams);
114
-
115
- expect(result).toBe("mocked-async-gauge");
116
- expect(mockMeter.createObservableGauge).toHaveBeenCalledWith(
117
- validMetricParams.metricName,
118
- validMetricParams.options,
119
- );
120
- });
121
-
122
- test("should throw an error for unsupported metric types", () => {
123
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
- const invalidMetricType = "invalid-type" as any;
125
-
126
- expect(() => getMetric(invalidMetricType, validMetricParams)).toThrow(
127
- `Unsupported metric type: ${invalidMetricType}`,
128
- );
129
- });
130
-
131
- test("should return noop metric fallback for null config", async () => {
132
- const nullMetricParams: MetricsParams = {
133
- metricName: null!,
134
- meterName: "",
135
- };
136
-
137
- const result = getMetric("async-gauge", nullMetricParams);
138
-
139
- assert.isNotNull(result);
140
- assert.equal(result.constructor.name, "NoopObservableGaugeMetric");
141
- });
142
- });
@@ -1,190 +0,0 @@
1
- import { NodeSDK, metrics } from "@opentelemetry/sdk-node";
2
- import { afterAll, assert, describe, expect, test } from "vitest";
3
- import buildNodeInstrumentation from "../lib/instrumentation.node.js";
4
-
5
- import {
6
- BatchLogRecordProcessor,
7
- SimpleLogRecordProcessor,
8
- } from "@opentelemetry/sdk-logs";
9
- import {
10
- BatchSpanProcessor,
11
- SimpleSpanProcessor,
12
- } from "@opentelemetry/sdk-trace-base";
13
- import buildHttpExporters from "../lib/exporter/http.js";
14
- import { NodeSDKConfig } from "../lib/index.js";
15
- import { EnrichLogProcessor } from "../lib/processor/enrich-logger-processor.js";
16
- import { EnrichSpanProcessor } from "../lib/processor/enrich-span-processor.js";
17
- import { PIIExporterDecorator } from "../lib/exporter/pii-exporter-decorator.js";
18
-
19
- describe("verify config settings", () => {
20
- const commonConfig = {
21
- collectorUrl: "https://testurl.com",
22
- serviceName: "test",
23
- };
24
-
25
- test("grpc config", async () => {
26
- const config: NodeSDKConfig = {
27
- ...commonConfig,
28
- protocol: "grpc",
29
- collectorMode: "batch",
30
- diagLogLevel: "NONE",
31
- };
32
-
33
- const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
34
-
35
- assert.ok(sdk);
36
-
37
- const _configuration = sdk["_configuration"];
38
- assert.equal(_configuration.serviceName, commonConfig.serviceName);
39
-
40
- const logs = _configuration.logRecordProcessors;
41
-
42
- assert.equal(logs.length, 1);
43
- assert.ok(logs[logs.length - 1] instanceof BatchLogRecordProcessor);
44
-
45
- const spans = _configuration.spanProcessors;
46
-
47
- assert.equal(spans.length, 1);
48
- assert.ok(spans[0] instanceof BatchSpanProcessor);
49
-
50
- assert.ok(
51
- _configuration.metricReader instanceof
52
- metrics.PeriodicExportingMetricReader,
53
- );
54
- });
55
-
56
- test("http config", async () => {
57
- const config: NodeSDKConfig = {
58
- ...commonConfig,
59
- protocol: "http",
60
- diagLogLevel: "NONE",
61
- spanAttributes: {
62
- name: "custom-value",
63
- },
64
- };
65
-
66
- const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
67
- assert.ok(sdk);
68
-
69
- const _configuration = sdk["_configuration"];
70
- assert.equal(_configuration.serviceName, commonConfig.serviceName);
71
-
72
- const logs = _configuration.logRecordProcessors;
73
-
74
- assert.equal(logs.length, 2);
75
- assert.ok(logs[0] instanceof EnrichLogProcessor);
76
- assert.ok(logs[1] instanceof BatchLogRecordProcessor);
77
-
78
- const spans = _configuration.spanProcessors;
79
-
80
- assert.equal(spans.length, 2);
81
- assert.ok(spans[0] instanceof BatchSpanProcessor);
82
- assert.ok(spans[1] instanceof EnrichSpanProcessor);
83
-
84
- assert.ok(
85
- _configuration.metricReader instanceof
86
- metrics.PeriodicExportingMetricReader,
87
- );
88
- });
89
-
90
- test("console - console config", async () => {
91
- const config: NodeSDKConfig = {
92
- ...commonConfig,
93
- protocol: "console",
94
- diagLogLevel: "NONE",
95
- spanAttributes: {
96
- name: "custom-name",
97
- },
98
- };
99
-
100
- const sdk: NodeSDK = await buildNodeInstrumentation(config)!;
101
- assert.ok(sdk);
102
-
103
- const _configuration = sdk["_configuration"];
104
- assert.equal(_configuration.serviceName, commonConfig.serviceName);
105
-
106
- const logs = _configuration.logRecordProcessors;
107
-
108
- // verify simple log processor for instant console logging
109
- assert.equal(logs.length, 2);
110
- assert.ok(logs[0] instanceof EnrichLogProcessor);
111
- assert.ok(logs[1] instanceof SimpleLogRecordProcessor);
112
-
113
- const spans = _configuration.spanProcessors;
114
-
115
- assert.equal(spans.length, 2);
116
- // verify simple span for instant console logging
117
- assert.ok(spans[0] instanceof SimpleSpanProcessor);
118
- assert.ok(spans[1] instanceof EnrichSpanProcessor);
119
-
120
- assert.ok(
121
- _configuration.metricReader instanceof
122
- metrics.PeriodicExportingMetricReader,
123
- );
124
- });
125
-
126
- test("single log sending config", async () => {
127
- const config: NodeSDKConfig = {
128
- ...commonConfig,
129
- protocol: "grpc",
130
- diagLogLevel: "NONE",
131
- collectorMode: "single",
132
- };
133
-
134
- const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
135
-
136
- assert.ok(sdk);
137
-
138
- const _configuration = sdk["_configuration"];
139
-
140
- const logRecordProcessors = _configuration.logRecordProcessors;
141
- assert.equal(logRecordProcessors.length, 1);
142
- assert.ok(
143
- logRecordProcessors[logRecordProcessors.length - 1] instanceof
144
- SimpleLogRecordProcessor,
145
- );
146
- });
147
-
148
- test("pii exporter decorator injected by default", async () => {
149
- const config: NodeSDKConfig = {
150
- ...commonConfig,
151
- protocol: "grpc",
152
- diagLogLevel: "NONE",
153
- collectorMode: "single",
154
- detection: {},
155
- };
156
-
157
- const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
158
-
159
- assert.ok(sdk);
160
-
161
- const _configuration = sdk["_configuration"];
162
-
163
- const logRecordProcessors = _configuration.logRecordProcessors;
164
- assert.equal(logRecordProcessors.length, 1);
165
- assert.ok(
166
- logRecordProcessors[logRecordProcessors.length - 1] instanceof
167
- SimpleLogRecordProcessor,
168
- );
169
- assert.ok(
170
- logRecordProcessors[logRecordProcessors.length - 1][
171
- "_exporter"
172
- ] instanceof PIIExporterDecorator,
173
- );
174
- });
175
-
176
- test("check if clear base endpoint final slash", () => {
177
- const config: NodeSDKConfig = {
178
- collectorUrl: "http://example.com/",
179
- };
180
-
181
- buildHttpExporters(config);
182
-
183
- expect(config.collectorUrl).toBe("http://example.com");
184
- });
185
-
186
- afterAll(() => {
187
- // shutdown every instrumentation
188
- process.emit("SIGTERM");
189
- });
190
- });
@@ -1,58 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { LogRecord } from "@opentelemetry/sdk-logs";
3
- import { EnrichLogProcessor } from "../../lib/processor/enrich-logger-processor.js";
4
-
5
- const createMockLogRecord = () => {
6
- return {
7
- setAttribute: vi.fn(),
8
- } as unknown as LogRecord;
9
- };
10
-
11
- describe("EnrichLogProcessor", () => {
12
- it("should enrich log record with static attributes", () => {
13
- const attributes = { key1: "value1", key2: 42 };
14
- const processor = new EnrichLogProcessor(attributes);
15
- const mockLogRecord = createMockLogRecord();
16
-
17
- processor.onEmit(mockLogRecord);
18
-
19
- expect(mockLogRecord.setAttribute).toHaveBeenCalledWith("key1", "value1");
20
- expect(mockLogRecord.setAttribute).toHaveBeenCalledWith("key2", 42);
21
- });
22
-
23
- it("should enrich log record with dynamic attributes", () => {
24
- const attributes = {
25
- key1: () => "dynamicValue",
26
- key2: () => 100,
27
- };
28
- const processor = new EnrichLogProcessor(attributes);
29
- const mockLogRecord = createMockLogRecord();
30
-
31
- processor.onEmit(mockLogRecord);
32
-
33
- expect(mockLogRecord.setAttribute).toHaveBeenCalledWith(
34
- "key1",
35
- "dynamicValue",
36
- );
37
- expect(mockLogRecord.setAttribute).toHaveBeenCalledWith("key2", 100);
38
- });
39
-
40
- it("should not set attributes if no span attributes are provided", () => {
41
- const processor = new EnrichLogProcessor();
42
- const mockLogRecord = createMockLogRecord();
43
-
44
- processor.onEmit(mockLogRecord);
45
-
46
- expect(mockLogRecord.setAttribute).not.toHaveBeenCalled();
47
- });
48
-
49
- it("should reject forceFlush", async () => {
50
- await expect(
51
- new EnrichLogProcessor().forceFlush(),
52
- ).resolves.toBeUndefined();
53
- });
54
-
55
- it("should resolve shutdown", async () => {
56
- await expect(new EnrichLogProcessor().shutdown()).resolves.toBeUndefined();
57
- });
58
- });
@@ -1,52 +0,0 @@
1
- import { Context } from "@opentelemetry/api";
2
- import { describe, expect, it } from "vitest";
3
- import { EnrichSpanProcessor } from "../../lib/processor/enrich-span-processor.js";
4
- import { MockSpan } from "../utils/mock-signals.js";
5
-
6
- describe("EnrichSpanProcessor", () => {
7
- it("should set static attributes on span", () => {
8
- const spanAttributes = {
9
- key1: "value1",
10
- key2: 123,
11
- };
12
- const processor = new EnrichSpanProcessor(spanAttributes);
13
- const mockSpan = new MockSpan();
14
- const mockContext = {} as Context;
15
-
16
- processor.onStart(mockSpan, mockContext);
17
-
18
- expect(mockSpan.attributes["key1"]).toBe("value1");
19
- expect(mockSpan.attributes["key2"]).toBe(123);
20
- });
21
-
22
- it("should set dynamic attributes on span", () => {
23
- const spanAttributes = {
24
- dynamicKey: () => "dynamicValue",
25
- };
26
- const processor = new EnrichSpanProcessor(spanAttributes);
27
- const mockSpan = new MockSpan();
28
- const mockContext = {} as Context;
29
-
30
- processor.onStart(mockSpan, mockContext);
31
-
32
- expect(mockSpan.attributes["dynamicKey"]).toBe("dynamicValue");
33
- });
34
-
35
- it("should not set attributes if none are provided", () => {
36
- const processor = new EnrichSpanProcessor();
37
- const mockSpan = new MockSpan();
38
- const mockContext = {} as Context;
39
-
40
- processor.onStart(mockSpan, mockContext);
41
-
42
- expect(mockSpan.attributes["key1"]).toBeUndefined();
43
- });
44
-
45
- it("default method, should maintain default behaviour", async () => {
46
- const processor = new EnrichSpanProcessor();
47
-
48
- expect(processor.onEnd(null!)).toBeUndefined();
49
- expect(await processor.shutdown()).toBeUndefined();
50
- expect(await processor.forceFlush()).toBeUndefined();
51
- });
52
- });
@@ -1,33 +0,0 @@
1
- import { describe, test, expect } from "vitest";
2
- import { ObservabilityResourceDetector } from "../lib/resource";
3
-
4
- describe("ObservabilityResourceDetector", () => {
5
- test("should return custom resource attribute", () => {
6
- const detector = new ObservabilityResourceDetector({
7
- first: "first_value",
8
- second: "second_value",
9
- });
10
- const result = detector.detect();
11
-
12
- expect(result.attributes).not.toBeNull();
13
- expect(result.attributes).toHaveProperty("first");
14
- expect(result.attributes!["first"]).eq("first_value");
15
- expect(result.attributes).toHaveProperty("second");
16
- expect(result.attributes!["second"]).eq("second_value");
17
- // default
18
- expect(result.attributes).toHaveProperty("o11y.sdk.name");
19
- expect(result.attributes!["o11y.sdk.name"]).eq("@ogcio/o11y-sdk-node");
20
- expect(result.attributes).toHaveProperty("o11y.sdk.version");
21
- });
22
-
23
- test("should return default resource attribute", () => {
24
- const detector = new ObservabilityResourceDetector();
25
- const result = detector.detect();
26
-
27
- expect(result.attributes).not.toBeNull();
28
- // default
29
- expect(result.attributes).toHaveProperty("o11y.sdk.name");
30
- expect(result.attributes!["o11y.sdk.name"]).eq("@ogcio/o11y-sdk-node");
31
- expect(result.attributes).toHaveProperty("o11y.sdk.version");
32
- });
33
- });
@@ -1,26 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { setNodeSdkConfig } from "../../lib/config-manager.js";
3
- import { getActiveSpan } from "../../lib/traces.js";
4
-
5
- describe("getActiveSpan", () => {
6
- it("returns undefined if no active span", async () => {
7
- setNodeSdkConfig({
8
- serviceName: "unit-test",
9
- collectorUrl: "http://collector",
10
- detection: {
11
- email: false,
12
- },
13
- });
14
-
15
- // Temporarily override
16
- const opentelemetry = await import("@opentelemetry/api");
17
-
18
- vi.spyOn(opentelemetry.trace, "getActiveSpan").mockImplementationOnce(
19
- () => undefined,
20
- );
21
-
22
- const span = getActiveSpan();
23
-
24
- expect(span).toBeUndefined();
25
- });
26
- });