Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 23 additions & 9 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def on_start(
span: The :class:`opentelemetry.trace.Span` that just started.
parent_context: The parent context of the span that just started.
"""
...

def on_end(self, span: "ReadableSpan") -> None:
"""Called when a :class:`opentelemetry.trace.Span` is ended.
Expand All @@ -122,9 +123,11 @@ def on_end(self, span: "ReadableSpan") -> None:
Args:
span: The :class:`opentelemetry.trace.Span` that just ended.
"""
...

def shutdown(self) -> None:
"""Called when a :class:`opentelemetry.sdk.trace.TracerProvider` is shutdown."""
...

def force_flush(self, timeout_millis: int = 30000) -> bool:
"""Export all ended spans to the configured Exporter that have not yet
Expand All @@ -137,6 +140,7 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
Returns:
False if the timeout is exceeded, True otherwise.
"""
...


# Temporary fix until https://github.com/PyCQA/pylint/issues/4098 is resolved
Expand Down Expand Up @@ -273,7 +277,7 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
timeout, False otherwise.
"""
futures = []
for sp in self._span_processors: # type: SpanProcessor
for sp in self._span_processors:
future = self._executor.submit(sp.force_flush, timeout_millis)
futures.append(future)

Expand Down Expand Up @@ -377,7 +381,7 @@ class ReadableSpan:
def __init__(
self,
name: str,
context: Optional[trace_api.SpanContext] = None,
context: trace_api.SpanContext,
parent: Optional[trace_api.SpanContext] = None,
resource: Optional[Resource] = None,
attributes: types.Attributes = None,
Expand Down Expand Up @@ -621,12 +625,12 @@ def __init__(
max_span_attribute_length: Optional[int] = None,
):
# span events and links count
self.max_events = self._from_env_if_absent(
self.max_events = self._from_env_if_absent_with_default(
max_events,
OTEL_SPAN_EVENT_COUNT_LIMIT,
_DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMIT,
)
self.max_links = self._from_env_if_absent(
self.max_links = self._from_env_if_absent_with_default(
max_links,
OTEL_SPAN_LINK_COUNT_LIMIT,
_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT,
Expand All @@ -642,7 +646,7 @@ def __init__(
else _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT
)

self.max_span_attributes = self._from_env_if_absent(
self.max_span_attributes = self._from_env_if_absent_with_default(
max_span_attributes,
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
(
Expand All @@ -651,7 +655,7 @@ def __init__(
else _DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
),
)
self.max_event_attributes = self._from_env_if_absent(
self.max_event_attributes = self._from_env_if_absent_with_default(
max_event_attributes,
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT,
(
Expand All @@ -660,7 +664,7 @@ def __init__(
else _DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT
),
)
self.max_link_attributes = self._from_env_if_absent(
self.max_link_attributes = self._from_env_if_absent_with_default(
max_link_attributes,
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT,
(
Expand Down Expand Up @@ -713,6 +717,13 @@ def _from_env_if_absent(
raise ValueError(err_msg.format(env_var, value))
return value

@classmethod
def _from_env_if_absent_with_default(
cls, value: Optional[int], env_var: str, default: int
) -> int:
value_from_env = cls._from_env_if_absent(value, env_var, default)
return value_from_env if value_from_env is not None else default


_UnsetLimits = SpanLimits(
max_attributes=SpanLimits.UNSET,
Expand Down Expand Up @@ -998,7 +1009,7 @@ def __exit__(
self.record_exception(exception=exc_val, escaped=True)
# Records status if span is used as context manager
# i.e. with tracer.start_span() as span:
if self._set_status_on_exception:
if exc_type and self._set_status_on_exception:
self.set_status(
Status(
status_code=StatusCode.ERROR,
Expand Down Expand Up @@ -1110,11 +1121,14 @@ def start_span( # pylint: disable=too-many-locals
context: Optional[context_api.Context] = None,
kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL,
attributes: types.Attributes = None,
links: Optional[Sequence[trace_api.Link]] = (),
links: Optional[Sequence[trace_api.Link]] = None,
start_time: Optional[int] = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
) -> trace_api.Span:
if links is None:
links = ()

parent_span_context = trace_api.get_current_span(
context
).get_span_context()
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ exclude = [
"opentelemetry-sdk/tests",
"opentelemetry-sdk/src/opentelemetry/sdk/_events",
"opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/",
"opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py",
"opentelemetry-sdk/benchmarks",
"exporter/opentelemetry-exporter-otlp-proto-grpc/tests",
]
Expand Down
Loading