Skip to content
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

feat: Add support for library instrumentation #551

Merged
merged 80 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
4979159
Add .python-version to .gitignore
arbrown May 13, 2022
34058e9
Add initial class/test for instrumentation_source
arbrown May 13, 2022
2c0668a
Add version and truncate logic
arbrown May 16, 2022
18e67e7
Add instrumentation tests and severity info
arbrown May 16, 2022
1868ed8
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 16, 2022
3ba423b
Add method to update and validate existing info
arbrown May 16, 2022
0ba6769
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 16, 2022
1188002
Add .python-version to gitignore
arbrown May 16, 2022
67f2343
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 16, 2022
8186234
Implement hook to add instrumentation for logger
arbrown May 17, 2022
3c4b057
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 17, 2022
19ac45c
Add tests for logger instrumentation logic
arbrown May 18, 2022
c006efd
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 18, 2022
ce3f231
Update structured log handler to emit info
arbrown May 18, 2022
1d80ff8
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 18, 2022
d354c45
Refactor structured log and add unit test
arbrown May 18, 2022
8f92f68
Merge branch 'main' into instrumentation
arbrown May 18, 2022
5b51050
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 18, 2022
b7b82e3
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] May 18, 2022
26016cf
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 18, 2022
aaa3675
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] May 18, 2022
4700b45
Add side effect to unit test
arbrown May 18, 2022
385aeb6
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 18, 2022
d15abab
Update to environment submodule
arbrown May 23, 2022
81a80c8
Fix linter errors
arbrown May 23, 2022
0eef799
chore(main): release 3.1.0 (#479)
release-please[bot] May 19, 2022
f5a357c
docs: Change button in README to .png file (#554)
arbrown May 22, 2022
738d9dc
chore(main): release 3.1.1 (#557)
release-please[bot] May 23, 2022
a64da5f
Update env-tests submodule
arbrown May 23, 2022
028bdfe
Merge branch 'main' into instrumentation
arbrown May 23, 2022
dc6a797
Minor format update
arbrown May 24, 2022
f6d37d5
Fix system test to skip diagnostic log entry
arbrown May 24, 2022
249a764
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 24, 2022
9be9332
Merge branch 'main' into instrumentation
arbrown Jun 3, 2022
38fee9f
Update truncation logic based on feedback
arbrown Jun 3, 2022
c3b63ba
Update environment tests
arbrown Jun 3, 2022
80ef001
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
61fe753
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jun 3, 2022
b86a946
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
d010873
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jun 3, 2022
ce5425b
Fix broken unit test
arbrown Jun 3, 2022
abfd16c
Fix broken unit test
arbrown Jun 3, 2022
cb1e6bf
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
cbd3835
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jun 3, 2022
5d0e702
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
9b7388d
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jun 3, 2022
5bff645
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
1157018
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jun 3, 2022
cd78d79
Change default name/version
arbrown Jun 3, 2022
4f81c5a
Refactor add_instrumentation
arbrown Jun 3, 2022
4553d7f
Add more documentation to validation methods
arbrown Jun 3, 2022
7d98aad
Refactor add_instrumentation to be more pythonic
arbrown Jun 3, 2022
4962604
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 3, 2022
70e6233
Update environemnt tests
arbrown Jun 8, 2022
05ae10e
Merge branch 'main' into instrumentation
arbrown Jun 8, 2022
3c3b6bb
Refactor _is_valid and add test
arbrown Jun 8, 2022
f96772a
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 8, 2022
914c98d
Add more detail to method documentation
arbrown Jun 8, 2022
27aa896
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 8, 2022
5d55bfd
Move methods to private
arbrown Jun 8, 2022
fc8ada3
Change instumentation_added to private
arbrown Jul 1, 2022
7e77837
Fix some issues with validation method
arbrown Jul 1, 2022
ee4fc22
Fix bug in _add_instrumentation
arbrown Jul 1, 2022
8fac555
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 1, 2022
55bfa06
Simplify string truncation
arbrown Jul 1, 2022
c939097
Merge branch 'main' into instrumentation
arbrown Jul 1, 2022
b5d8400
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 1, 2022
da3caa9
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jul 1, 2022
bfda525
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 1, 2022
b5dfeef
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jul 1, 2022
d62389a
Merge branch 'main' into instrumentation
daniel-sanche Jul 6, 2022
572a04c
Remove unused import to fix lint
arbrown Jul 6, 2022
6676621
Merge branch 'main' into instrumentation
arbrown Jul 11, 2022
587367c
Remove validate_and_update_instrumentation
arbrown Jul 11, 2022
b60ae45
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 11, 2022
f84d303
Remove _is_valid code (no longer checked)
arbrown Jul 11, 2022
b7f5c41
Run nox blacken
arbrown Jul 11, 2022
4066927
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 11, 2022
8acee94
Merge branch 'instrumentation' of https://github.com/googleapis/pytho…
gcf-owl-bot[bot] Jul 11, 2022
7b85737
Remove extraneous unit test
arbrown Jul 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add instrumentation tests and severity info
  • Loading branch information
arbrown committed May 16, 2022
commit 18e67e7e6b4b4388ec8d2717569effd8d4a41cc3
14 changes: 8 additions & 6 deletions google/cloud/logging_v2/_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def create_diagnostic_entry(name=None, version=None):
"""
name = name if name != None else _PYTHON_LIBRARY_NAME
version = version if version != None else _LIBRARY_VERSION
payload = {_DIAGNOSTIC_INFO_KEY: {
_INSTRUMENTATION_SOURCE_KEY: {
"name": truncate_string(name, _MAX_NAME_LENGTH),
"version": truncate_string(version, 16),
payload = {
_DIAGNOSTIC_INFO_KEY: {
_INSTRUMENTATION_SOURCE_KEY: {
"name": truncate_string(name, _MAX_NAME_LENGTH),
"version": truncate_string(version, _MAX_VERSION_LENGTH),
}
}
}}
entry = StructEntry(payload=payload)
}
entry = StructEntry(payload=payload, severity="INFO")
return entry

def truncate_string(str, max_length):
Expand Down
33 changes: 29 additions & 4 deletions tests/unit/test__instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,37 @@
# limitations under the License.

import unittest
import google.cloud.logging_v2._instrumentation as i

class TestInstrumentation(unittest.TestCase):

TEST_NAME = "python"
# LONG_NAME > 14 characters
LONG_NAME = TEST_NAME + "789ABCDEF"

def test_default_diagnostic_info(self):
import google.cloud.logging_v2._instrumentation as i
TEST_VERSION = "1.0.0"
# LONG_VERSION > 16 characters
LONG_VERSION = TEST_VERSION + "6789ABCDEF12"

def _get_diagonstic_value(self, entry, key):
return entry.payload[i._DIAGNOSTIC_INFO_KEY][i._INSTRUMENTATION_SOURCE_KEY][key]

def test_default_diagnostic_info(self):
entry = i.create_diagnostic_entry()
self.assertEqual(entry.payload[i._DIAGNOSTIC_INFO_KEY][i._INSTRUMENTATION_SOURCE_KEY]["name"], i._PYTHON_LIBRARY_NAME)
self.assertEqual(entry.payload[i._DIAGNOSTIC_INFO_KEY][i._INSTRUMENTATION_SOURCE_KEY]["version"], i._LIBRARY_VERSION)
self.assertEqual(i._PYTHON_LIBRARY_NAME, self._get_diagonstic_value(entry, "name"),)
self.assertEqual(i._LIBRARY_VERSION, self._get_diagonstic_value(entry, "version"))

def test_custom_diagnostic_info(self):
entry = i.create_diagnostic_entry(name = self.TEST_NAME, version = self.TEST_VERSION)
self.assertEqual(self.TEST_NAME, self._get_diagonstic_value(entry, "name"),)
self.assertEqual(self.TEST_VERSION, self._get_diagonstic_value(entry, "version"))

def test_truncate_long_values(self):
entry = i.create_diagnostic_entry(name = self.LONG_NAME, version = self.LONG_VERSION)

expected_name = self.LONG_NAME[:i._MAX_NAME_LENGTH -1] + "*"
expected_version = self.LONG_VERSION[:i._MAX_VERSION_LENGTH - 1] + "*"

self.assertEqual(expected_name, self._get_diagonstic_value(entry, "name"))
self.assertEqual(expected_version, self._get_diagonstic_value(entry, "version"))