From 89f1a0c1c2976c01588a231c7309ee9135ba0ad8 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Tue, 30 Jul 2019 16:22:51 -0700 Subject: [PATCH] Quarantine type aliases --- .../src/opentelemetry/trace/__init__.py | 1 + opentelemetry-api/src/opentelemetry/types.py | 19 +++++++++++++++++++ .../src/opentelemetry/sdk/trace/__init__.py | 19 ++++++++----------- 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 opentelemetry-api/src/opentelemetry/types.py diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 352c2fea5d9..34580c81b9a 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -66,6 +66,7 @@ from opentelemetry import loader +# TODO: quarantine ParentSpan = typing.Optional[typing.Union['Span', 'SpanContext']] diff --git a/opentelemetry-api/src/opentelemetry/types.py b/opentelemetry-api/src/opentelemetry/types.py new file mode 100644 index 00000000000..ce5682ee0af --- /dev/null +++ b/opentelemetry-api/src/opentelemetry/types.py @@ -0,0 +1,19 @@ +# Copyright 2019, OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import typing + +AttributeValue = typing.Union[str, bool, float] +Attributes = typing.Dict[str, AttributeValue] diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 6d39b5c18ee..13a1fff1196 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -23,6 +23,7 @@ import typing from opentelemetry import trace as trace_api +from opentelemetry import types from opentelemetry.sdk import util try: @@ -41,9 +42,6 @@ MAX_NUM_EVENTS = 128 MAX_NUM_LINKS = 32 -AttributeValue = typing.Union[str, bool, float] -Attributes = typing.Dict[str, AttributeValue] - class BoundedList(Sequence): """An append only list with a fixed max size.""" @@ -187,7 +185,7 @@ def __init__(self: 'Span', sampler=None, # TODO trace_config=None, # TODO resource=None, # TODO - attributes: Attributes = None, # TODO + attributes: types.Attributes = None, # TODO events: typing.Sequence[Event] = None, # TODO links: typing.Sequence[Link] = None, # TODO ) -> None: @@ -233,7 +231,7 @@ def get_context(self): def set_attribute(self: 'Span', key: str, - value: 'AttributeValue' + value: 'types.AttributeValue' ) -> None: if self.attributes is Span.empty_attributes: self.attributes = BoundedDict(MAX_NUM_ATTRIBUTES) @@ -241,7 +239,7 @@ def set_attribute(self: 'Span', def add_event(self: 'Span', name: str, - attributes: typing.Dict[str, 'AttributeValue'] + attributes: 'types.Attributes', ) -> None: if self.events is Span.empty_events: self.events = BoundedList(MAX_NUM_EVENTS) @@ -249,7 +247,7 @@ def add_event(self: 'Span', def add_link(self: 'Span', context: 'trace_api.SpanContext', - attributes: typing.Dict[str, 'AttributeValue'], + attributes: 'types.Attributes', ) -> None: if self.links is Span.empty_links: self.links = BoundedList(MAX_NUM_LINKS) @@ -289,8 +287,6 @@ class Tracer(trace_api.Tracer): cv: The context variable that holds the current span. """ - CURRENT_SPAN = trace_api.Tracer.CURRENT_SPAN - def __init__(self, cv: 'contextvars.ContextVar' = _CURRENT_SPAN_CV ) -> None: @@ -307,7 +303,7 @@ def get_current_span(self): @contextmanager def start_span(self, name: str, - parent: trace_api.ParentSpan = CURRENT_SPAN + parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN ) -> typing.Iterator['Span']: """See `opentelemetry.trace.Tracer.start_span`.""" with self.use_span(self.create_span(name, parent)) as span: @@ -315,7 +311,8 @@ def start_span(self, def create_span(self, name: str, - parent: trace_api.ParentSpan = CURRENT_SPAN + parent: trace_api.ParentSpan = + trace_api.Tracer.CURRENT_SPAN ) -> 'Span': """See `opentelemetry.trace.Tracer.create_span`.""" span_id = generate_span_id()