From 5554152ff87934f60d58c96b15ad90ad81b26229 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 16 Oct 2020 01:39:41 -0400 Subject: [PATCH 1/2] Bug fix: Serialize event attributes properly (#1246) --- .../src/opentelemetry/sdk/trace/__init__.py | 2 ++ opentelemetry-sdk/tests/trace/test_trace.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 4eb6760a9ae..c43ceaf33a8 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -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 diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 92dce44e232..571fe755158 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -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 @@ -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": {}}', + ) From 5fc08ad642dc7b9acd557536647e789b540bc2ff Mon Sep 17 00:00:00 2001 From: alrex Date: Fri, 16 Oct 2020 07:35:01 -0700 Subject: [PATCH 2/2] Updating limits for attributes, events, links (#1249) --- opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index c43ceaf33a8..1d27e5c739b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -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)