Skip to content

Commit

Permalink
Merge branch 'master' into issue_1236
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Oct 16, 2020
2 parents b2bd32f + 5fc08ad commit 83226c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

logger = logging.getLogger(__name__)

MAX_NUM_ATTRIBUTES = 32
MAX_NUM_EVENTS = 128
MAX_NUM_LINKS = 32
MAX_NUM_ATTRIBUTES = 1000
MAX_NUM_EVENTS = 1000
MAX_NUM_LINKS = 1000
VALID_ATTR_VALUE_TYPES = (bool, str, int, float)


Expand Down Expand Up @@ -463,6 +463,8 @@ def _format_context(context):
def _format_attributes(attributes):
if isinstance(attributes, BoundedDict):
return attributes._dict # pylint: disable=protected-access
if isinstance(attributes, MappingProxyType):
return attributes.copy()
return attributes

@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from opentelemetry import trace as trace_api
from opentelemetry.sdk import resources, trace
from opentelemetry.sdk.trace import Resource, sampling
from opentelemetry.sdk.util import ns_to_iso_str
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.util import time_ns
Expand Down Expand Up @@ -1032,3 +1033,22 @@ def test_to_json(self):
span.to_json(indent=None),
'{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "attributes": {}, "events": [], "links": [], "resource": {}}',
)

def test_attributes_to_json(self):
context = trace_api.SpanContext(
trace_id=0x000000000000000000000000DEADBEEF,
span_id=0x00000000DEADBEF0,
is_remote=False,
trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED),
)
span = trace._Span("span-name", context)
span.resource = Resource({})
span.set_attribute("key", "value")
span.add_event("event", {"key2": "value2"}, 123)
date_str = ns_to_iso_str(123)
self.assertEqual(
span.to_json(indent=None),
'{"name": "span-name", "context": {"trace_id": "0x000000000000000000000000deadbeef", "span_id": "0x00000000deadbef0", "trace_state": "{}"}, "kind": "SpanKind.INTERNAL", "parent_id": null, "start_time": null, "end_time": null, "attributes": {"key": "value"}, "events": [{"name": "event", "timestamp": "'
+ date_str
+ '", "attributes": {"key2": "value2"}}], "links": [], "resource": {}}',
)

0 comments on commit 83226c5

Please sign in to comment.