Skip to content

Commit

Permalink
Merge branch 'main' into log-record-processor3
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Jan 3, 2024
2 parents 5cf254d + ff9a7d3 commit 3c03cc9
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ jobs:
- opentelemetry-common
- opentelemetry-logs-api
- opentelemetry-metrics-api
- opentelemetry-metrics-sdk
- opentelemetry-registry
- opentelemetry-sdk
- opentelemetry-sdk-experimental
- opentelemetry-semantic_conventions
- opentelemetry-test-helpers
os:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
tools: latest

- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module Encoder # rubocop:disable Metrics/ModuleLength

def encoded_process(resource)
service_name = DEFAULT_SERVICE_NAME
tags = resource&.attribute_enumerator&.select do |key, value|
tags = resource&.attribute_enumerator&.reject do |key, value|
service_name = value if key == 'service.name'
key != 'service.name'
key == 'service.name'
end
tags = encoded_tags(tags)
Thrift::Process.new('serviceName' => service_name, 'tags' => tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def initialize(
def collect(start_time, end_time)
if @aggregation_temporality == :delta
# Set timestamps and 'move' data point values to result.
hdps = @data_points.each_value do |hdp|
hdps = @data_points.values.map! do |hdp|
hdp.start_time_unix_nano = start_time
hdp.time_unix_nano = end_time
hdp
end
@data_points.clear
hdps
Expand Down
3 changes: 2 additions & 1 deletion metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/sum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def initialize(aggregation_temporality: :delta)
def collect(start_time, end_time)
if @aggregation_temporality == :delta
# Set timestamps and 'move' data point values to result.
ndps = @data_points.each_value do |ndp|
ndps = @data_points.values.map! do |ndp|
ndp.start_time_unix_nano = start_time
ndp.time_unix_nano = end_time
ndp
end
@data_points.clear
ndps
Expand Down
37 changes: 21 additions & 16 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
# Release History: opentelemetry-sdk

### v1.3.1 / 2023-11-02

* FIXED: Spec compliance for span attribute limit
* FIXED: BatchSpanProcessor#force_flush: purge inherited spans even on shutdown

### v1.3.0 / 2023-06-08

* BREAKING CHANGE: Remove support for EoL Ruby 2.7
* BREAKING CHANGE: Remove support for EoL Ruby 2.7

* ADDED: Remove support for EoL Ruby 2.7
* FIXED: SDK requires opentelemetry-common 0.19.7
* ADDED: Remove support for EoL Ruby 2.7
* FIXED: SDK requires opentelemetry-common 0.19.7

### v1.2.1 / 2023-05-30

* FIXED: Untraced only works with parent-based sampler
* DOCS: Improve formatting of usage examples in OpenTelemetry SDK rubydocs
* FIXED: Untraced only works with parent-based sampler
* DOCS: Improve formatting of usage examples in OpenTelemetry SDK rubydocs

### v1.2.0 / 2022-09-14

* ADDED: Support OTEL_PROPAGATORS=none
* ADDED: Support OTEL_ATTRIBUTE_{COUNT,VALUE_LENGTH}_LIMIT env vars
* ADDED: Support InstrumentationScope, and update OTLP proto to 0.18.0
* FIXED: SpanLimits setting event attributes length limit
* ADDED: Support OTEL_PROPAGATORS=none
* ADDED: Support OTEL_ATTRIBUTE_{COUNT,VALUE_LENGTH}_LIMIT env vars
* ADDED: Support InstrumentationScope, and update OTLP proto to 0.18.0
* FIXED: SpanLimits setting event attributes length limit

### v1.1.0 / 2022-05-26

* BREAKING CHANGE: This requires upgrading both the SDK and Instrumentation gem in tandem
* BREAKING CHANGE: This requires upgrading both the SDK and Instrumentation gem in tandem


### v1.0.3 / 2022-05-02

* ADDED: Truncate the strings in an array attribute value if length_limit is configured
* FIXED: Update attribute length limit env var name to match spec
* FIXED: Warning about Struct initialization in Ruby 3.2+
* FIXED: Warn on unsupported otlp transport protocols
* FIXED: Only allow certain types of Numeric values as attribute values.
* FIXED: Update attribute length limit env var name to match spec
* FIXED: Warning about Struct initialization in Ruby 3.2+
* FIXED: Warn on unsupported otlp transport protocols
* FIXED: Only allow certain types of Numeric values as attribute values.

### v1.0.2 / 2021-12-01

* FIXED: Default span kind
* FIXED: Use monotonic clock where possible
* FIXED: Default span kind
* FIXED: Use monotonic clock where possible

### v1.0.1 / 2021-10-29

Expand Down
10 changes: 5 additions & 5 deletions sdk/lib/opentelemetry/sdk/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ def valid_value?(value)
end

def valid_attributes?(owner, kind, attrs)
attrs.nil? || attrs.all? do |k, v|
attrs.nil? || attrs.each do |k, v|
if !valid_key?(k)
OpenTelemetry.handle_error(message: "invalid #{kind} attribute key type #{k.class} on span '#{owner}'")
false
return false
elsif !valid_value?(v)
OpenTelemetry.handle_error(message: "invalid #{kind} attribute value type #{v.class} for key '#{k}' on span '#{owner}'")
false
else
true
return false
end
end

true
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def on_finish(span)
# @param [optional Numeric] timeout An optional timeout in seconds.
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
# non-specific failure occurred, TIMEOUT if a timeout occurred.
def force_flush(timeout: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
def force_flush(timeout: nil) # rubocop:disable Metrics/MethodLength
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
snapshot = lock do
reset_on_fork if @keep_running
reset_on_fork(restart_thread: @keep_running)
spans.shift(spans.size)
end
until snapshot.empty?
Expand Down
22 changes: 14 additions & 8 deletions sdk/lib/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def to_span_data
end

# @api private
def initialize(context, parent_context, parent_span, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_scope) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
def initialize(context, parent_context, parent_span, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_scope) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
super(span_context: context)
@mutex = Mutex.new
@name = name
Expand All @@ -297,7 +297,7 @@ def initialize(context, parent_context, parent_span, name, kind, parent_span_id,
@total_recorded_events = 0
@total_recorded_links = links&.size || 0
@total_recorded_attributes = attributes&.size || 0
@attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes.
@attributes = attributes
trim_span_attributes(@attributes)
@events = nil
@links = trim_links(links, span_limits.link_count_limit, span_limits.link_attribute_count_limit)
Expand All @@ -317,7 +317,7 @@ def initialize(context, parent_context, parent_span, name, kind, parent_span_id,
# SpanData.
@monotonic_start_timestamp = monotonic_now
@realtime_start_timestamp = if parent_span.recording?
relative_realtime(parent_span.realtime_start_timestamp, parent_span.monotonic_start_timestamp)
relative_realtime(parent_span.realtime_start_timestamp, parent_span.monotonic_start_timestamp, @monotonic_start_timestamp)
else
realtime_now
end
Expand Down Expand Up @@ -347,8 +347,14 @@ def validated_attributes(attrs)
def trim_span_attributes(attrs)
return if attrs.nil?

excess = attrs.size - @span_limits.attribute_count_limit
excess.times { attrs.shift } if excess.positive?
if attrs.size > @span_limits.attribute_count_limit
n = @span_limits.attribute_count_limit
attrs.delete_if do |_key, _value|
n -= 1
n.negative?
end
end

truncate_attribute_values(attrs, @span_limits.attribute_length_limit)
nil
end
Expand Down Expand Up @@ -413,15 +419,15 @@ def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity,
def relative_timestamp(timestamp)
return time_in_nanoseconds(timestamp) unless timestamp.nil?

relative_realtime(realtime_start_timestamp, monotonic_start_timestamp)
relative_realtime(realtime_start_timestamp, monotonic_start_timestamp, monotonic_now)
end

def time_in_nanoseconds(timestamp)
(timestamp.to_r * 1_000_000_000).to_i
end

def relative_realtime(realtime_base, monotonic_base)
realtime_base + (monotonic_now - monotonic_base)
def relative_realtime(realtime_base, monotonic_base, now)
realtime_base + (now - monotonic_base)
end

def realtime_now
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def internal_start_span(name, kind, attributes, links, start_timestamp, parent_c
if result.recording? && !@stopped
trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT
context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, trace_flags: trace_flags, tracestate: result.tracestate)
attributes = attributes&.merge(result.attributes) || result.attributes
attributes = attributes&.merge(result.attributes) || result.attributes.dup
Span.new(
context,
parent_context,
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/opentelemetry/sdk/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
module OpenTelemetry
module SDK
## Current OpenTelemetry version
VERSION = '1.3.0'
VERSION = '1.3.1'
end
end
17 changes: 9 additions & 8 deletions sdk/test/opentelemetry/sdk/trace/span_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
_(span.attributes).must_equal('foo' => 'bar')
end

it 'trims the oldest attribute' do
it 'trims the newest attribute' do
span.set_attribute('old', 'oldbar')
span.set_attribute('foo', 'bar')
_(span.attributes).must_equal('foo' => 'bar')
_(span.attributes).must_equal('old' => 'oldbar')
end

it 'truncates attribute value length based if configured' do
Expand Down Expand Up @@ -138,10 +138,10 @@
_(span.attributes).must_equal('foo' => 'bar')
end

it 'trims the oldest attributes' do
it 'trims the newest attributes' do
span.add_attributes('old' => 'oldbar')
span.add_attributes('foo' => 'bar', 'bar' => 'baz')
_(span.attributes).must_equal('bar' => 'baz')
_(span.attributes).must_equal('old' => 'oldbar')
end

it 'truncates attribute value length based if configured' do
Expand Down Expand Up @@ -499,22 +499,23 @@
end

it 'trims excess attributes' do
attributes = { 'foo': 'bar', 'other': 'attr' }
attributes = { 'foo' => 'bar', 'other' => 'attr' }
span = Span.new(context, Context.empty, OpenTelemetry::Trace::Span::INVALID, 'name', SpanKind::INTERNAL, nil, span_limits,
[], attributes, nil, Time.now, nil, nil)
_(span.to_span_data.total_recorded_attributes).must_equal(2)
_(span.attributes.length).must_equal(1)
_(span.attributes).must_equal('foo' => 'bar')
end

it 'truncates attributes if configured' do
attributes = { 'foo': 'oldbaroldbaroldbaroldbaroldbaroldbar' }
attributes = { 'foo' => 'oldbaroldbaroldbaroldbaroldbaroldbar' }
span = Span.new(context, Context.empty, OpenTelemetry::Trace::Span::INVALID, 'name', SpanKind::INTERNAL, nil, span_limits,
[], attributes, nil, Time.now, nil, nil)
_(span.attributes[:foo]).must_equal('oldbaroldbaroldbaroldbaroldba...')
_(span.attributes['foo']).must_equal('oldbaroldbaroldbaroldbaroldba...')
end

it 'counts attributes' do
attributes = { 'foo': 'bar', 'other': 'attr' }
attributes = { 'foo' => 'bar', 'other' => 'attr' }
span = Span.new(context, Context.empty, OpenTelemetry::Trace::Span::INVALID, 'name', SpanKind::INTERNAL, nil, span_limits,
[], attributes, nil, Time.now, nil, nil)
_(span.to_span_data.total_recorded_attributes).must_equal(2)
Expand Down
4 changes: 4 additions & 0 deletions sdk_experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History: opentelemetry-sdk-experimental

### v0.3.2 / 2023-11-02

* FIXED: Ruby 3.0 compatibility for generate_r

### v0.3.1 / 2023-09-18

* FIXED: Small perf improvement to generate_r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module OpenTelemetry
module SDK
module Experimental
# Current OpenTelemetry experimental sdk version
VERSION = '0.3.1'
VERSION = '0.3.2'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def decimal(str)
end

def generate_r(trace_id)
x = trace_id.unpack1('Q>', offset: 8) | 0x3
x = trace_id.unpack1('@8Q>') | 0x3
64 - x.bit_length
end
end
Expand Down

0 comments on commit 3c03cc9

Please sign in to comment.