func encode()

in Sources/OtlpExporter/OtlpSLSSpanExporter.swift [226:284]


    func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        
        try container.encode(name, forKey: .name)
        try container.encode(traceId, forKey: .traceID)
        try container.encode(spanId, forKey: .spanID)
        try container.encode(spanKind, forKey: .kind)
        
        var traceFlagsContainer = container.nestedContainer(keyedBy: TraceFlagsCodingKeys.self, forKey: .traceFlags)
        try traceFlagsContainer.encode(traceFlags.sampled, forKey: .sampled)
        
//        var traceStateContainer = container.nestedContainer(keyedBy: TraceStateCodingKeys.self, forKey: .traceState)
//        var traceStateEntriesContainer = traceStateContainer.nestedUnkeyedContainer(forKey: .entries)
//        
//        try traceState.entries.forEach { entry in
//            var traceStateEntryContainer = traceStateEntriesContainer.nestedContainer(keyedBy: TraceStateEntryCodingKeys.self)
//            
//            try traceStateEntryContainer.encode(entry.key, forKey: .key)
//            try traceStateEntryContainer.encode(entry.value, forKey: .value)
//        }
        
        try container.encodeIfPresent(parentSpanId, forKey: .parentSpanID)
        try container.encode(start, forKey: .start)
        try container.encode(end, forKey: .end)
        try container.encode(duration, forKey: .duration)
        
        try container.encode(host, forKey: .host)
        try container.encode(service, forKey: .service)
        try container.encode(statusCode, forKey: .statusCode)
        try container.encode(statusMessage, forKey: .statusMessage)
        
        var attributesContainer = container.nestedContainer(keyedBy: AttributesCodingKeys.self, forKey: .attribute)
        
        try attributes.forEach { attribute in
            if let attributeValueCodingKey = AttributesCodingKeys(stringValue: attribute.key) {
                try attributesContainer.encode(attribute.value.description, forKey: attributeValueCodingKey)
            } else {
                // this should never happen
                let encodingContext = EncodingError.Context(codingPath: attributesContainer.codingPath,
                                                            debugDescription: "Failed to create coding key")
                
                throw EncodingError.invalidValue(attribute, encodingContext)
            }
        }
        
        var resourceContainer = container.nestedContainer(keyedBy: AttributesCodingKeys.self, forKey: .resource)
        try resource.forEach { attribute in
            if let attributeValueCodingKey = AttributesCodingKeys(stringValue: attribute.key) {
                try resourceContainer.encode(attribute.value.description, forKey: attributeValueCodingKey)
            } else {
                // this should never happen
                let encodingContext = EncodingError.Context(codingPath: resourceContainer.codingPath,
                                                            debugDescription: "Failed to create resouce coding key")
                throw EncodingError.invalidValue(attribute, encodingContext)
            }
        }
        
        
    }