Skip to content

Commit 5d141e1

Browse files
committed
ref: Tweak StreamedSpan interface
1 parent 4d9394d commit 5d141e1

1 file changed

Lines changed: 24 additions & 29 deletions

File tree

sentry_sdk/traces.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ def __init__(
9292
self._span_id: "Optional[str]" = None
9393
self._trace_id: "Optional[str]" = trace_id
9494

95-
self.set_status(SpanStatus.OK)
96-
self.set_source(SegmentSource.CUSTOM)
95+
self._status = SpanStatus.OK.value
96+
self.set_attribute("sentry.span.source", SegmentSource.CUSTOM.value)
97+
98+
def __repr__(self) -> str:
99+
return (
100+
f"<{self.__class__.__name__}("
101+
f"name={self._name}, "
102+
f"trace_id={self.trace_id}, "
103+
f"span_id={self.span_id}>"
104+
)
97105

98106
def get_attributes(self) -> "Attributes":
99107
return self._attributes
@@ -111,44 +119,31 @@ def remove_attribute(self, key: str) -> None:
111119
except KeyError:
112120
pass
113121

114-
def get_status(self) -> "Union[SpanStatus, str]":
115-
if self._status in {s.value for s in SpanStatus}:
116-
return SpanStatus(self._status)
117-
122+
@property
123+
def status(self) -> "str":
118124
return self._status
119125

120-
def set_status(self, status: "Union[SpanStatus, str]") -> None:
126+
@status.setter
127+
def status(self, status: "Union[SpanStatus, str]") -> None:
121128
if isinstance(status, Enum):
122129
status = status.value
123130

124-
self._status = status
125-
126-
def set_http_status(self, http_status: int) -> None:
127-
self.set_attribute(SPANDATA.HTTP_STATUS_CODE, http_status)
131+
if status not in {e.value for e in SpanStatus}:
132+
logger.debug(
133+
f'Unsupported span status {status}. Expected one of: "ok", "error"'
134+
)
135+
return
128136

129-
if http_status >= 400:
130-
self.set_status(SpanStatus.ERROR)
131-
else:
132-
self.set_status(SpanStatus.OK)
137+
self._status = status
133138

134-
def get_name(self) -> str:
139+
@property
140+
def name(self) -> str:
135141
return self._name
136142

137-
def set_name(self, name: str) -> None:
143+
@name.setter
144+
def name(self, name: str) -> None:
138145
self._name = name
139146

140-
def set_op(self, op: str) -> None:
141-
self.set_attribute("sentry.op", op)
142-
143-
def set_origin(self, origin: str) -> None:
144-
self.set_attribute("sentry.origin", origin)
145-
146-
def set_source(self, source: "Union[str, SegmentSource]") -> None:
147-
if isinstance(source, Enum):
148-
source = source.value
149-
150-
self.set_attribute("sentry.span.source", source)
151-
152147
@property
153148
def span_id(self) -> str:
154149
if not self._span_id:

0 commit comments

Comments
 (0)