Skip to content

Commit 112feba

Browse files
authored
fix: make test independent of sdk version (#519)
1 parent 090b170 commit 112feba

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

runtimes/runtimes/operational-telemetry/operational-telemetry-service.test.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,17 @@ describe('OperationalTelemetryService with OpenTelemetry SDK', () => {
6363
await promisify(server.close.bind(server))()
6464
})
6565

66-
function makeMetricsRequestDeterministic(jsonStr: string): string {
66+
function makeRequestDeterministic(jsonStr: string): string {
6767
return jsonStr
68-
.replace(/"(startTimeUnixNano|timeUnixNano)":"[0-9]+"/g, '"$1":"1746710710801000000"')
69-
.replace(
70-
/"key":"sessionId","value":{"stringValue":"[^"]+"/g,
71-
'"key":"sessionId","value":{"stringValue":"80fd44e9-55e5-4b80-a08a-4f2bcaf2e1b9"'
72-
)
73-
}
74-
75-
function makeLogsRequestDeterministic(jsonStr: string): string {
76-
return jsonStr
77-
.replace(/"(timeUnixNano|observedTimeUnixNano)":"[0-9]+"/g, '"$1":"1746710710801000000"')
68+
.replace(/"(startTimeUnixNano|timeUnixNano|observedTimeUnixNano)":"[0-9]+"/g, '"$1":"1746710710801000000"')
7869
.replace(
7970
/"key":"sessionId","value":{"stringValue":"[^"]+"}}/g,
8071
'"key":"sessionId","value":{"stringValue":"80fd44e9-55e5-4b80-a08a-4f2bcaf2e1b9"}}'
8172
)
73+
.replace(
74+
/"key":"telemetry.sdk.version","value":{"stringValue":"[^"]+"/g,
75+
'"key":"telemetry.sdk.version","value":{"stringValue":"2.0.0"' // Changes with the version of the sdk in package.json
76+
)
8277
}
8378

8479
function getOperationalTelemetryConfig() {
@@ -130,7 +125,7 @@ describe('OperationalTelemetryService with OpenTelemetry SDK', () => {
130125
assert(request.method === 'POST', 'Request should use POST method')
131126

132127
const requestBodyStr = JSON.stringify(request.body)
133-
const normalizedBody = makeMetricsRequestDeterministic(requestBodyStr)
128+
const normalizedBody = makeRequestDeterministic(requestBodyStr)
134129
assert.deepStrictEqual(JSON.parse(normalizedBody), resourceMetrics)
135130
})
136131

@@ -151,7 +146,7 @@ describe('OperationalTelemetryService with OpenTelemetry SDK', () => {
151146
assert(request.method === 'POST', 'Request should use POST method')
152147
const requestBodyStr = JSON.stringify(request.body)
153148

154-
const normalizedBody = makeLogsRequestDeterministic(requestBodyStr)
149+
const normalizedBody = makeRequestDeterministic(requestBodyStr)
155150

156151
assert.deepStrictEqual(JSON.parse(normalizedBody), resourceLogs)
157152
})

0 commit comments

Comments
 (0)