void convertSpan()

in prod/native/libphpbridge/code/OtlpExporter/SpanConverter.h [198:269]


    void convertSpan(elasticapm::php::AutoZval const &span, opentelemetry::proto::trace::v1::Span *out) {
        using namespace opentelemetry::proto::trace::v1;
        using opentelemetry::proto::trace::v1::Status;
        using namespace std::string_view_literals;

        auto context = span.callMethod("getContext"sv);
        out->set_trace_id(context.callMethod("getTraceIdBinary"sv).getStringView());
        out->set_span_id(context.callMethod("getSpanIdBinary"sv).getStringView());

        auto parentSpanContext = span.callMethod("getParentContext"sv);
        out->set_flags(buildFlagsForSpan(context, parentSpanContext));

        auto traceState = context.callMethod("getTraceState"sv);
        if (traceState.isObject()) {
            out->set_trace_state(traceState.callMethod("__toString"sv, {}).getStringView());
        }

        if (parentSpanContext.callMethod("isValid"sv).getBoolean()) {
            out->set_parent_span_id(parentSpanContext.callMethod("getSpanIdBinary"sv).getStringView());
        }

        out->set_name(span.callMethod("getName"sv).getStringView());
        out->set_kind(convertSpanKind(span.callMethod("getKind"sv).getLong()));

        out->set_start_time_unix_nano(span.callMethod("getStartEpochNanos"sv).getLong());
        out->set_end_time_unix_nano(span.callMethod("getEndEpochNanos"sv).getLong());

        {
            auto attributes = span.callMethod("getAttributes"sv);
            out->set_dropped_attributes_count(attributes.callMethod("getDroppedAttributesCount"sv).getLong());
            AttributesConverter::convertAttributes(attributes, out->mutable_attributes());
        }

        {
            auto events = span.callMethod("getEvents"sv);
            for (auto const &event : events) {
                opentelemetry::proto::trace::v1::Span::Event *outEvent = out->add_events();
                outEvent->set_time_unix_nano(event.callMethod("getEpochNanos"sv).getLong());
                outEvent->set_name(event.callMethod("getName"sv).getStringView());

                auto attributes = event.callMethod("getAttributes"sv);
                AttributesConverter::convertAttributes(attributes, outEvent->mutable_attributes());
                outEvent->set_dropped_attributes_count(attributes.callMethod("getDroppedAttributesCount"sv).getLong());
            }
            out->set_dropped_events_count(span.callMethod("getTotalDroppedEvents"sv).getLong());
        }

        auto links = span.callMethod("getLinks"sv);
        for (auto const &link : links) {
            opentelemetry::proto::trace::v1::Span::Link *outLink = out->add_links();
            {
                auto linkSpanContext = link.callMethod("getSpanContext"sv);
                outLink->set_trace_id(linkSpanContext.callMethod("getTraceIdBinary"sv).getStringView());
                outLink->set_span_id(linkSpanContext.callMethod("getSpanIdBinary"sv).getStringView());
                outLink->set_flags(buildFlagsForLink(linkSpanContext));

                if (auto traceState = linkSpanContext.callMethod("getTraceState"sv); traceState.isObject()) {
                    outLink->set_trace_state(traceState.callMethod("__toString"sv).getStringView());
                }
            }
            auto attributes = link.callMethod("getAttributes"sv);
            AttributesConverter::convertAttributes(attributes, outLink->mutable_attributes());
            outLink->set_dropped_attributes_count(attributes.callMethod("getDroppedAttributesCount"sv).getLong());
        }
        out->set_dropped_links_count(span.callMethod("getTotalDroppedLinks"sv).getLong());

        Status *outStatus = out->mutable_status();
        auto status = span.callMethod("getStatus"sv);

        outStatus->set_message(status.callMethod("getDescription"sv).getStringView());
        outStatus->set_code(convertStatusCode(status.callMethod("getCode"sv).getStringView()));
    }