Skip to content

Commit de88853

Browse files
Fixing span marshaling and autoconfig after OTel update
related: gh-81
1 parent ba60ae8 commit de88853

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

spring-cloud-sleuth-otel-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/otel/actuate/OtelOtlpFinishedSpanWriter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
package org.springframework.cloud.sleuth.autoconfig.otel.actuate;
1818

19+
import java.io.ByteArrayOutputStream;
20+
import java.io.IOException;
21+
import java.io.UncheckedIOException;
22+
import java.util.Arrays;
1923
import java.util.List;
2024
import java.util.stream.Collectors;
2125

22-
import io.opentelemetry.exporter.otlp.internal.SpanAdapter;
26+
import io.opentelemetry.exporter.otlp.internal.traces.ResourceSpansMarshaler;
2327
import io.opentelemetry.proto.trace.v1.ResourceSpans;
2428
import io.opentelemetry.sdk.trace.data.SpanData;
2529

@@ -40,7 +44,7 @@ class OtelOtlpFinishedSpanWriter implements FinishedSpanWriter<byte[]> {
4044
public byte[] write(TextOutputFormat format, List<FinishedSpan> spans) {
4145
if (format == TextOutputFormat.CONTENT_TYPE_OTLP_PROTOBUF) {
4246
List<SpanData> spanData = spans.stream().map(OtelFinishedSpan::toOtel).collect(Collectors.toList());
43-
List<ResourceSpans> resourceSpans = SpanAdapter.toProtoResourceSpans(spanData);
47+
List<ResourceSpans> resourceSpans = toProtoResourceSpans(spanData);
4448
if (resourceSpans.isEmpty()) {
4549
return null;
4650
}
@@ -52,4 +56,19 @@ public byte[] write(TextOutputFormat format, List<FinishedSpan> spans) {
5256
return null;
5357
}
5458

59+
private List<ResourceSpans> toProtoResourceSpans(List<SpanData> spanData) {
60+
return Arrays.stream(ResourceSpansMarshaler.create(spanData)).map(this::toResourceSpans)
61+
.collect(Collectors.toList());
62+
}
63+
64+
private ResourceSpans toResourceSpans(ResourceSpansMarshaler resourceSpansMarshaler) {
65+
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
66+
resourceSpansMarshaler.writeBinaryTo(os);
67+
return ResourceSpans.parseFrom(os.toByteArray());
68+
}
69+
catch (IOException e) {
70+
throw new UncheckedIOException(e);
71+
}
72+
}
73+
5574
}

spring-cloud-sleuth-otel-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/otel/actuate/TraceSleuthOtelActuatorAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Supplier<FinishedSpanWriter> sleuthZipkinOtelFinishedSpanWriter() {
5959
}
6060

6161
@Bean
62-
@ConditionalOnClass(name = "io.opentelemetry.exporter.otlp.internal.SpanAdapter")
62+
@ConditionalOnClass(name = "io.opentelemetry.exporter.otlp.internal.traces.ResourceSpansMarshaler")
6363
Supplier<FinishedSpanWriter> sleuthOtlpOtelFinishedSpanWriter() {
6464
return OtelOtlpFinishedSpanWriter::new;
6565
}

0 commit comments

Comments
 (0)