diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 4eb6760a9ae..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) @@ -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": {}}', + )