Skip to content

Commit

Permalink
Merge branch 'main' into logs-sdk-log-record
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed May 14, 2024
2 parents 1f9f902 + 5172e84 commit 7dfc712
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/actions/test_gem/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ runs:
# ...but not for appraisals, sadly.
- name: Install Ruby ${{ inputs.ruby }} with dependencies
if: "${{ steps.setup.outputs.appraisals == 'false' }}"
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: "${{ inputs.ruby }}"
working-directory: "${{ steps.setup.outputs.gem_dir }}"
Expand All @@ -69,7 +69,7 @@ runs:
# If we're using appraisals, do it all manually.
- name: Install Ruby ${{ inputs.ruby }} without dependencies
if: "${{ steps.setup.outputs.appraisals == 'true' }}"
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: "${{ inputs.ruby }}"
bundler: "latest"
Expand Down
37 changes: 0 additions & 37 deletions .github/workflows/codeql.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release-hook-on-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-hook-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-perform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-retry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Ruby ${{ env.ruby_version }}
uses: ruby/setup-ruby@v1.165.1
uses: ruby/setup-ruby@v1.176.0
with:
ruby-version: ${{ env.ruby_version }}
- name: Checkout repo
Expand Down
22 changes: 22 additions & 0 deletions api/lib/opentelemetry/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ def add_attributes(attributes)
self
end

# Add a link to a {Span}.
#
# Adding links at span creation using the `links` option is preferred
# to calling add_link later, because head sampling decisions can only
# consider information present during span creation.
#
# Example:
#
# span.add_link(OpenTelemetry::Trace::Link.new(span_to_link_from.context))
#
# Note that the OpenTelemetry project
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
# documents} certain "standard attributes" that have prescribed semantic
# meanings.
#
# @param [OpenTelemetry::Trace::Link] the link object to add on the {Span}.
#
# @return [self] returns itself
def add_link(link)
self
end

# Add an event to a {Span}.
#
# Example:
Expand Down
6 changes: 6 additions & 0 deletions api/test/opentelemetry/trace/span_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
end
end

describe '#add_link' do
it 'returns self' do
_(span.add_link(OpenTelemetry::Trace::Link.new(span_context))).must_equal(span)
end
end

describe '#add_event' do
it 'returns self' do
_(span.add_event('event-name')).must_equal(span)
Expand Down
2 changes: 2 additions & 0 deletions common/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bundler/OrderedGems:
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ExplicitBlockArgument:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
Expand Down
4 changes: 4 additions & 0 deletions common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History: opentelemetry-common

### v0.21.0 / 2024-05-08

* ADDED: Untraced method updated to support both block and non block structured calls

### v0.20.1 / 2024-02-06

* FIXED: Patch the issue for frozen string on ruby < 3.0 with string interpolation
Expand Down
17 changes: 13 additions & 4 deletions common/lib/opentelemetry/common/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'uri'

module OpenTelemetry
module Common
# Utilities contains common helpers.
Expand Down Expand Up @@ -86,10 +88,17 @@ def truncate_attribute_value(value, limit)
end
end

# Disables tracing within the provided block.
def untraced
Context.with_value(UNTRACED_KEY, true) do |ctx, _|
yield ctx
# Disables tracing within the provided block
# If no block is provided instead returns an
# untraced ctx.
#
# @param [optional Context] context Accepts an explicit context, defaults to current
def untraced(context = Context.current)
context = context.set_value(UNTRACED_KEY, true)
if block_given?
Context.with_current(context) { |ctx| yield ctx }
else
context
end
end

Expand Down
2 changes: 1 addition & 1 deletion common/lib/opentelemetry/common/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

module OpenTelemetry
module Common
VERSION = '0.20.1'
VERSION = '0.21.0'
end
end
7 changes: 7 additions & 0 deletions common/test/opentelemetry/common/utilities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def shutdown(timeout: nil); end
common_utils.untraced {}
assert_equal(false, common_utils.untraced?)
end

it 'supports non block format' do
token = OpenTelemetry::Context.attach(common_utils.untraced)
assert_equal(true, common_utils.untraced?)
OpenTelemetry::Context.detach(token)
assert_equal(false, common_utils.untraced?)
end
end

describe '#utf8_encode' do
Expand Down
6 changes: 6 additions & 0 deletions exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/
end

