aspecto-opentelemetry 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2bcc099a425ea9d9d4ea5279fcdde5fd1c72ee7a747cac0db749ec4946e6400
4
- data.tar.gz: 4045a1f967fc690eb67d057311f8543924abb14a223fd6484135e3831bc1fa11
3
+ metadata.gz: dd25c9da7c25d1c4c7e7a389189e7f0369dc7b97120425eda7cf49d9fb344b42
4
+ data.tar.gz: '075783f49804d1e01c16b6b80d1c37ed3b0d1de4c05b6ed4f2cd19007c28ccfc'
5
5
  SHA512:
6
- metadata.gz: 5abe512f0a006febca0d20dab3dc2600539ef5af63429e3f05e715278e2760f611cc85908176a08e84a5570a045d02fd6baba260a8b769b691e9ad13f8d29abd
7
- data.tar.gz: f37300481a7a2994eb99600ed22fd122abaae7afe2569f36beb342f79204320b8726125fdb226adf1114169b178f6b7f43ff93c482c3d8b682681c9503d4579a
6
+ metadata.gz: eb1b4410ae3dfa99e61592663cc1f4dff627908632f784fc39938b72a698a9f220e2ce88feb636402ae7a1c791b3395ad7dd5a376daa240ee0398f62961a25a2
7
+ data.tar.gz: 67606263a5e1dc5ecbf8375bd511fd97e9728dd8fd6fa259d746641abb8a488b8e88d81a0b72416a3aee8184c94f30f61e2600bda267cfba6d8a16d814b1d82a
data/README.md CHANGED
@@ -65,17 +65,12 @@ end
65
65
 
66
66
  | Option Name | Environment Variable | Type | Default | Description |
67
67
  | -------------- | ---------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
68
- | aspecto_auth | ASPECTO_AUTH | UUID string | - | Aspecto's [API key for authentication](https://app.aspecto.io/app/integration/api-key) |
69
- | service_name | OTEL_SERVICE_NAME | string | - | name of the service which is sending telemetry |
70
- | env | ASPECTO_ENV | string | extracted from rails or sinatra if used | deployment environment: `"production"` / `"staging"` / `"development"`, etc. |
71
- | log_level | OTEL_LOG_LEVEL | string | 'ERROR' | `"ERROR"` / `"WARN"` / `"INFO"`, etc. |
72
- | sampling_ratio | ASPECTO_SAMPLING_RATIO | float | 1.0 | How many of the traces starting in this service should be sampled. set to number in range [0.0, 1.0] where 0.0 is no sampling, and 1.0 is sample all |
68
+ | `aspecto_auth` | `ASPECTO_AUTH` | UUID string | - | Aspecto's [API key for authentication](https://app.aspecto.io/app/integration/api-key) |
69
+ | `service_name` | `OTEL_SERVICE_NAME` | string | - | name of the service which is sending telemetry |
70
+ | `env` | `ASPECTO_ENV` | string | extracted from rails or sinatra if used | deployment environment: `production` / `staging` / `development`, etc. |
71
+ | `log_level` | `OTEL_LOG_LEVEL` | string | `ERROR` | `ERROR` / `WARN` / `INFO`, etc. |
72
+ | `sampling_ratio` | `ASPECTO_SAMPLING_RATIO` | float | 1.0 | How many of the traces starting in this service should be sampled. set to number in range [0.0, 1.0] where 0.0 is no sampling, and 1.0 is sample all |
73
73
 
74
- ## Development
75
-
76
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
-
78
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
74
 
80
75
  ## Contributing
