Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/error_reporting/_logging.py: 62%

8 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:45 +0000

1# Copyright 2016 Google LLC All Rights Reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15"""Interact with Error Reporting via Logging API. 

16 

17It's possible to report Error Reporting errors by formatting 

18structured log messages in Cloud Logging in a given format. This 

19client provides a mechanism to report errors using that technique. 

20""" 

21 

22import google.cloud.logging 

23 

24 

25class _ErrorReportingLoggingAPI(object): 

26 """Report to Error Reporting via Logging API 

27 

28 :type project: str 

29 :param project: the project which the client acts on behalf of. If not 

30 passed falls back to the default inferred from the 

31 environment. 

32 

33 :type credentials: :class:`google.auth.credentials.Credentials` or 

34 :class:`NoneType` 

35 :param credentials: The authorization credentials to attach to requests. 

36 These credentials identify this application to the service. 

37 If none are specified, the client will attempt to ascertain 

38 the credentials from the environment. 

39 

40 :type _http: :class:`~requests.Session` 

41 :param _http: (Optional) HTTP object to make requests. Can be any object 

42 that defines ``request()`` with the same interface as 

43 :meth:`requests.Session.request`. If not passed, an 

44 ``_http`` object is created that is bound to the 

45 ``credentials`` for the current object. 

46 This parameter should be considered private, and could 

47 change in the future. 

48 

49 :type client_info: 

50 :class:`google.api_core.client_info.ClientInfo` or 

51 :class:`google.api_core.gapic_v1.client_info.ClientInfo` 

52 :param client_info: 

53 The client info used to send a user-agent string along with API 

54 requests. If ``None``, then default info will be used. Generally, 

55 you only need to set this if you're developing your own library 

56 or partner tool. 

57 

58 :type client_options: :class:`~google.api_core.client_options.ClientOptions` 

59 or :class:`dict` 

60 :param client_options: (Optional) Client options used to set user options 

61 on the client. API Endpoint should be set through client_options. 

62 """ 

63 

64 def __init__( 

65 self, 

66 project, 

67 credentials=None, 

68 _http=None, 

69 client_info=None, 

70 client_options=None, 

71 ): 

72 self.logging_client = google.cloud.logging.Client( 

73 project=project, 

74 credentials=credentials, 

75 _http=_http, 

76 client_info=client_info, 

77 client_options=client_options, 

78 ) 

79 

80 def report_error_event(self, error_report): 

81 """Report error payload. 

82 

83 :type error_report: dict 

84 :param: error_report: 

85 dict payload of the error report formatted according to 

86 https://cloud.google.com/error-reporting/docs/formatting-error-messages 

87 This object should be built using 

88 :meth:~`google.cloud.error_reporting.client._build_error_report` 

89 """ 

90 logger = self.logging_client.logger("errors") 

91 logger.log_struct(error_report)