Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/util/tracing.spec.ts
2500 views
1
/**
2
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { suite, test } from "@testdeck/mocha";
8
import * as chai from "chai";
9
import { TraceContext } from "./tracing";
10
import { MockTracer } from "opentracing";
11
12
const expect = chai.expect;
13
14
@suite
15
class TestTracing {
16
@test public async testTracingContext_addNestedTags() {
17
const tracer = new MockTracer();
18
const span = tracer.startSpan("testTracingContext_addNestedTags");
19
TraceContext.addNestedTags(
20
{ span },
21
{
22
rpc: {
23
system: "jsonrpc",
24
jsonrpc: {
25
version: "1.0",
26
method: "test",
27
parameters: ["abc", "def"],
28
},
29
},
30
},
31
);
32
33
const mockSpan = tracer.report().spans[0];
34
expect(mockSpan.tags()).to.deep.equal({
35
"rpc.system": "jsonrpc",
36
"rpc.jsonrpc.version": "1.0",
37
"rpc.jsonrpc.method": "test",
38
"rpc.jsonrpc.parameters.0": "abc",
39
"rpc.jsonrpc.parameters.1": "def",
40
});
41
}
42
43
@test public async testTracingContext_addNestedTags_null() {
44
const tracer = new MockTracer();
45
const span = tracer.startSpan("testTracingContext_addNestedTags_null");
46
TraceContext.addNestedTags(
47
{ span },
48
{
49
someShape: {
50
thisIsNull: null,
51
thisIsUndefined: undefined,
52
},
53
},
54
);
55
56
const mockSpan = tracer.report().spans[0];
57
expect(mockSpan.tags()).to.deep.equal({
58
"someShape.thisIsNull": null,
59
"someShape.thisIsUndefined": undefined,
60
});
61
}
62
63
@test public async testTracingContext_addJsonRPCParameters() {
64
const tracer = new MockTracer();
65
const span = tracer.startSpan("testTracingContext_addJsonRPCParameters");
66
const ctx = { span };
67
TraceContext.addJsonRPCParameters(ctx, {
68
one: "one",
69
two: {
70
name: "two",
71
some: "shape",
72
containing: "PII",
73
},
74
three: "three",
75
});
76
77
const mockSpan = tracer.report().spans[0];
78
expect(mockSpan.tags()).to.deep.equal({
79
"rpc.jsonrpc.parameters.one": "one",
80
"rpc.jsonrpc.parameters.two.containing": "PII",
81
"rpc.jsonrpc.parameters.two.name": "two",
82
"rpc.jsonrpc.parameters.two.some": "shape",
83
"rpc.jsonrpc.parameters.three": "three",
84
"rpc.system": "jsonrpc",
85
});
86
}
87
}
88
module.exports = new TestTracing();
89
90