Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make span attributes inaccessible except when needed [WIP] #1501

Closed
Closed
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
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ exclude-protected=_asdict,
_fields,
_replace,
_source,
_make,
_Span
_make

# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from opentelemetry import trace as trace_api
from opentelemetry.configuration import Configuration
from opentelemetry.exporter.jaeger.gen.jaeger import ttypes as jaeger
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.trace import _ReadWriteSpan, Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCode
Expand All @@ -38,7 +37,7 @@ def setUp(self):
is_remote=False,
)

self._test_span = trace._Span("test_span", context=context)
self._test_span = _ReadWriteSpan("test_span", context=context)
self._test_span.start()
self._test_span.end()
# pylint: disable=protected-access
Expand Down Expand Up @@ -230,18 +229,18 @@ def test_translate_to_jaeger(self):
]

otel_spans = [
trace._Span(
_ReadWriteSpan(
name=span_names[0],
context=span_context,
parent=parent_span_context,
events=(event,),
links=(link,),
kind=trace_api.SpanKind.CLIENT,
),
trace._Span(
_ReadWriteSpan(
name=span_names[1], context=parent_span_context, parent=None
),
trace._Span(
_ReadWriteSpan(
name=span_names[2], context=other_context, parent=None
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
OpenCensusSpanExporter,
translate_to_collector,
)
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import _ReadWriteSpan, Event
from opentelemetry.sdk.trace.export import SpanExportResult
from opentelemetry.trace import TraceFlags

Expand Down Expand Up @@ -108,7 +108,7 @@ def test_translate_to_collector(self):
"key_float": 0.3,
}
event_timestamp = base_time + 50 * 10 ** 6
event = trace.Event(
event = Event(
name="event0",
timestamp=event_timestamp,
attributes=event_attributes,
Expand All @@ -120,21 +120,21 @@ def test_translate_to_collector(self):
link_2 = trace_api.Link(
context=parent_span_context, attributes=link_attributes
)
span_1 = trace._Span(
span_1 = _ReadWriteSpan(
name="test1",
context=span_context,
parent=parent_span_context,
events=(event,),
links=(link_1,),
kind=trace_api.SpanKind.CLIENT,
)
span_2 = trace._Span(
span_2 = _ReadWriteSpan(
name="test2",
context=parent_span_context,
parent=None,
kind=trace_api.SpanKind.SERVER,
)
span_3 = trace._Span(
span_3 = _ReadWriteSpan(
name="test3",
context=other_context,
links=(link_2,),
Expand Down Expand Up @@ -300,7 +300,7 @@ def test_export(self):
trace_flags=TraceFlags(TraceFlags.SAMPLED),
)
otel_spans = [
trace._Span(
_ReadWriteSpan(
name="test1",
context=span_context,
kind=trace_api.SpanKind.CLIENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from opentelemetry.proto.trace.v1.trace_pb2 import Span as OTLPSpan
from opentelemetry.proto.trace.v1.trace_pb2 import Status
from opentelemetry.sdk.resources import Resource as SDKResource
from opentelemetry.sdk.trace import TracerProvider, _Span
from opentelemetry.sdk.trace import _ReadWriteSpan, TracerProvider
from opentelemetry.sdk.trace.export import (
SimpleExportSpanProcessor,
SpanExportResult,
Expand Down Expand Up @@ -127,7 +127,7 @@ def setUp(self):

type(event_mock).name = PropertyMock(return_value="a")

self.span = _Span(
self.span = _ReadWriteSpan(
"a",
context=Mock(
**{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
nsec_to_usec_round,
)
from opentelemetry.exporter.zipkin.gen import zipkin_pb2
from opentelemetry.sdk import trace
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.trace import _ReadWriteSpan, Event, Resource
from opentelemetry.sdk.trace.export import SpanExportResult
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanKind, TraceFlags
Expand All @@ -51,7 +50,7 @@ def setUp(self):
is_remote=False,
)

self._test_span = trace._Span("test_span", context=context)
self._test_span = _ReadWriteSpan("test_span", context=context)
self._test_span.start()
self._test_span.end()

Expand Down Expand Up @@ -166,7 +165,7 @@ def test_export_json(self):
}

event_timestamp = base_time + 50 * 10 ** 6
event = trace.Event(
event = Event(
name="event0",
timestamp=event_timestamp,
attributes=event_attributes,
Expand All @@ -179,20 +178,20 @@ def test_export_json(self):
)

otel_spans = [
trace._Span(
_ReadWriteSpan(
name=span_names[0],
context=span_context,
parent=parent_span_context,
events=(event,),
links=(link,),
),
trace._Span(
_ReadWriteSpan(
name=span_names[1], context=parent_span_context, parent=None
),
trace._Span(
_ReadWriteSpan(
name=span_names[2], context=other_context, parent=None
),
trace._Span(
_ReadWriteSpan(
name=span_names[3], context=other_context, parent=None
),
]
Expand Down Expand Up @@ -354,7 +353,7 @@ def test_export_json_zero_padding(self):
trace_id, parent_id, is_remote=False
)

otel_span = trace._Span(
otel_span = _ReadWriteSpan(
name=span_names[0],
context=span_context,
parent=parent_span_context,
Expand Down Expand Up @@ -415,7 +414,7 @@ def test_export_json_max_tag_length(self):
trace_flags=TraceFlags(TraceFlags.SAMPLED),
)

span = trace._Span(name="test-span", context=span_context,)
span = _ReadWriteSpan(name="test-span", context=span_context,)

span.start()
span.resource = Resource({})
Expand Down Expand Up @@ -686,7 +685,7 @@ def test_export_protobuf(self):
}

event_timestamp = base_time + 50 * 10 ** 6
event = trace.Event(
event = Event(
name="event0",
timestamp=event_timestamp,
attributes=event_attributes,
Expand All @@ -699,20 +698,20 @@ def test_export_protobuf(self):
)

otel_spans = [
trace._Span(
_ReadWriteSpan(
name=span_names[0],
context=span_context,
parent=parent_span_context,
events=(event,),
links=(link,),
),
trace._Span(
_ReadWriteSpan(
name=span_names[1], context=parent_span_context, parent=None
),
trace._Span(
_ReadWriteSpan(
name=span_names[2], context=other_context, parent=None
),
trace._Span(
_ReadWriteSpan(
name=span_names[3], context=other_context, parent=None
),
]
Expand Down Expand Up @@ -871,7 +870,7 @@ def test_export_protobuf_max_tag_length(self):
trace_flags=TraceFlags(TraceFlags.SAMPLED),
)

span = trace._Span(name="test-span", context=span_context,)
span = _ReadWriteSpan(name="test-span", context=span_context,)

span.start()
span.resource = Resource({})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ def test_tags(self):
tags = {"foo": "bar"}
with self.shim.start_active_span("TestSetTag", tags=tags) as scope:
scope.span.set_tag("baz", "qux")

self.assertEqual(scope.span.unwrap().attributes["foo"], "bar")
self.assertEqual(scope.span.unwrap().attributes["baz"], "qux")
span = scope.span.unwrap()._data # pylint: disable=protected-access
self.assertEqual(span.attributes["foo"], "bar")
self.assertEqual(span.attributes["baz"], "qux")

def test_span_tracer(self):
"""Test the `tracer` property on `Span` objects."""
Expand Down Expand Up @@ -479,7 +479,7 @@ def test_span_on_error(self):
raise Exception

# Verify exception details have been added to span.
self.assertEqual(scope.span.unwrap().attributes["error"], True)
self.assertEqual(scope.span.unwrap()._data.attributes["error"], True) # pylint: disable=protected-access

def test_inject_http_headers(self):
"""Test `inject()` method for Format.HTTP_HEADERS."""
Expand Down
Loading