private void serializeOtel()

in apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java [1081:1149]


        private void serializeOtel(AbstractSpanImpl<?> span, List<IdImpl> profilingStackTraceIds, @Nullable BodyCaptureImpl httpRequestBody) {
            OTelSpanKind kind = span.getOtelKind();
            Map<String, Object> attributes = span.getOtelAttributes();

            boolean hasRequestBody = httpRequestBody != null && httpRequestBody.hasContent() && webConfiguration.isCaptureClientRequestBodyAsLabel();
            boolean hasAttributes = !attributes.isEmpty() || !profilingStackTraceIds.isEmpty() || hasRequestBody;
            boolean hasKind = kind != null;
            if (hasKind || hasAttributes) {
                writeFieldName("otel");
                jw.writeByte(OBJECT_START);

                if (hasKind) {
                    writeFieldName("span_kind");
                    writeStringValue(kind.name());
                }

                if (hasAttributes) {
                    if (hasKind) {
                        jw.writeByte(COMMA);
                    }
                    writeFieldName("attributes");
                    jw.writeByte(OBJECT_START);
                    boolean isFirstAttrib = true;
                    for (Map.Entry<String, Object> entry : attributes.entrySet()) {
                        if (!isFirstAttrib) {
                            jw.writeByte(COMMA);
                        }
                        isFirstAttrib = false;

                        writeFieldName(entry.getKey());
                        Object o = entry.getValue();
                        if (o instanceof Number) {
                            serializeNumber((Number) o, jw);
                        } else if (o instanceof String) {
                            writeStringValue((String) o);
                        } else if (o instanceof Boolean) {
                            BoolConverter.serialize((Boolean) o, jw);
                        }
                    }
                    if (!profilingStackTraceIds.isEmpty()) {
                        if (!isFirstAttrib) {
                            jw.writeByte(COMMA);
                        }
                        writeFieldName("elastic.profiler_stack_trace_ids");
                        jw.writeByte(ARRAY_START);
                        for (int i = 0; i < profilingStackTraceIds.size(); i++) {
                            if (i != 0) {
                                jw.writeByte(COMMA);
                            }
                            jw.writeByte(QUOTE);
                            profilingStackTraceIds.get(i).writeAsBase64UrlSafe(jw);
                            jw.writeByte(QUOTE);
                        }
                        jw.writeByte(ARRAY_END);
                    }
                    if (hasRequestBody) {
                        if (!isFirstAttrib) {
                            jw.writeByte(COMMA);
                        }
                        writeFieldName("http.request.body.content");
                        writeRequestBodyAsString(jw, httpRequestBody);
                    }
                    jw.writeByte(OBJECT_END);
                }

                jw.writeByte(OBJECT_END);
                jw.writeByte(COMMA);
            }
        }