-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Batch traces before making API calls (#291)
- Loading branch information
Showing
5 changed files
with
161 additions
and
85 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from mock import MagicMock, patch | ||
import os | ||
import sys | ||
import unittest | ||
|
||
sys.modules["datadog_lambda.wrapper"] = MagicMock() | ||
sys.modules["datadog_lambda.metric"] = MagicMock() | ||
sys.modules["datadog"] = MagicMock() | ||
sys.modules["requests"] = MagicMock() | ||
|
||
env_patch = patch.dict(os.environ, {"DD_API_KEY": "11111111111111111111111111111111"}) | ||
env_patch.start() | ||
from lambda_function import batch_trace_payloads | ||
|
||
env_patch.stop() | ||
|
||
|
||
class TestBatchTracePayloads(unittest.TestCase): | ||
def test_batch_trace_payloads(self): | ||
trace_payloads = [ | ||
{"tags": "tag1:value", "message": '{"traces":[[{"trace_id":"1"}]]}\n',}, | ||
{ | ||
"tags": "tag1:value", | ||
"message": '{"traces":[[{"trace_id":"2"}, {"trace_id":"3"}]]}\n', | ||
}, | ||
{ | ||
"tags": "tag2:value", | ||
"message": '{"traces":[[{"trace_id":"4"}], [{"trace_id":"5"}]]}\n', | ||
}, | ||
] | ||
|
||
batched_payloads = batch_trace_payloads(trace_payloads) | ||
|
||
expected_batched_payloads = [ | ||
{ | ||
"tags": "tag1:value", | ||
"message": '{"traces": [[{"trace_id": "1"}], [{"trace_id": "2"}, {"trace_id": "3"}]]}', | ||
}, | ||
{ | ||
"tags": "tag2:value", | ||
"message": '{"traces": [[{"trace_id": "4"}], [{"trace_id": "5"}]]}', | ||
}, | ||
] | ||
|
||
self.assertEqual(batched_payloads, expected_batched_payloads) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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