diff --git a/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift b/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift index 705ff41d..0460d637 100644 --- a/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift +++ b/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift @@ -195,26 +195,28 @@ public class RecordEventsReadableSpan: ReadableSpan { } public func toSpanData() -> SpanData { - return SpanData(traceId: context.traceId, - spanId: context.spanId, - traceFlags: context.traceFlags, - traceState: context.traceState, - parentSpanId: parentContext?.spanId, - resource: resource, - instrumentationScope: instrumentationScopeInfo, - name: name, - kind: kind, - startTime: startTime, - attributes: attributes.attributes, - events: adaptEvents(), - links: adaptLinks(), - status: status, - endTime: endTime ?? clock.now, - hasRemoteParent: hasRemoteParent, - hasEnded: hasEnded, - totalRecordedEvents: getTotalRecordedEvents(), - totalRecordedLinks: totalRecordedLinks, - totalAttributeCount: totalAttributeCount) + attributesSyncLock.withLock { + return SpanData(traceId: context.traceId, + spanId: context.spanId, + traceFlags: context.traceFlags, + traceState: context.traceState, + parentSpanId: parentContext?.spanId, + resource: resource, + instrumentationScope: instrumentationScopeInfo, + name: name, + kind: kind, + startTime: startTime, + attributes: attributes.attributes, + events: adaptEvents(), + links: adaptLinks(), + status: status, + endTime: endTime ?? clock.now, + hasRemoteParent: hasRemoteParent, + hasEnded: hasEnded, + totalRecordedEvents: getTotalRecordedEvents(), + totalRecordedLinks: totalRecordedLinks, + totalAttributeCount: totalAttributeCount) + } } private func adaptEvents() -> [SpanData.Event] {