Skip to content

Commit

Permalink
move measurement inside encode
Browse files Browse the repository at this point in the history
  • Loading branch information
plantfansam committed Apr 15, 2024
1 parent 6ad8851 commit 21d7f7f
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def export(span_data, timeout: nil)
return FAILURE if @shutdown

send_bytes(
measure_encode_duration { encode(span_data) },
encode(span_data),
timeout: timeout)
end

Expand Down Expand Up @@ -285,30 +285,32 @@ def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/
end

def encode(span_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.encode(
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.new(
resource_spans: span_data
.group_by(&:resource)
.map do |resource, span_datas|
Opentelemetry::Proto::Trace::V1::ResourceSpans.new(
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
),
scope_spans: span_datas
.group_by(&:instrumentation_scope)
.map do |il, sds|
Opentelemetry::Proto::Trace::V1::ScopeSpans.new(
scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
name: il.name,
version: il.version
),
spans: sds.map { |sd| as_otlp_span(sd) }
)
end
)
end
measure_encode_duration do
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.encode(
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.new(
resource_spans: span_data
.group_by(&:resource)
.map do |resource, span_datas|
Opentelemetry::Proto::Trace::V1::ResourceSpans.new(
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
),
scope_spans: span_datas
.group_by(&:instrumentation_scope)
.map do |il, sds|
Opentelemetry::Proto::Trace::V1::ScopeSpans.new(
scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
name: il.name,
version: il.version
),
spans: sds.map { |sd| as_otlp_span(sd) }
)
end
)
end
)
)
)
end
rescue StandardError => e
OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#encode')
nil
Expand Down

0 comments on commit 21d7f7f

Please sign in to comment.