def encode(span_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.encode(
Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.new(
resource_spans: span_data
Expand Down Expand Up @@ -298,6 +299,11 @@ def encode(span_data) # rubocop:disable Metrics/MethodLength, Metrics/Cyclomatic
rescue StandardError => e
OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#encode')
nil
ensure
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
duration_ms = 1000.0 * (stop - start)
@metrics_reporter.record_value('otel.otlp_exporter.encode_duration',
value: duration_ms)
end

def as_otlp_span(span_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down
11 changes: 11 additions & 0 deletions exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@
_(result).must_equal(SUCCESS)
end

it 'records metrics' do
metrics_reporter = Minitest::Mock.new
exporter = OpenTelemetry::Exporter::OTLP::Exporter.new(metrics_reporter: metrics_reporter)
stub_request(:post, 'http://localhost:4318/v1/traces').to_timeout.then.to_return(status: 200)
metrics_reporter.expect(:record_value, nil) { |m, _, _| m == 'otel.otlp_exporter.encode_duration' }
metrics_reporter.expect(:record_value, nil) { |m, _, _| m == 'otel.otlp_exporter.message.uncompressed_size' }
metrics_reporter.expect(:record_value, nil) { |m, _, _| m == 'otel.otlp_exporter.message.compressed_size' }
metrics_reporter.expect(:add_to_counter, nil) { |m, _, _| m == 'otel.otlp_exporter.failure' }
exporter.export([OpenTelemetry::TestHelpers.create_span_data])
end

it 'retries on timeout' do
stub_request(:post, 'http://localhost:4318/v1/traces').to_timeout.then.to_return(status: 200)
span_data = OpenTelemetry::TestHelpers.create_span_data
Expand Down
1 change: 1 addition & 0 deletions logs_api/lib/opentelemetry/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_relative 'logs/log_record'
require_relative 'logs/logger'
require_relative 'logs/logger_provider'
require_relative 'logs/severity_number'

module OpenTelemetry
# The Logs API records a timestamped record with metadata.
Expand Down
37 changes: 37 additions & 0 deletions logs_api/lib/opentelemetry/logs/severity_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
module Logs
class SeverityNumber
SEVERITY_NUMBER_UNSPECIFIED = 0
SEVERITY_NUMBER_TRACE = 1
SEVERITY_NUMBER_TRACE2 = 2
SEVERITY_NUMBER_TRACE3 = 3
SEVERITY_NUMBER_TRACE4 = 4
SEVERITY_NUMBER_DEBUG = 5
SEVERITY_NUMBER_DEBUG2 = 7
SEVERITY_NUMBER_DEBUG3 = 6
SEVERITY_NUMBER_DEBUG4 = 8
SEVERITY_NUMBER_INFO = 9
SEVERITY_NUMBER_INFO2 = 10
SEVERITY_NUMBER_INFO3 = 11
SEVERITY_NUMBER_INFO4 = 12
SEVERITY_NUMBER_WARN = 13
SEVERITY_NUMBER_WARN2 = 14
SEVERITY_NUMBER_WARN3 = 15
SEVERITY_NUMBER_WARN4 = 16
SEVERITY_NUMBER_ERROR = 17
SEVERITY_NUMBER_ERROR2 = 18
SEVERITY_NUMBER_ERROR3 = 19
SEVERITY_NUMBER_ERROR4 = 20
SEVERITY_NUMBER_FATAL = 21
SEVERITY_NUMBER_FATAL2 = 22
SEVERITY_NUMBER_FATAL3 = 23
SEVERITY_NUMBER_FATAL4 = 24
end
end
end
2 changes: 1 addition & 1 deletion metrics_api/lib/opentelemetry/metrics/meter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meter
UP_DOWN_COUNTER = Instrument::UpDownCounter.new
OBSERVABLE_UP_DOWN_COUNTER = Instrument::ObservableUpDownCounter.new

NAME_REGEX = /^[a-zA-Z][-.\w]{0,62}$/
NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/

private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)

Expand Down
36 changes: 34 additions & 2 deletions sdk/lib/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ def add_attributes(attributes)
self
end

# Add a link to a {Span}.
#
# Adding links at span creation using the `links` option is preferred
# to calling add_link later, because head sampling decisions can only
# consider information present during span creation.
#
# Example:
#
# span.add_link(OpenTelemetry::Trace::Link.new(span_to_link_from.context))
#
# Note that the OpenTelemetry project
# {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
# documents} certain "standard attributes" that have prescribed semantic
# meanings.
#
# @param [OpenTelemetry::Trace::Link] the link object to add on the {Span}.
#
# @return [self] returns itself
def add_link(link)
@mutex.synchronize do
if @ended
OpenTelemetry.logger.warn('Calling add_link on an ended Span.')
else
@links ||= []
@links = trim_links(@links << link, @span_limits.link_count_limit, @span_limits.link_attribute_count_limit)
@total_recorded_links += 1
end
end
self
end

# Add an Event to a {Span}.
#
# Example:
Expand Down Expand Up @@ -242,6 +273,7 @@ def finish(end_timestamp: nil)
@end_timestamp = relative_timestamp(end_timestamp)
@attributes = validated_attributes(@attributes).freeze
@events.freeze
@links.freeze
@ended = true
end
@span_processors.each { |processor| processor.on_finish(self) }
Expand Down Expand Up @@ -373,7 +405,7 @@ def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:di

if links.size <= link_count_limit &&
links.all? { |link| link.span_context.valid? && link.attributes.size <= link_attribute_count_limit && Internal.valid_attributes?(name, 'link', link.attributes) }
return links.frozen? ? links : links.clone.freeze
return links
end

# Slow path: trim attributes for each Link.
Expand All @@ -386,7 +418,7 @@ def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:di
excess = attrs.size - link_attribute_count_limit
excess.times { attrs.shift } if excess.positive?
OpenTelemetry::Trace::Link.new(link.span_context, attrs)
end.freeze
end
end

def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down
2 changes: 0 additions & 2 deletions sdk/lib/opentelemetry/sdk/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kin

def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
with_parent ||= Context.current
return super(name, with_parent: with_parent, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind) if Common::Utilities.untraced?(with_parent)

name ||= 'empty'
kind ||= :internal

Expand Down
Loading

0 comments on commit 7dfc712

Please sign in to comment.