diff --git a/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift b/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift index 8b3a04c4..1d244198 100644 --- a/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift +++ b/Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift @@ -192,26 +192,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] {