@ogcio/o11y-sdk-node 0.4.1 → 0.6.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.
- package/dist/sdk-core/index.d.ts +1 -0
- package/dist/sdk-core/index.js +1 -0
- package/dist/sdk-core/lib/index.d.ts +2 -0
- package/dist/sdk-core/lib/index.js +2 -0
- package/dist/sdk-core/lib/redaction/basic-redactor.d.ts +7 -0
- package/dist/sdk-core/lib/redaction/basic-redactor.js +18 -0
- package/dist/sdk-core/lib/redaction/email-redactor.d.ts +8 -0
- package/dist/sdk-core/lib/redaction/email-redactor.js +17 -0
- package/dist/sdk-core/lib/redaction/index.d.ts +9 -0
- package/dist/sdk-core/lib/redaction/index.js +4 -0
- package/dist/sdk-core/lib/redaction/ip-redactor.d.ts +9 -0
- package/dist/sdk-core/lib/redaction/ip-redactor.js +23 -0
- package/dist/sdk-core/lib/redaction/ppsn-redactor.d.ts +8 -0
- package/dist/sdk-core/lib/redaction/ppsn-redactor.js +17 -0
- package/dist/sdk-core/lib/utils/data-structures.d.ts +15 -0
- package/dist/{lib/internals/redaction/pii-detection.js → sdk-core/lib/utils/data-structures.js} +4 -27
- package/dist/sdk-core/lib/utils/index.d.ts +2 -0
- package/dist/sdk-core/lib/utils/index.js +2 -0
- package/dist/sdk-core/lib/utils/string-decoding.d.ts +7 -0
- package/dist/sdk-core/lib/utils/string-decoding.js +22 -0
- package/dist/{index.d.ts → sdk-node/index.d.ts} +1 -0
- package/dist/{index.js → sdk-node/index.js} +1 -0
- package/dist/sdk-node/lib/config-manager.d.ts +3 -0
- package/dist/{lib → sdk-node/lib}/config-manager.js +1 -4
- package/dist/sdk-node/lib/exporter/console.d.ts +3 -0
- package/dist/sdk-node/lib/exporter/grpc.d.ts +3 -0
- package/dist/sdk-node/lib/exporter/http.d.ts +3 -0
- package/dist/{lib → sdk-node/lib}/exporter/index.d.ts +2 -2
- package/dist/{lib → sdk-node/lib}/exporter/pii-exporter-decorator.d.ts +6 -6
- package/dist/{lib → sdk-node/lib}/exporter/pii-exporter-decorator.js +7 -3
- package/dist/sdk-node/lib/exporter/processor-config.d.ts +7 -0
- package/dist/{lib → sdk-node/lib}/exporter/processor-config.js +4 -0
- package/dist/{lib → sdk-node/lib}/index.d.ts +11 -0
- package/dist/{lib → sdk-node/lib}/instrumentation.node.js +1 -1
- package/dist/sdk-node/lib/internals/redaction/redactors/email.d.ts +8 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/email.js +19 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/index.d.ts +16 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/index.js +13 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/ip.d.ts +8 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/ip.js +20 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/ppsn.d.ts +8 -0
- package/dist/sdk-node/lib/internals/redaction/redactors/ppsn.js +18 -0
- package/dist/{lib → sdk-node/lib}/metrics.d.ts +1 -1
- package/dist/{lib → sdk-node/lib}/processor/enrich-logger-processor.d.ts +3 -3
- package/dist/{lib → sdk-node/lib}/processor/enrich-span-processor.d.ts +3 -3
- package/dist/sdk-node/lib/processor/nextjs-logger-processor.d.ts +7 -0
- package/dist/sdk-node/lib/processor/nextjs-logger-processor.js +30 -0
- package/dist/sdk-node/lib/processor/nextjs-span-processor.d.ts +8 -0
- package/dist/sdk-node/lib/processor/nextjs-span-processor.js +25 -0
- package/dist/{lib → sdk-node/lib}/resource.d.ts +2 -2
- package/dist/{lib → sdk-node/lib}/traces.d.ts +1 -1
- package/dist/{lib → sdk-node/lib}/traces.js +2 -2
- package/dist/{lib → sdk-node/lib}/url-sampler.d.ts +3 -3
- package/dist/{lib → sdk-node/lib}/utils.d.ts +1 -1
- package/dist/sdk-node/package.json +62 -0
- package/package.json +25 -22
- package/CHANGELOG.md +0 -226
- package/dist/lib/config-manager.d.ts +0 -3
- package/dist/lib/exporter/console.d.ts +0 -3
- package/dist/lib/exporter/grpc.d.ts +0 -3
- package/dist/lib/exporter/http.d.ts +0 -3
- package/dist/lib/exporter/processor-config.d.ts +0 -5
- package/dist/lib/internals/redaction/pii-detection.d.ts +0 -25
- package/dist/lib/internals/redaction/redactors/email.d.ts +0 -8
- package/dist/lib/internals/redaction/redactors/email.js +0 -48
- package/dist/lib/internals/redaction/redactors/index.d.ts +0 -4
- package/dist/lib/internals/redaction/redactors/index.js +0 -6
- package/dist/lib/internals/redaction/redactors/ip.d.ts +0 -10
- package/dist/lib/internals/redaction/redactors/ip.js +0 -54
- package/dist/lib/internals/shared-metrics.d.ts +0 -7
- package/dist/lib/internals/shared-metrics.js +0 -18
- package/dist/package.json +0 -59
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -45
- package/index.ts +0 -9
- package/lib/config-manager.ts +0 -16
- package/lib/exporter/console.ts +0 -33
- package/lib/exporter/grpc.ts +0 -65
- package/lib/exporter/http.ts +0 -56
- package/lib/exporter/index.ts +0 -9
- package/lib/exporter/pii-exporter-decorator.ts +0 -187
- package/lib/exporter/processor-config.ts +0 -23
- package/lib/index.ts +0 -118
- package/lib/instrumentation.node.ts +0 -115
- package/lib/internals/hooks.ts +0 -14
- package/lib/internals/redaction/pii-detection.ts +0 -113
- package/lib/internals/redaction/redactors/email.ts +0 -58
- package/lib/internals/redaction/redactors/index.ts +0 -12
- package/lib/internals/redaction/redactors/ip.ts +0 -68
- package/lib/internals/shared-metrics.ts +0 -34
- package/lib/metrics.ts +0 -75
- package/lib/processor/enrich-logger-processor.ts +0 -34
- package/lib/processor/enrich-span-processor.ts +0 -39
- package/lib/resource.ts +0 -30
- package/lib/traces.ts +0 -78
- package/lib/url-sampler.ts +0 -52
- package/lib/utils.ts +0 -22
- package/test/config-manager.test.ts +0 -34
- package/test/exporter/pii-exporter-decorator.test.ts +0 -88
- package/test/index.test.ts +0 -70
- package/test/integration/README.md +0 -26
- package/test/integration/http-tracing.integration.test.ts +0 -56
- package/test/integration/pii.integration.test.ts +0 -68
- package/test/integration/run.sh +0 -88
- package/test/internals/hooks.test.ts +0 -45
- package/test/internals/pii-detection.test.ts +0 -265
- package/test/internals/redactors/email.test.ts +0 -81
- package/test/internals/redactors/ip.test.ts +0 -93
- package/test/internals/shared-metrics.test.ts +0 -34
- package/test/metrics.test.ts +0 -142
- package/test/node-config.test.ts +0 -190
- package/test/processor/enrich-logger-processor.test.ts +0 -58
- package/test/processor/enrich-span-processor.test.ts +0 -52
- package/test/resource.test.ts +0 -33
- package/test/traces/active-span.test.ts +0 -28
- package/test/traces/with-span.test.ts +0 -340
- package/test/url-sampler.test.ts +0 -215
- package/test/utils/alloy-log-parser.ts +0 -53
- package/test/utils/mock-signals.ts +0 -144
- package/test/validation.test.ts +0 -103
- package/tsconfig.json +0 -15
- package/vitest.config.ts +0 -46
- /package/dist/{lib → sdk-node/lib}/exporter/console.js +0 -0
- /package/dist/{lib → sdk-node/lib}/exporter/grpc.js +0 -0
- /package/dist/{lib → sdk-node/lib}/exporter/http.js +0 -0
- /package/dist/{lib → sdk-node/lib}/exporter/index.js +0 -0
- /package/dist/{lib → sdk-node/lib}/index.js +0 -0
- /package/dist/{lib → sdk-node/lib}/instrumentation.node.d.ts +0 -0
- /package/dist/{lib → sdk-node/lib}/internals/hooks.d.ts +0 -0
- /package/dist/{lib → sdk-node/lib}/internals/hooks.js +0 -0
- /package/dist/{lib → sdk-node/lib}/metrics.js +0 -0
- /package/dist/{lib → sdk-node/lib}/processor/enrich-logger-processor.js +0 -0
- /package/dist/{lib → sdk-node/lib}/processor/enrich-span-processor.js +0 -0
- /package/dist/{lib → sdk-node/lib}/resource.js +0 -0
- /package/dist/{lib → sdk-node/lib}/url-sampler.js +0 -0
- /package/dist/{lib → sdk-node/lib}/utils.js +0 -0
package/test/url-sampler.test.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Context } from "@opentelemetry/api";
|
|
2
|
-
import {
|
|
3
|
-
SamplingDecision,
|
|
4
|
-
SamplingResult,
|
|
5
|
-
} from "@opentelemetry/sdk-trace-base";
|
|
6
|
-
import { describe, expect, test, vi } from "vitest";
|
|
7
|
-
import { UrlSampler } from "../lib/url-sampler";
|
|
8
|
-
|
|
9
|
-
describe("url sampler", () => {
|
|
10
|
-
// mock sampler to be sure every trace after UrlSamper has RECORD status
|
|
11
|
-
const mockSampler = {
|
|
12
|
-
shouldSample: vi
|
|
13
|
-
.fn()
|
|
14
|
-
.mockImplementation(
|
|
15
|
-
(_context, _traceId, _spanName, _spanKind, attributes, _links) => {
|
|
16
|
-
return {
|
|
17
|
-
decision: SamplingDecision.RECORD,
|
|
18
|
-
attributes: attributes,
|
|
19
|
-
} as SamplingResult;
|
|
20
|
-
},
|
|
21
|
-
),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
test("should add custom span attributes to trace", async () => {
|
|
25
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
26
|
-
[
|
|
27
|
-
{
|
|
28
|
-
type: "endsWith",
|
|
29
|
-
url: "/health",
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
mockSampler,
|
|
33
|
-
{
|
|
34
|
-
"signal.namespace": "unittest",
|
|
35
|
-
"signal.callback.result": () => "test",
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
expect(sampler).not.toBeNull();
|
|
40
|
-
|
|
41
|
-
const result = sampler.shouldSample(
|
|
42
|
-
{} as Context,
|
|
43
|
-
"traceId",
|
|
44
|
-
"span",
|
|
45
|
-
0,
|
|
46
|
-
{ "http.target": "/track" },
|
|
47
|
-
[],
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
51
|
-
expect(result.decision).toBe(SamplingDecision.RECORD);
|
|
52
|
-
expect(result.attributes).not.toBeNull();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("should not record trace about /health api", async () => {
|
|
56
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
57
|
-
[
|
|
58
|
-
{
|
|
59
|
-
type: "endsWith",
|
|
60
|
-
url: "/health",
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
mockSampler,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const result = sampler.shouldSample(
|
|
67
|
-
{} as Context,
|
|
68
|
-
"traceId",
|
|
69
|
-
"span",
|
|
70
|
-
0,
|
|
71
|
-
{ "http.target": "/health" },
|
|
72
|
-
[],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
76
|
-
expect(result.decision).toBe(SamplingDecision.NOT_RECORD);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("should record every other trace which is not /health api", async () => {
|
|
80
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
81
|
-
[
|
|
82
|
-
{
|
|
83
|
-
type: "endsWith",
|
|
84
|
-
url: "/health",
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
mockSampler,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
let result = sampler.shouldSample(
|
|
91
|
-
{} as Context,
|
|
92
|
-
"traceId",
|
|
93
|
-
"span",
|
|
94
|
-
0,
|
|
95
|
-
{ "http.target": "/test" },
|
|
96
|
-
[],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
expect(result.decision).toBe(SamplingDecision.RECORD);
|
|
100
|
-
|
|
101
|
-
result = sampler.shouldSample(
|
|
102
|
-
{} as Context,
|
|
103
|
-
"traceId",
|
|
104
|
-
"span",
|
|
105
|
-
0,
|
|
106
|
-
{ "http.target": "/another/url" },
|
|
107
|
-
[],
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(result.decision).toBe(SamplingDecision.RECORD);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("operator 'includes', should not record every trace which include /block in url", async () => {
|
|
114
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
115
|
-
[
|
|
116
|
-
{
|
|
117
|
-
type: "includes",
|
|
118
|
-
url: "/block",
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
mockSampler,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(sampler).not.toBeNull();
|
|
125
|
-
|
|
126
|
-
const result = sampler.shouldSample(
|
|
127
|
-
{} as Context,
|
|
128
|
-
"traceId",
|
|
129
|
-
"span",
|
|
130
|
-
0,
|
|
131
|
-
{ "http.target": "/namespace/block/example/12" },
|
|
132
|
-
[],
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
136
|
-
expect(result.decision).toBe(SamplingDecision.NOT_RECORD);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test("operator 'endsWith', should not record only trace which ends with /block in url", async () => {
|
|
140
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
141
|
-
[
|
|
142
|
-
{
|
|
143
|
-
type: "endsWith",
|
|
144
|
-
url: "/block",
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
mockSampler,
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
expect(sampler).not.toBeNull();
|
|
151
|
-
|
|
152
|
-
// expect traced with block in the URL middle
|
|
153
|
-
let result = sampler.shouldSample(
|
|
154
|
-
{} as Context,
|
|
155
|
-
"traceId",
|
|
156
|
-
"span",
|
|
157
|
-
0,
|
|
158
|
-
{ "http.target": "/namespace/block/example/12" },
|
|
159
|
-
[],
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
163
|
-
expect(result.decision).toBe(SamplingDecision.RECORD);
|
|
164
|
-
|
|
165
|
-
// should stop trace with block at the end
|
|
166
|
-
result = sampler.shouldSample(
|
|
167
|
-
{} as Context,
|
|
168
|
-
"traceId",
|
|
169
|
-
"span",
|
|
170
|
-
0,
|
|
171
|
-
{ "http.target": "/namespace/example/block" },
|
|
172
|
-
[],
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
176
|
-
expect(result.decision).toBe(SamplingDecision.NOT_RECORD);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("operator 'equals', should not record trace which is equal to /block in url", async () => {
|
|
180
|
-
const sampler: UrlSampler = new UrlSampler(
|
|
181
|
-
[
|
|
182
|
-
{
|
|
183
|
-
type: "equals",
|
|
184
|
-
url: "/block",
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
mockSampler,
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
expect(sampler).not.toBeNull();
|
|
191
|
-
|
|
192
|
-
let result = sampler.shouldSample(
|
|
193
|
-
{} as Context,
|
|
194
|
-
"traceId",
|
|
195
|
-
"span",
|
|
196
|
-
0,
|
|
197
|
-
{ "http.target": "/namespace/block/example/12" },
|
|
198
|
-
[],
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
expect(sampler.toString()).toBe("UrlSampler");
|
|
202
|
-
expect(result.decision).toBe(SamplingDecision.RECORD);
|
|
203
|
-
|
|
204
|
-
result = sampler.shouldSample(
|
|
205
|
-
{} as Context,
|
|
206
|
-
"traceId",
|
|
207
|
-
"span",
|
|
208
|
-
0,
|
|
209
|
-
{ "http.target": "/block" },
|
|
210
|
-
[],
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
expect(result.decision).toBe(SamplingDecision.NOT_RECORD);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export function parseLog(
|
|
2
|
-
log: string,
|
|
3
|
-
): Record<string, object | string | number> {
|
|
4
|
-
const logArray = log
|
|
5
|
-
.split("\\n")
|
|
6
|
-
.map((line) => line.trim())
|
|
7
|
-
.filter((line) => line);
|
|
8
|
-
|
|
9
|
-
const jsonObject: Record<string, object | string | number> = {};
|
|
10
|
-
let currentSection: Record<string, object | string | number> = jsonObject;
|
|
11
|
-
const sectionStack: Record<string, object | string | number>[] = [];
|
|
12
|
-
|
|
13
|
-
logArray.forEach((line) => {
|
|
14
|
-
line = line.trim();
|
|
15
|
-
|
|
16
|
-
if (line.startsWith("->")) {
|
|
17
|
-
const match = line.match(/->\s+([^:]+):\s+(Str|Int)\((.+)\)/);
|
|
18
|
-
if (match) {
|
|
19
|
-
const [, key, type, value] = match;
|
|
20
|
-
const parsedValue = type === "Int" ? parseInt(value, 10) : value;
|
|
21
|
-
|
|
22
|
-
if (typeof currentSection === "object") {
|
|
23
|
-
currentSection[key] = parsedValue;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
} else if (line.endsWith(":")) {
|
|
27
|
-
// new section
|
|
28
|
-
const sectionName = line
|
|
29
|
-
.slice(0, -1)
|
|
30
|
-
.trim()
|
|
31
|
-
.toLowerCase()
|
|
32
|
-
.replace(" ", "_");
|
|
33
|
-
jsonObject[sectionName] = {};
|
|
34
|
-
currentSection = jsonObject[sectionName] as Record<
|
|
35
|
-
string,
|
|
36
|
-
object | string | number
|
|
37
|
-
>;
|
|
38
|
-
sectionStack.push(currentSection);
|
|
39
|
-
} else if (line.startsWith('"')) {
|
|
40
|
-
// Additional metadata at the end, store it separately
|
|
41
|
-
jsonObject["metadata"] = line;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (line.includes("Body:")) {
|
|
45
|
-
const match = line.match(/Body:\s+(\w+)\((.+)\)/);
|
|
46
|
-
if (match) {
|
|
47
|
-
jsonObject["log_body"] = match[2];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return jsonObject;
|
|
53
|
-
}
|
|
@@ -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
|
-
}
|
package/test/validation.test.ts
DELETED
|
@@ -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
|
|
File without changes
|
|
File without changes
|