Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/opencensus/trace/link.py: 35%

20 statements  

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

1# Copyright 2017, OpenCensus Authors 

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 

16class Type(object): 

17 """The relationship of the current span relative to the linked span: child, 

18 parent, or unspecified. 

19 

20 Attributes: 

21 TYPE_UNSPECIFIED (int): The relationship of the two spans is unknown. 

22 CHILD_LINKED_SPAN (int): The linked span is a child of the current span. 

23 PARENT_LINKED_SPAN (int): The linked span is a parent of the current 

24 span. 

25 """ 

26 TYPE_UNSPECIFIED = 0 

27 CHILD_LINKED_SPAN = 1 

28 PARENT_LINKED_SPAN = 2 

29 

30 

31class Link(object): 

32 """A pointer from the current span to another span in the same trace or in 

33 a different trace. For example, this can be used in batching operations, 

34 where a single batch handler processes multiple requests from different 

35 traces or when the handler receives a request from a different project. 

36 

37 :type trace_id: str 

38 :param trace_id: The [TRACE_ID] for a trace within a project. 

39 

40 :type span_id: str 

41 :param span_id: The [SPAN_ID] for a span within a trace. 

42 

43 :type type: Enum of :class:`~opencensus.trace.link.Type` 

44 :param type: The relationship of the current span relative to the linked 

45 span. 

46 

47 :type attributes: :class:`~opencensus.trace.attributes.Attributes` 

48 :param attributes: A set of attributes on the link. You have have up to 32 

49 attributes per link. 

50 """ 

51 def __init__(self, trace_id, span_id, type=None, attributes=None): 

52 self.trace_id = trace_id 

53 self.span_id = span_id 

54 

55 if type is None: 

56 type = Type.TYPE_UNSPECIFIED 

57 

58 self.type = type 

59 self.attributes = attributes 

60 

61 def format_link_json(self): 

62 """Convert a Link object to json format.""" 

63 link_json = {} 

64 link_json['trace_id'] = self.trace_id 

65 link_json['span_id'] = self.span_id 

66 link_json['type'] = self.type 

67 

68 if self.attributes is not None: 

69 link_json['attributes'] = self.attributes 

70 

71 return link_json