Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ def as_etsr(span_data)

private

# Builds span flags based on whether the parent span context is remote.
# This follows the OTLP specification for span flags.
def build_span_flags(parent_span_is_remote, base_flags)
# Extract integer value from TraceFlags object if needed
# Derive the low 8-bit W3C trace flags using the public API.
base_flags_int =
if base_flags.sampled?
1
else
0
end

has_remote_mask = Opentelemetry::Proto::Trace::V1::SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK
is_remote_mask = Opentelemetry::Proto::Trace::V1::SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK

flags = base_flags_int | has_remote_mask
flags |= is_remote_mask if parent_span_is_remote
flags
end

def as_otlp_span(span_data)
Opentelemetry::Proto::Trace::V1::Span.new(
trace_id: span_data.trace_id,
Expand All @@ -96,8 +116,9 @@ def as_otlp_span(span_data)
trace_id: link.span_context.trace_id,
span_id: link.span_context.span_id,
trace_state: link.span_context.tracestate.to_s,
attributes: link.attributes&.map { |k, v| as_otlp_key_value(k, v) }
attributes: link.attributes&.map { |k, v| as_otlp_key_value(k, v) },
# TODO: track dropped_attributes_count in Span#trim_links
flags: build_span_flags(link.span_context.remote?, link.span_context.trace_flags)
)
end,
dropped_links_count: span_data.total_recorded_links - span_data.links&.size.to_i,
Expand All @@ -106,7 +127,8 @@ def as_otlp_span(span_data)
code: as_otlp_status_code(status.code),
message: status.description
)
end
end,
flags: build_span_flags(span_data.parent_span_is_remote, span_data.trace_flags)
)
end

Expand Down
Loading
Loading