Skip to content

Commit

Permalink
Merge branch 'main' into record-base-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Mar 22, 2024
2 parents cb53ea1 + 29c293f commit d4872bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
27 changes: 14 additions & 13 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Dict,
Iterator,
List,
MutableMapping,
Optional,
Sequence,
Tuple,
Expand Down Expand Up @@ -745,17 +746,17 @@ def __init__(
parent: Optional[trace_api.SpanContext] = None,
sampler: Optional[sampling.Sampler] = None,
trace_config: None = None, # TODO
resource: Resource = None,
resource: Optional[Resource] = None,
attributes: types.Attributes = None,
events: Sequence[Event] = None,
events: Optional[Sequence[Event]] = None,
links: Sequence[trace_api.Link] = (),
kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL,
span_processor: SpanProcessor = SpanProcessor(),
instrumentation_info: InstrumentationInfo = None,
instrumentation_info: Optional[InstrumentationInfo] = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
limits=_UnsetLimits,
instrumentation_scope: InstrumentationScope = None,
instrumentation_scope: Optional[InstrumentationScope] = None,
) -> None:
if resource is None:
resource = Resource.create({})
Expand Down Expand Up @@ -994,7 +995,7 @@ def record_exception(
type(exception), value=exception, tb=exception.__traceback__
)
)
_attributes = {
_attributes: MutableMapping[str, types.AttributeValue] = {
"exception.type": exception.__class__.__name__,
"exception.message": str(exception),
"exception.stacktrace": stacktrace,
Expand Down Expand Up @@ -1045,7 +1046,7 @@ def start_as_current_span(
context: Optional[context_api.Context] = None,
kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL,
attributes: types.Attributes = None,
links: Sequence[trace_api.Link] = (),
links: Optional[Sequence[trace_api.Link]] = (),
start_time: Optional[int] = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
Expand Down Expand Up @@ -1075,7 +1076,7 @@ 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: Sequence[trace_api.Link] = (),
links: Optional[Sequence[trace_api.Link]] = (),
start_time: Optional[int] = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
Expand Down Expand Up @@ -1152,15 +1153,15 @@ class TracerProvider(trace_api.TracerProvider):

def __init__(
self,
sampler: sampling.Sampler = None,
resource: Resource = None,
sampler: Optional[sampling.Sampler] = None,
resource: Optional[Resource] = None,
shutdown_on_exit: bool = True,
active_span_processor: Union[
SynchronousMultiSpanProcessor, ConcurrentMultiSpanProcessor
SynchronousMultiSpanProcessor, ConcurrentMultiSpanProcessor, None
] = None,
id_generator: IdGenerator = None,
span_limits: SpanLimits = None,
):
id_generator: Optional[IdGenerator] = None,
span_limits: Optional[SpanLimits] = None,
) -> None:
self._active_span_processor = (
active_span_processor or SynchronousMultiSpanProcessor()
)
Expand Down
32 changes: 17 additions & 15 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(
self,
decision: Decision,
attributes: "Attributes" = None,
trace_state: "TraceState" = None,
trace_state: Optional["TraceState"] = None,
) -> None:
self.decision = decision
if attributes is None:
Expand All @@ -201,10 +201,10 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
links: Optional[Sequence["Link"]] = None,
trace_state: Optional["TraceState"] = None,
) -> "SamplingResult":
pass

Expand All @@ -216,18 +216,18 @@ def get_description(self) -> str:
class StaticSampler(Sampler):
"""Sampler that always returns the same decision."""

def __init__(self, decision: "Decision"):
def __init__(self, decision: "Decision") -> None:
self._decision = decision

def should_sample(
self,
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
links: Optional[Sequence["Link"]] = None,
trace_state: Optional["TraceState"] = None,
) -> "SamplingResult":
if self._decision is Decision.DROP:
attributes = None
Expand Down Expand Up @@ -285,10 +285,10 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
links: Optional[Sequence["Link"]] = None,
trace_state: Optional["TraceState"] = None,
) -> "SamplingResult":
decision = Decision.DROP
if trace_id & self.TRACE_ID_LIMIT < self.bound:
Expand Down Expand Up @@ -340,10 +340,10 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
kind: Optional[SpanKind] = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
links: Optional[Sequence["Link"]] = None,
trace_state: Optional["TraceState"] = None,
) -> "SamplingResult":
parent_span_context = get_current_span(
parent_context
Expand Down Expand Up @@ -443,7 +443,9 @@ def _get_from_env_or_default() -> Sampler:
return _KNOWN_SAMPLERS[trace_sampler]


def _get_parent_trace_state(parent_context) -> Optional["TraceState"]:
def _get_parent_trace_state(
parent_context: Optional[Context],
) -> Optional["TraceState"]:
parent_span_context = get_current_span(parent_context).get_span_context()
if parent_span_context is None or not parent_span_context.is_valid:
return None
Expand Down

0 comments on commit d4872bd

Please sign in to comment.