Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/sentry_sdk/api.py: 62%

83 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1import inspect 

2 

3from sentry_sdk.hub import Hub 

4from sentry_sdk.scope import Scope 

5 

6from sentry_sdk._types import MYPY 

7 

8if MYPY: 8 ↛ 9line 8 didn't jump to line 9, because the condition on line 8 was never true

9 from typing import Any 

10 from typing import Dict 

11 from typing import Optional 

12 from typing import overload 

13 from typing import Callable 

14 from typing import TypeVar 

15 from typing import ContextManager 

16 from typing import Union 

17 

18 from sentry_sdk._types import Event, Hint, Breadcrumb, BreadcrumbHint, ExcInfo 

19 from sentry_sdk.tracing import Span, Transaction 

20 

21 T = TypeVar("T") 

22 F = TypeVar("F", bound=Callable[..., Any]) 

23else: 

24 

25 def overload(x): 

26 # type: (T) -> T 

27 return x 

28 

29 

30# When changing this, update __all__ in __init__.py too 

31__all__ = [ 

32 "capture_event", 

33 "capture_message", 

34 "capture_exception", 

35 "add_breadcrumb", 

36 "configure_scope", 

37 "push_scope", 

38 "flush", 

39 "last_event_id", 

40 "start_span", 

41 "start_transaction", 

42 "set_tag", 

43 "set_context", 

44 "set_extra", 

45 "set_user", 

46 "set_level", 

47] 

48 

49 

50def hubmethod(f): 

51 # type: (F) -> F 

52 f.__doc__ = "%s\n\n%s" % ( 

53 "Alias for :py:meth:`sentry_sdk.Hub.%s`" % f.__name__, 

54 inspect.getdoc(getattr(Hub, f.__name__)), 

55 ) 

56 return f 

57 

58 

59def scopemethod(f): 

60 # type: (F) -> F 

61 f.__doc__ = "%s\n\n%s" % ( 

62 "Alias for :py:meth:`sentry_sdk.Scope.%s`" % f.__name__, 

63 inspect.getdoc(getattr(Scope, f.__name__)), 

64 ) 

65 return f 

66 

67 

68@hubmethod 

69def capture_event( 

70 event, # type: Event 

71 hint=None, # type: Optional[Hint] 

72 scope=None, # type: Optional[Any] 

73 **scope_args # type: Any 

74): 

75 # type: (...) -> Optional[str] 

76 return Hub.current.capture_event(event, hint, scope=scope, **scope_args) 

77 

78 

79@hubmethod 

80def capture_message( 

81 message, # type: str 

82 level=None, # type: Optional[str] 

83 scope=None, # type: Optional[Any] 

84 **scope_args # type: Any 

85): 

86 # type: (...) -> Optional[str] 

87 return Hub.current.capture_message(message, level, scope=scope, **scope_args) 

88 

89 

90@hubmethod 

91def capture_exception( 

92 error=None, # type: Optional[Union[BaseException, ExcInfo]] 

93 scope=None, # type: Optional[Any] 

94 **scope_args # type: Any 

95): 

96 # type: (...) -> Optional[str] 

97 return Hub.current.capture_exception(error, scope=scope, **scope_args) 

98 

99 

100@hubmethod 

101def add_breadcrumb( 

102 crumb=None, # type: Optional[Breadcrumb] 

103 hint=None, # type: Optional[BreadcrumbHint] 

104 **kwargs # type: Any 

105): 

106 # type: (...) -> None 

107 return Hub.current.add_breadcrumb(crumb, hint, **kwargs) 

108 

109 

110@overload 

111def configure_scope(): # noqa: F811 

112 # type: () -> ContextManager[Scope] 

113 pass 

114 

115 

116@overload 

117def configure_scope( # noqa: F811 

118 callback, # type: Callable[[Scope], None] 

119): 

120 # type: (...) -> None 

121 pass 

122 

123 

124@hubmethod 

125def configure_scope( # noqa: F811 

126 callback=None, # type: Optional[Callable[[Scope], None]] 

127): 

128 # type: (...) -> Optional[ContextManager[Scope]] 

129 return Hub.current.configure_scope(callback) 

130 

131 

132@overload 

133def push_scope(): # noqa: F811 

134 # type: () -> ContextManager[Scope] 

135 pass 

136 

137 

138@overload 

139def push_scope( # noqa: F811 

140 callback, # type: Callable[[Scope], None] 

141): 

142 # type: (...) -> None 

143 pass 

144 

145 

146@hubmethod 

147def push_scope( # noqa: F811 

148 callback=None, # type: Optional[Callable[[Scope], None]] 

149): 

150 # type: (...) -> Optional[ContextManager[Scope]] 

151 return Hub.current.push_scope(callback) 

152 

153 

154@scopemethod # noqa 

155def set_tag(key, value): 

156 # type: (str, Any) -> None 

157 return Hub.current.scope.set_tag(key, value) 

158 

159 

160@scopemethod # noqa 

161def set_context(key, value): 

162 # type: (str, Dict[str, Any]) -> None 

163 return Hub.current.scope.set_context(key, value) 

164 

165 

166@scopemethod # noqa 

167def set_extra(key, value): 

168 # type: (str, Any) -> None 

169 return Hub.current.scope.set_extra(key, value) 

170 

171 

172@scopemethod # noqa 

173def set_user(value): 

174 # type: (Optional[Dict[str, Any]]) -> None 

175 return Hub.current.scope.set_user(value) 

176 

177 

178@scopemethod # noqa 

179def set_level(value): 

180 # type: (str) -> None 

181 return Hub.current.scope.set_level(value) 

182 

183 

184@hubmethod 

185def flush( 

186 timeout=None, # type: Optional[float] 

187 callback=None, # type: Optional[Callable[[int, float], None]] 

188): 

189 # type: (...) -> None 

190 return Hub.current.flush(timeout=timeout, callback=callback) 

191 

192 

193@hubmethod 

194def last_event_id(): 

195 # type: () -> Optional[str] 

196 return Hub.current.last_event_id() 

197 

198 

199@hubmethod 

200def start_span( 

201 span=None, # type: Optional[Span] 

202 **kwargs # type: Any 

203): 

204 # type: (...) -> Span 

205 return Hub.current.start_span(span=span, **kwargs) 

206 

207 

208@hubmethod 

209def start_transaction( 

210 transaction=None, # type: Optional[Transaction] 

211 **kwargs # type: Any 

212): 

213 # type: (...) -> Transaction 

214 return Hub.current.start_transaction(transaction, **kwargs)