@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,144 +0,0 @@
1
- import type {
2
- Span,
3
- SpanContext,
4
- AttributeValue,
5
- SpanStatus,
6
- TimeInput,
7
- Link,
8
- Exception,
9
- Attributes,
10
- TraceState,
11
- } from "@opentelemetry/api";
12
-
13
- export class MockSpan implements Span {
14
- public attributes: Record<string, AttributeValue> = {};
15
- public events: {
16
- name: string;
17
- attributes?: Attributes | TimeInput;
18
- startTime?: TimeInput;
19
- }[] = [];
20
- public links: Link[] = [];
21
- public status?: SpanStatus;
22
- public updatedName?: string;
23
- public ended: boolean = false;
24
- public endTime?: TimeInput;
25
- public exceptions: { exception: Exception; time?: TimeInput }[] = [];
26
-
27
- public resource: { attributes: Attributes } = { attributes: {} };
28
-
29
- spanContext(): SpanContext {
30
- return {
31
- traceId: "test-trace-id",
32
- spanId: "test-span-id",
33
- traceFlags: 1,
34
- };
35
- }
36
-
37
- setAttribute(key: string, value: AttributeValue): this {
38
- this.attributes[key] = value;
39
- return this;
40
- }
41
-
42
- setAttributes(attributes: Attributes): this {
43
- Object.assign(this.attributes, attributes);
44
- return this;
45
- }
46
-
47
- addEvent(
48
- name: string,
49
- attributesOrStartTime?: Attributes | TimeInput,
50
- startTime?: TimeInput,
51
- ): this {
52
- this.events.push({ name, attributes: attributesOrStartTime, startTime });
53
- return this;
54
- }
55
-
56
- addLink(link: Link): this {
57
- this.links.push(link);
58
- return this;
59
- }
60
-
61
- addLinks(links: Link[]): this {
62
- this.links.push(...links);
63
- return this;
64
- }
65
-
66
- setStatus(status: SpanStatus): this {
67
- this.status = status;
68
- return this;
69
- }
70
-
71
- updateName(name: string): this {
72
- this.updatedName = name;
73
- return this;
74
- }
75
-
76
- end(endTime?: TimeInput): void {
77
- this.ended = true;
78
- this.endTime = endTime;
79
- }
80
-
81
- isRecording(): boolean {
82
- return true;
83
- }
84
-
85
- recordException(exception: Exception, time?: TimeInput): void {
86
- this.exceptions.push({ exception, time });
87
- }
88
-
89
- reset(): void {
90
- this.attributes = {};
91
- this.events = [];
92
- this.links = [];
93
- this.status = undefined;
94
- this.updatedName = undefined;
95
- this.ended = false;
96
- this.endTime = undefined;
97
- this.exceptions = [];
98
- this.resource = { attributes: {} };
99
- }
100
- }
101
-
102
- export class TestTraceState implements TraceState {
103
- private entries: Map<string, string>;
104
-
105
- constructor(initEntries?: [string, string][]) {
106
- this.entries = new Map(initEntries ?? []);
107
- }
108
-
109
- set(key: string, value: string): TraceState {
110
- const newEntries: [string, string][] = [[key, value]];
111
- for (const [k, v] of this.entries.entries()) {
112
- if (k !== key) {
113
- newEntries.push([k, v]);
114
- }
115
- }
116
- return new TestTraceState(newEntries);
117
- }
118
-
119
- unset(key: string): TraceState {
120
- const newEntries: [string, string][] = [];
121
- for (const [k, v] of this.entries.entries()) {
122
- if (k !== key) {
123
- newEntries.push([k, v]);
124
- }
125
- }
126
- return new TestTraceState(newEntries);
127
- }
128
-
129
- get(key: string): string | undefined {
130
- return this.entries.get(key);
131
- }
132
-
133
- serialize(): string {
134
- return Array.from(this.entries)
135
- .slice(0, 32) // Enforce 32-member max
136
- .map(([key, value]) => `${key}=${value}`)
137
- .join(",");
138
- }
139
-
140
- // Optional: for testing/debugging
141
- toJSON(): Record<string, string> {
142
- return Object.fromEntries(this.entries);
143
- }
144
- }
@@ -1,103 +0,0 @@
1
- import type { NodeSDK } from "@opentelemetry/sdk-node";
2
- import { test, describe, assert, vi, expect } from "vitest";
3
-
4
- import buildNodeInstrumentation from "../lib/instrumentation.node.js";
5
- import { instrumentNode } from "../index.js";
6
-
7
- describe("validation config: should return without breaking the execution", () => {
8
- test("should call buildNodeInstrumentation without config and skip instrumentation", async () => {
9
- const consoleWarnSpy = vi
10
- .spyOn(console, "warn")
11
- .mockImplementation(vi.fn());
12
-
13
- await instrumentNode();
14
-
15
- expect(consoleWarnSpy).toHaveBeenCalled();
16
- expect(consoleWarnSpy).toHaveBeenCalledWith(
17
- "observability config not set. Skipping NodeJS OpenTelemetry instrumentation.",
18
- );
19
- });
20
-
21
- test("node instrumentation: url undefined", async () => {
22
- let sdk: NodeSDK | undefined = undefined;
23
-
24
- const consoleWarnSpy = vi
25
- .spyOn(console, "warn")
26
- .mockImplementation(vi.fn());
27
- const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn());
28
-
29
- await expect(
30
- buildNodeInstrumentation({
31
- collectorUrl: undefined,
32
- }).then((result) => {
33
- sdk = result;
34
- }),
35
- ).resolves.not.toThrowError();
36
-
37
- assert.equal(sdk, undefined);
38
-
39
- expect(consoleWarnSpy).toHaveBeenCalled();
40
- expect(consoleWarnSpy).toHaveBeenCalledWith(
41
- "collectorUrl not set. Skipping NodeJS OpenTelemetry instrumentation.",
42
- );
43
- expect(consoleLogSpy).not.toHaveBeenCalled();
44
- });
45
-
46
- test("node instrumentation: invalid url", async () => {
47
- let sdk: NodeSDK | undefined = undefined;
48
-
49
- const consoleErrorSpy = vi
50
- .spyOn(console, "error")
51
- .mockImplementation(vi.fn());
52
- const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn());
53
-
54
- await expect(
55
- buildNodeInstrumentation({
56
- collectorUrl: "notavalidURL",
57
- }).then((result) => {
58
- sdk = result;
59
- }),
60
- ).resolves.not.toThrowError();
61
-
62
- assert.equal(sdk, undefined);
63
-
64
- expect(consoleErrorSpy).toHaveBeenCalled();
65
- expect(consoleErrorSpy).toHaveBeenCalledWith(
66
- "collectorUrl does not use a valid format. Skipping NodeJS OpenTelemetry instrumentation.",
67
- );
68
- expect(consoleLogSpy).not.toHaveBeenCalled();
69
- });
70
-
71
- test("node instrumentation: verify no instrumentation if exception occurs", async () => {
72
- let sdk: NodeSDK | undefined = undefined;
73
-
74
- const consoleErrorSpy = vi
75
- .spyOn(console, "error")
76
- .mockImplementation(vi.fn());
77
- const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn());
78
-
79
- vi.mock("@opentelemetry/auto-instrumentations-node", () => ({
80
- getNodeAutoInstrumentations: vi.fn(() => {
81
- throw new Error("Wanted error");
82
- }),
83
- }));
84
-
85
- await expect(
86
- buildNodeInstrumentation({
87
- collectorUrl: "https://testurl.com",
88
- serviceName: "test",
89
- }).then((result) => {
90
- sdk = result;
91
- }),
92
- ).resolves.not.toThrowError();
93
-
94
- assert.equal(sdk, undefined);
95
-
96
- expect(consoleErrorSpy).toHaveBeenCalled();
97
- expect(consoleErrorSpy).toHaveBeenCalledWith(
98
- "Error starting NodeJS OpenTelemetry instrumentation:",
99
- new Error("Wanted error"),
100
- );
101
- expect(consoleLogSpy).not.toHaveBeenCalled();
102
- });
103
- });
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4
- "module": "NodeNext" /* Specify what module code is generated. */,
5
- "outDir": "./dist" /* Specify an output folder for all emitted files. */,
6
- "moduleResolution": "NodeNext",
7
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
8
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
9
- "strict": true /* Enable all strict type-checking options. */,
10
- "skipLibCheck": true /* Skip type checking all .d.ts files. */,
11
- "declaration": true,
12
- "resolveJsonModule": true
13
- },
14
- "exclude": ["**/test/**"]
15
- }
package/vitest.config.ts DELETED
@@ -1,46 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- watch: false,
7
- exclude: ["**/fixtures/**", "**/dist/**"],
8
- poolOptions: {
9
- threads: {
10
- maxThreads: 8,
11
- },
12
- },
13
- clearMocks: true,
14
- testTimeout: 30_000,
15
- coverage: {
16
- enabled: true,
17
- provider: "v8",
18
- reportsDirectory: "coverage",
19
- reporter: ["lcov", "cobertura"],
20
- clean: true,
21
- },
22
- reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
23
- environment: "node",
24
- pool: "threads",
25
- projects: [
26
- {
27
- test: {
28
- include: [
29
- "**/test/*.test.ts",
30
- "**/test/processor/**/*.test.ts",
31
- "**/test/traces/**/*.test.ts",
32
- "**/test/internals/**/*.test.ts",
33
- "**/test/exporter/**/*.test.ts",
34
- ],
35
- name: "unit",
36
- },
37
- },
38
- {
39
- test: {
40
- include: ["**/test/integration/**/*.test.ts"],
41
- name: "integration",
42
- },
43
- },
44
- ],
45
- },
46
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes