forked from open-telemetry/opentelemetry-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat add manticore instrumentation (#3)
* initial code complete * chore: fix tests for sidekiq to support inline lua changes (open-telemetry#1011) * chore: fix tests for sidekiq to support inline lua changes to redis calls * chore: add additional sidekiq appraisal * feat: add dalli obfuscation for db_statement (open-telemetry#1013) * feat: add dalli obfuscation for db_statement * chore: linting * Link to website spec pages (open-telemetry#1018) Co-authored-by: Matthew Wear <matthew.wear@gmail.com> * Feat: Add custom getters to common (open-telemetry#1006) Co-authored-by: Matthew Wear <matthew.wear@gmail.com> Co-authored-by: Eric Mustin <eric.mustin@shopify.com> Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com> Co-authored-by: Matthew Wear <matthew.wear@gmail.com> Co-authored-by: Robert <robertlaurin@users.noreply.github.com>
- Loading branch information
1 parent
eab3631
commit b8eaddb
Showing
34 changed files
with
1,045 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require_relative './propagation/rack_env_getter' | ||
require_relative './propagation/symbol_key_getter' | ||
|
||
module OpenTelemetry | ||
module Common | ||
# Propagation contains common helpers for context propagation. | ||
module Propagation | ||
extend self | ||
|
||
RACK_ENV_GETTER = RackEnvGetter.new | ||
SYMBOL_KEY_GETTER = SymbolKeyGetter.new | ||
private_constant :RACK_ENV_GETTER, :SYMBOL_KEY_GETTER | ||
|
||
# Returns a {RackEnvGetter} instance suitable for reading values from a | ||
# Rack environment. | ||
def rack_env_getter | ||
RACK_ENV_GETTER | ||
end | ||
|
||
# Returns a {SymbolKeyGetter} instance for reading values from a | ||
# symbol keyed hash. | ||
def symbol_key_getter | ||
SYMBOL_KEY_GETTER | ||
end | ||
end | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
common/lib/opentelemetry/common/propagation/rack_env_getter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Common | ||
module Propagation | ||
# The RackEnvGetter class provides a common methods for reading | ||
# keys from a rack environment. It abstracts away the rack-normalization | ||
# process so that keys can be looked up without having to transform them | ||
# first. With this class you can get +traceparent+ instead of | ||
# +HTTP_TRACEPARENT+ | ||
class RackEnvGetter | ||
# Converts key into a rack-normalized key and reads it from the carrier. | ||
# Useful for extract operations. | ||
def get(carrier, key) | ||
carrier[to_rack_key(key)] || carrier[key] | ||
end | ||
|
||
# Reads all keys from a carrier and converts them from the rack-normalized | ||
# form to the original. The resulting keys will be lowercase and | ||
# underscores will be replaced with dashes. | ||
def keys(carrier) | ||
carrier.keys.map(&method(:from_rack_key)) | ||
end | ||
|
||
private | ||
|
||
def to_rack_key(key) | ||
ret = 'HTTP_' + key | ||
ret.tr!('-', '_') | ||
ret.upcase! | ||
ret | ||
end | ||
|
||
def from_rack_key(key) | ||
start = key.start_with?('HTTP_') ? 5 : 0 | ||
ret = key[start..-1] | ||
ret.tr!('_', '-') | ||
ret.downcase! | ||
ret | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
common/lib/opentelemetry/common/propagation/symbol_key_getter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Common | ||
module Propagation | ||
# The SymbolKeyGetter class provides a common method for reading | ||
# symbol keys from a hash. | ||
class SymbolKeyGetter | ||
# Converts key into a symbol and reads it from the carrier. | ||
# Useful for extract operations. | ||
def get(carrier, key) | ||
carrier[key.to_sym] | ||
end | ||
|
||
# Reads all keys from a carrier | ||
def keys(carrier) | ||
carrier.keys.map(&:to_s) | ||
end | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
common/test/opentelemetry/common/propagation/rack_env_getter_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::Common::Propagation::RackEnvGetter do | ||
let(:getter) do | ||
OpenTelemetry::Context::Propagation::RackEnvGetter.new | ||
end | ||
|
||
let(:carrier) do | ||
{ | ||
'HTTP_TRACEPARENT' => 'tp', | ||
'HTTP_TRACESTATE' => 'ts', | ||
'HTTP_X_SOURCE_ID' => '123', | ||
'rack.hijack?' => true | ||
} | ||
end | ||
|
||
describe '#get' do | ||
it 'reads key from carrier' do | ||
_(getter.get(carrier, 'traceparent')).must_equal('tp') | ||
_(getter.get(carrier, 'tracestate')).must_equal('ts') | ||
_(getter.get(carrier, 'x-source-id')).must_equal('123') | ||
_(getter.get(carrier, 'rack.hijack?')).must_equal(true) | ||
end | ||
|
||
it 'returns nil for non-existent key' do | ||
_(getter.get(carrier, 'not-here')).must_be_nil | ||
end | ||
end | ||
|
||
describe '#keys' do | ||
it 'returns carrier keys' do | ||
_(getter.keys(carrier)).must_equal(%w[traceparent tracestate x-source-id rack.hijack?]) | ||
end | ||
|
||
it 'returns empty array for empty carrier' do | ||
_(getter.keys({})).must_equal([]) | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
common/test/opentelemetry/common/propagation/symbol_key_getter_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::Common::Propagation::SymbolKeyGetter do | ||
let(:symbol_key_getter) { OpenTelemetry::Common::Propagation::SymbolKeyGetter.new } | ||
let(:carrier) { { foo: 'bar' } } | ||
|
||
describe '#get' do | ||
it 'retrieves the value' do | ||
_(symbol_key_getter.get(carrier, 'foo')).must_equal('bar') | ||
end | ||
end | ||
|
||
describe '#keys' do | ||
it 'returns all the keys as strings' do | ||
_(symbol_key_getter.keys(carrier)).must_equal(['foo']) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
inherit_from: ../.rubocop-examples.yml | ||
|
||
Naming/FileName: | ||
Exclude: | ||
- "lib/opentelemetry-instrumentation-manticore.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--no-private | ||
--title=OpenTelemetry Manticore Instrumentation | ||
--markup=markdown | ||
--main=README.md | ||
./lib/opentelemetry/instrumentation/**/*.rb | ||
./lib/opentelemetry/instrumentation.rb | ||
- | ||
README.md | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Release History: opentelemetry-instrumentation-manticore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
gem 'opentelemetry-api', path: '../../api' | ||
gem 'opentelemetry-instrumentation-base', path: '../base' | ||
|
||
group :test do | ||
gem 'opentelemetry-common', path: '../../common' | ||
gem 'opentelemetry-sdk', path: '../../sdk' | ||
end |
Oops, something went wrong.