81
76
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+
6
+ module Aspecto
7
+ # Aspecto's OpenTelemetry distribution
8
+ module OpenTelemetry
9
+ def self.fetch_config(aspecto_auth)
10
+ aspecto_config_url = ENV["ASPECTO_CONFIG_HOST"] || "https://config.aspecto.io"
11
+
12
+ conn = Faraday.new "#{aspecto_config_url}/config/#{aspecto_auth}" do |f|
13
+ f.response :json # decode response bodies as JSON
14
+ end
15
+
16
+ ::OpenTelemetry::Common::Utilities.untraced do
17
+ response = conn.get
18
+ response.body
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./utils"
4
+
5
+ module Aspecto
6
+ # Aspecto OpenTelemetry Distro
7
+ module OpenTelemetry
8
+ module Sampler
9
+ # Aspecto's sampling rule condition
10
+ class Condition
11
+ def initialize(condition_config)
12
+ @comparison = condition_config["comparison"]&.to_sym
13
+ @value = condition_config["value"]
14
+ @from = condition_config["from"]&.to_sym
15
+ @key = condition_config["key"]
16
+ end
17
+
18
+ def satisfied?(attributes, span_name)
19
+ case @from
20
+ when :attribute
21
+ Sampler.meets_operator?(@comparison, @value, attributes[@key]&.to_s)
22
+ when :operation
23
+ Sampler.meets_operator?(@comparison, @value, span_name)
24
+ else
25
+ # Other "from" are not implemented for now
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./sampling_rule"
4
+ require_relative "./utils"
5
+
6
+ module Aspecto
7
+ # Aspecto OpenTelemetry Distro
8
+ module OpenTelemetry
9
+ module Sampler
10
+ # OpenTelemetry sampler which implements the remote rules logic with fallback to service sampler
11
+ class RulesSampler
12
+ def initialize(config, fallback_sampler, service_name, env)
13
+ @rules = config
14
+ .select { |rule| Sampler.meets_operator?(rule["packageName"]["comparison"].to_sym, rule["packageName"]["value"], service_name) }
15
+ .select { |rule| Sampler.meets_operator?(rule["env"]["comparison"].to_sym, rule["env"]["value"], env) }
16
+ .map { |rule_config| SamplingRule.new rule_config }
17
+ @fallback_sampler = fallback_sampler
18
+ end
19
+
20
+ def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
21
+ matching_rule = @rules.find { |rule| rule.satisfied?(attributes, name) }
22
+ delegate_sampler = matching_rule ? matching_rule.sampler : @fallback_sampler
23
+ delegate_sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
24
+ end
25
+
26
+ def description
27
+ "RulesSampler {#{rules.length} rules}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentelemetry/sdk"
4
+ require_relative "./condition"
5
+
6
+ module Aspecto
7
+ # Aspecto OpenTelemetry Distro
8
+ module OpenTelemetry
9
+ module Sampler
10
+ # Single rule for sampling
11
+ class SamplingRule
12
+ def initialize(rule_config)
13
+ @id = rule_config["_id"]
14
+ @sampler = ::OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(rule_config["samplingRate"])
15
+ @conditions = rule_config["conditions"].map { |condition_config| Condition.new condition_config }
16
+ end
17
+
18
+ attr_reader :sampler
19
+
20
+ def satisfied?(attributes, span_name)
21
+ @conditions.all? { |condition| condition.satisfied?(attributes, span_name) }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aspecto
4
+ # Aspecto OpenTelemetry Distro
5
+ module OpenTelemetry
6
+ # Sampling logic for aspecto otel distribution
7
+ module Sampler
8
+ extend self
9
+
10
+ def meets_operator?(operator, expected, actual) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
11
+ expected_lower = expected&.downcase
12
+ actual_lower = actual&.downcase
13
+ case operator
14
+ when :eq
15
+ expected_lower == actual_lower
16
+ when :ne
17
+ expected_lower != actual_lower
18
+ when :starts_with
19
+ actual_lower.start_with?(expected_lower)
20
+ when :ends_with
21
+ actual_lower.end_with?(expected_lower)
22
+ when :contains
23
+ actual_lower.include?(expected_lower)
24
+ when :not_contains
25
+ !actual_lower.include?(expected_lower)
26
+ when :matches
27
+ Regexp.new(expected_lower).match(actual_lower)
28
+ when :defined
29
+ !actual.nil?
30
+ when :undefined
31
+ actual.nil?
32
+ when :any
33
+ true
34
+ else
35
+ false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aspecto
4
4
  module OpenTelemetry
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -4,6 +4,9 @@ require_relative "opentelemetry/version"
4
4
  require_relative "opentelemetry/configurator"
5
5
  require_relative "opentelemetry/resource/detectors/aspecto"
6
6
  require_relative "opentelemetry/resource/detectors/deployment"
7
+ require_relative "opentelemetry/remote_config"
8
+ require_relative "opentelemetry/sampler/rules_sampler"
9
+
7
10
  require "opentelemetry/sdk"
8
11
  require "opentelemetry/exporter/otlp"
9
12
  require "opentelemetry/instrumentation/all"
@@ -37,9 +40,19 @@ module Aspecto
37
40
  })
38
41
  )
39
42
  )
43
+
44
+ at_exit do
45
+ ::OpenTelemetry.tracer_provider.shutdown
46
+ end
40
47
  end
41
48
 
42
- ::OpenTelemetry.tracer_provider.sampler = ::OpenTelemetry::SDK::Trace::Samplers.parent_based(root: ::OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(configurator.sampling_ratio))
49
+ fallback_sampler = ::OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(configurator.sampling_ratio)
50
+ remote_config = fetch_config configurator.aspecto_auth
51
+ # TODO: how to properly extract the data from resource?
52
+ _, service_name = ::OpenTelemetry.tracer_provider.resource.attribute_enumerator.detect { |elem| elem[0] == ::OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME }
53
+ _, env = ::OpenTelemetry.tracer_provider.resource.attribute_enumerator.detect { |elem| elem[0] == ::OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT }
54
+ rules_sampler = Sampler::RulesSampler.new remote_config["samplingRules"], fallback_sampler, service_name, env
55
+ ::OpenTelemetry.tracer_provider.sampler = ::OpenTelemetry::SDK::Trace::Samplers.parent_based(root: rules_sampler)
43
56
  rescue StandardError => e
44
57
  warn "Failed to initialize Aspecto tracing."
45
58
  warn e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspecto-opentelemetry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aspecto
@@ -10,20 +10,48 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: aspecto-opentelemetry-instrumentation-aws_sdk
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
45
  - - '='
18
46
  - !ruby/object:Gem::Version
19
- version: 0.1.3
47
+ version: 0.1.4
20
48
  type: :runtime
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
52
  - - '='
25
53
  - !ruby/object:Gem::Version
26
- version: 0.1.3
54
+ version: 0.1.4
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: opentelemetry-exporter-otlp
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -124,8 +152,13 @@ files:
124
152
  - lib/aspecto/auto_instrument.rb
125
153
  - lib/aspecto/opentelemetry.rb
126
154
  - lib/aspecto/opentelemetry/configurator.rb
155
+ - lib/aspecto/opentelemetry/remote_config.rb
127
156
  - lib/aspecto/opentelemetry/resource/detectors/aspecto.rb
128
157
  - lib/aspecto/opentelemetry/resource/detectors/deployment.rb
158
+ - lib/aspecto/opentelemetry/sampler/condition.rb
159
+ - lib/aspecto/opentelemetry/sampler/rules_sampler.rb
160
+ - lib/aspecto/opentelemetry/sampler/sampling_rule.rb
161
+ - lib/aspecto/opentelemetry/sampler/utils.rb
129
162
  - lib/aspecto/opentelemetry/version.rb
130
163
  homepage: https://docs.aspecto.io/
131
164
  licenses: