-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
breaking: Use sha256 to hash lambda traceId that are triggered by Step Functions and set _dd.p.tid #534
Merged
Merged
breaking: Use sha256 to hash lambda traceId that are triggered by Step Functions and set _dd.p.tid #534
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
131f778
v1
kimi-p b9032cd
fix test
kimi-p aa1a0fa
remove md5 package and regenerate yarn lock
kimi-p 60e0445
lint
kimi-p 1617e1a
upgrade node/type
kimi-p 858cfd5
fix 3 tests
kimi-p 3338526
fix span ids for the same tests (previous commit was for trace id
kimi-p 3c7b456
add @aws-crypto/sha256-js
kimi-p 89a3ce3
remove 8h
kimi-p 43fe7b8
Empty-Commit
kimi-p 4ed002f
update yarn.lock
kimi-p 1a22e0a
update 65th bit to be 0 and tests all accidentally pass
kimi-p ee7d6bd
rename
kimi-p eb49ebf
rename
kimi-p f3c87db
add option to hashing to 64 bits or 128 bits
kimi-p e8470cd
merge main
kimi-p d9c4072
update test name
kimi-p b3d76cd
try log-backend log
kimi-p 36f3942
remote print
kimi-p a3b7bd7
update 64 zeros case
kimi-p e3be794
Empty-Commit
kimi-p 848a3b2
Empty-Commit
kimi-p 0de000f
lint
kimi-p 0c3dbbd
Merge branch 'main' of github.com:DataDog/datadog-lambda-js into kimi…
kimi-p cf96c98
remove unnecessary edge case check
kimi-p 8e28404
Merge branch 'main' into kimi/update-sha256
kimi-p 0debb2a
small logic update from comment
kimi-p 1837ffe
use .reduce()
kimi-p b385614
lazy load require dd-trace/packages/dd-trace/src/opentracing/span_con…
kimi-p d3e6fbf
lazy load tracer classes
duncanista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { StepFunctionContextService } from "./step-function-service"; | ||
import { PARENT_ID, StepFunctionContextService } from "./step-function-service"; | ||
|
||
describe("StepFunctionContextService", () => { | ||
const stepFunctionEvent = { | ||
|
@@ -194,8 +194,8 @@ describe("StepFunctionContextService", () => { | |
|
||
expect(spanContext).not.toBeNull(); | ||
|
||
expect(spanContext?.toTraceId()).toBe("947965466153612645"); | ||
expect(spanContext?.toSpanId()).toBe("4602916161841036335"); | ||
expect(spanContext?.toTraceId()).toBe("1139193989631387307"); | ||
expect(spanContext?.toSpanId()).toBe("5892738536804826142"); | ||
expect(spanContext?.sampleMode()).toBe("1"); | ||
expect(spanContext?.source).toBe("event"); | ||
}); | ||
|
@@ -211,54 +211,55 @@ describe("StepFunctionContextService", () => { | |
}); | ||
}); | ||
|
||
describe("deterministicMd5HashToBigIntString", () => { | ||
describe("deterministicSha256HashToBigIntString", () => { | ||
it("returns the same hash number generated in `logs backend` for a random string", () => { | ||
const instance = StepFunctionContextService.instance(); | ||
const hash = instance["deterministicMd5HashToBigIntString"]("some_testing_random_string"); | ||
expect(hash).toEqual("2251275791555400689"); | ||
const hash = instance["deterministicSha256HashToBigIntString"]("some_testing_random_string", PARENT_ID); | ||
expect(hash).toEqual("4364271812988819936"); | ||
}); | ||
|
||
it("returns the same hash number generated in `logs backend` for execution id # state name # entered time", () => { | ||
const instance = StepFunctionContextService.instance(); | ||
const hash = instance["deterministicMd5HashToBigIntString"]( | ||
const hash = instance["deterministicSha256HashToBigIntString"]( | ||
"arn:aws:states:sa-east-1:601427271234:express:DatadogStateMachine:acaf1a67-336a-e854-1599-2a627eb2dd8a:c8baf081-31f1-464d-971f-70cb17d01111#step-one#2022-12-08T21:08:19.224Z", | ||
PARENT_ID, | ||
); | ||
expect(hash).toEqual("8034507082463708833"); | ||
expect(hash).toEqual("4340734536022949921"); | ||
}); | ||
}); | ||
|
||
describe("deterministicMd5HashInBinary", () => { | ||
describe("deterministicSha256Hash", () => { | ||
it.each([ | ||
[ | ||
"a random string", | ||
"some_testing_random_string", | ||
"0001111100111110001000110110011110010111000110001001001111110001", | ||
"0011110010010001000000100001011101001100011100101101100111100000", | ||
], | ||
[ | ||
"an execution id", | ||
"arn:aws:states:sa-east-1:601427271234:express:DatadogStateMachine:acaf1a67-336a-e854-1599-2a627eb2dd8a:c8baf081-31f1-464d-971f-70cb17d041f4", | ||
"0010010000101100100000101011111101111100110110001110111100111101", | ||
"0100010100110010010010100001011001110100111011010100110010000100", | ||
], | ||
[ | ||
"another execution id", | ||
"arn:aws:states:sa-east-1:601427271234:express:DatadogStateMachine:acaf1a67-336a-e854-1599-2a627eb2dd8a:c8baf081-31f1-464d-971f-70cb17d01111", | ||
"0010001100110000011011011111010000100111100000110000100100101010", | ||
"0010111110001100100010000101001100110000000000010111011100101011", | ||
], | ||
[ | ||
"execution id # state name # entered time", | ||
"arn:aws:states:sa-east-1:601427271234:express:DatadogStateMachine:acaf1a67-336a-e854-1599-2a627eb2dd8a:c8baf081-31f1-464d-971f-70cb17d01111#step-one#2022-12-08T21:08:19.224Z", | ||
"0110111110000000010011011001111101110011100111000000011010100001", | ||
"0011110000111101011000110000111111110011111010110000000000100001", | ||
], | ||
])("returns the same hash number generated in `logs backend` for %s", (_, str, expected) => { | ||
const instance = StepFunctionContextService.instance(); | ||
const hash = instance["deterministicMd5HashInBinary"](str); | ||
const hash = instance["deterministicSha256Hash"](str, PARENT_ID); | ||
expect(hash).toEqual(expected); | ||
}); | ||
|
||
it("returns a hash always leading with 0", () => { | ||
const instance = StepFunctionContextService.instance(); | ||
for (let i = 0; i < 20; i++) { | ||
const hash = instance["deterministicMd5HashInBinary"](i.toString()); | ||
const hash = instance["deterministicSha256Hash"](i.toString(), PARENT_ID); | ||
expect(hash.substring(0, 1)).toMatch("0"); | ||
} | ||
}); | ||
|
@@ -268,36 +269,44 @@ describe("StepFunctionContextService", () => { | |
const times = 20; | ||
for (let i = 0; i < times; i++) { | ||
for (let j = i + 1; j < times; j++) { | ||
const hash1 = instance["deterministicMd5HashInBinary"](i.toString()); | ||
const hash2 = instance["deterministicMd5HashInBinary"](j.toString()); | ||
const hash1 = instance["deterministicSha256Hash"](i.toString(), PARENT_ID); | ||
const hash2 = instance["deterministicSha256Hash"](j.toString(), PARENT_ID); | ||
expect(hash1).not.toMatch(hash2); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
describe("hexToBinary", () => { | ||
describe("numberToBinaryString", () => { | ||
const instance = StepFunctionContextService.instance(); | ||
it.each([ | ||
["0", "0000"], | ||
["1", "0001"], | ||
["2", "0010"], | ||
["3", "0011"], | ||
["4", "0100"], | ||
["5", "0101"], | ||
["6", "0110"], | ||
["7", "0111"], | ||
["8", "1000"], | ||
["9", "1001"], | ||
["a", "1010"], | ||
["b", "1011"], | ||
["c", "1100"], | ||
["d", "1101"], | ||
["e", "1110"], | ||
["f", "1111"], | ||
[0, "00000000"], | ||
[1, "00000001"], | ||
[2, "00000010"], | ||
[3, "00000011"], | ||
[4, "00000100"], | ||
])("returns the right binary number for %s => %s", (hex, expected) => { | ||
const binary = instance["hexToBinary"](hex); | ||
const binary = instance["numberToBinaryString"](hex); | ||
expect(binary).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe("test 64 bits deterministicSha256HashToBigIntString for span id", () => { | ||
const instance = StepFunctionContextService.instance(); | ||
it("first test of #1", () => { | ||
const actual = instance["deterministicSha256HashToBigIntString"]( | ||
"arn:aws:states:sa-east-1:425362996713:stateMachine:MyStateMachine-b276uka1j#lambda#1", | ||
PARENT_ID, | ||
); | ||
expect(actual).toEqual("3711631873188331089"); | ||
}); | ||
|
||
it("test same hashing number is generated as logs-backend for execution id # state name # entered time", () => { | ||
const actual = instance["deterministicSha256HashToBigIntString"]( | ||
"arn:aws:states:sa-east-1:425362996713:stateMachine:MyStateMachine-b276uka1j#lambda#2", | ||
PARENT_ID, | ||
); | ||
expect(actual).toEqual("5759173372325510050"); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this matches logs-backend's hash result |
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this matches logs-backend PR's hashing result
https://github.com/DataDog/logs-backend/pull/71616/files#diff-820e0a1dd4f0f97815ac54f993c08b3c44c67dd26a312968c214f16ab73494c0R15