Skip to content

Commit

Permalink
Quarantine type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
c24t committed Jul 31, 2019
1 parent 48f2fe4 commit 89f1a0c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

from opentelemetry import loader

# TODO: quarantine
ParentSpan = typing.Optional[typing.Union['Span', 'SpanContext']]


Expand Down
19 changes: 19 additions & 0 deletions opentelemetry-api/src/opentelemetry/types.py
Original file line number Diff line number Diff line change
@@ -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]
19 changes: 8 additions & 11 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import typing

from opentelemetry import trace as trace_api
from opentelemetry import types
from opentelemetry.sdk import util

try:
Expand All @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -233,23 +231,23 @@ 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)
self.attributes[key] = value

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)
self.events.append(Event(name, attributes))

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)
Expand Down Expand Up @@ -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:
Expand All @@ -307,15 +303,16 @@ 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:
yield span

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()
Expand Down

0 comments on commit 89f1a0c

Please sign in to comment.