aspecto-opentelemetry 0.1.5 → 0.1.6

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: 42bf7169cad40cd8e0fc53c8ef85c766f783330e06ed185c5bb14fcf48ce4d4d
4
- data.tar.gz: aa44a60faa0b08052bbfb60458e53697fe6c11c22f0b64fe7285a4f4cec19635
3
+ metadata.gz: c8d67f2909e02b637a0342f01aaab45d1cbb0b5fae5cc27271b76113fe7af183
4
+ data.tar.gz: 1615052d3f62bb92ac80f91e3bc5a4f5f035ed9f361cefd4e7f459b6b3849d77
5
5
  SHA512:
6
- metadata.gz: 81009b5b65381793e19eee34fb04c579a910952a4ad965b6b7879f69d15ac42477ec274380895a38a49b6fd31a991090a7ac7ab6ca9b1bbc27da524ceae23971
7
- data.tar.gz: 2a1ac520558ef20b6fa09e7cad8c310b0507336ed7f1ab715bfe42ae8ab2df5dd8670e7132810b009e7289298d4572d16370cf45b8199d9d318b8ea47917448d
6
+ metadata.gz: 7133ce0b64d98585b535fac5791f77b84850ed98c561ec820ea5ba9ebd282b04249810eae0af36cb34f7d52dcd0eb54c020432d03a0d0d967884362d49401f94
7
+ data.tar.gz: 8686004ce06bb37f4b4e92623b708d7905e1b9dfdf26220853f0887bfb19293123e58b3a633b251f92f6c91bce788ee5b4bb5879b37ce36176a163488b2c3c36
data/README.md CHANGED
@@ -105,6 +105,8 @@ The only required config options are [`aspecto_auth`](https://app.aspecto.io/app
105
105
  | `log_level` | `OTEL_LOG_LEVEL` | string | `ERROR` | `ERROR` / `WARN` / `INFO`, etc. |
106
106
  | `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 |
107
107
  | `otel_exporter_otlp_traces_endpoint` | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | URL | "https://otelcol.aspecto.io/v1/trace" | Url |
108
+ | `require_config_for_traces` | `ASPECTO_REQUIRE_CONFIG_FOR_TRACES` | boolean | False | When `True`, the SDK will not trace anything until remote sampling configuration arrives (few hundreds ms). Can be used to enforce sampling configuration is always applied, with the cost of losing traces generated during service startup.
109
+ |
108
110
 
109
111
  ## Contributing
110
112
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
4
- require "faraday_middleware"
5
3
  require "rufus/scheduler"
4
+ require "net/http"
5
+ require "json"
6
6
 
7
7
  require_relative "../sampler/rules_sampler"
8
8
  require_relative "../sampler/message_process_sampler"
@@ -17,12 +17,9 @@ module Aspecto
17
17
  @service_name = service_name
18
18
  @env = env
19
19
  @fallback_sampler = fallback_sampler
20
-
21
- aspecto_config_url = ENV.fetch("ASPECTO_CONFIG_HOST", "https://config.aspecto.io")
22
- @http_client = Faraday.new "#{aspecto_config_url}/config/#{aspecto_auth}" do |f|
23
- f.response :json # decode response bodies as JSON
24
- end
25
- @http_client.options.timeout = 10
20
+ aspecto_config_host = ENV.fetch("ASPECTO_CONFIG_HOST", "https://config.aspecto.io")
21
+ @aspecto_config_url = URI("#{aspecto_config_host}/config/#{aspecto_auth}")
22
+ init_http_client
26
23
 
27
24
  @scheduler = Rufus::Scheduler.new
28
25
  @remote_config_poll_frequency = ENV.fetch("ASPECTO_REMOTE_CONFIG_POLL_FREQUENCY", "30s")
@@ -39,19 +36,36 @@ module Aspecto
39
36
 
40
37
  private
41
38
 
39
+ def init_http_client
40
+ write_timeout_supported = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6")
41
+
42
+ @http_client = Net::HTTP.new(@aspecto_config_url.host, @aspecto_config_url.port)
43
+ @http_client.read_timeout = 10
44
+ @http_client.open_timeout = 10
45
+ @http_client.write_timeout = 10 if write_timeout_supported
46
+ @http_client.max_retries = 0
47
+
48
+ # use uri.scheme == 'https' instead
49
+ @http_client.use_ssl = true
50
+ @http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
51
+ end
52
+
42
53
  def update_config # rubocop:disable Metrics/AbcSize
43
54
  ::OpenTelemetry::Common::Utilities.untraced do
44
- response = @http_client.get do |req|
45
- req.headers["If-None-Match"] = @latest_config_etag unless @latest_config_etag.nil?
46
- end
47
- @latest_config_etag = response.headers["etag"]
48
- return if response.status == 304
55
+ request = Net::HTTP::Get.new(@aspecto_config_url.path)
56
+ request["If-None-Match"] = @latest_config_etag unless @latest_config_etag.nil?
57
+ response = @http_client.request(request)
58
+ response_code = response.code.to_i
49
59
 
50
- if response.status >= 400
60
+ return if response_code == 304
61
+
62
+ if response_code >= 400
51
63
  ::OpenTelemetry.logger.error("[Aspecto] error when trying to get remote config. will try again in #{@remote_config_poll_frequency}")
52
64
  return
53
65
  end
54
- handle_new_config response.body if response.status < 300
66
+
67
+ @latest_config_etag = response["etag"]
68
+ handle_new_config JSON.parse(response.body) if response_code < 300
55
69
  end
56
70
  rescue StandardError => e
57
71
  ::OpenTelemetry.logger.error "[Aspecto] updating remote config failed. using previous remote config"
@@ -4,6 +4,8 @@ module Aspecto
4
4
  module OpenTelemetry
5
5
  # Aspecto OpenTelemetry Distro Configurator
6
6
  class Configurator
7
+ TRUTHY_VALUES = %w[1 T t true TRUE True].freeze
8
+
7
9
  def initialize
8
10
  # initialize config options from environment variables.
9
11
  # they can later be overwritten with configurator attribute setters
@@ -14,6 +16,7 @@ module Aspecto
14
16
  self.env = ENV["ASPECTO_ENV"] if ENV["ASPECTO_ENV"]
15
17
  self.sampling_ratio = Float(ENV.fetch("ASPECTO_SAMPLING_RATIO", 1.0))
16
18
  self.otel_exporter_otlp_traces_endpoint = ENV.fetch("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://otelcol.aspecto.io/v1/trace")
19
+ self.require_config_for_traces = TRUTHY_VALUES.include?(ENV["ASPECTO_REQUIRE_CONFIG_FOR_TRACES"]&.strip)
17
20
  end
18
21
 
19
22
  def service_name=(service_name)
@@ -24,7 +27,7 @@ module Aspecto
24
27
  @override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT] = env
25
28
  end
26
29
 
27
- attr_accessor :sampling_ratio, :log_level, :otel_exporter_otlp_traces_endpoint
30
+ attr_accessor :sampling_ratio, :log_level, :otel_exporter_otlp_traces_endpoint, :require_config_for_traces
28
31
  attr_reader :aspecto_auth
29
32
 
30
33
  def aspecto_auth=(aspecto_auth)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aspecto
4
4
  module OpenTelemetry
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
@@ -50,6 +50,11 @@ module Aspecto
50
50
  end
51
51
  end
52
52
 
53
+ if configurator.require_config_for_traces
54
+ ::OpenTelemetry.logger.info "[Aspecto] Require config for traces. Applying ALWAYS_OFF sampler"
55
+ ::OpenTelemetry.tracer_provider.sampler = ::OpenTelemetry::SDK::Trace::Samplers::ALWAYS_OFF
56
+ end
57
+
53
58
  fallback_sampler = ::OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(configurator.sampling_ratio)
54
59
  # TODO: how to properly extract the data from resource?
55
60
  _, service_name = ::OpenTelemetry.tracer_provider.resource.attribute_enumerator.detect { |elem| elem[0] == ::OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspecto-opentelemetry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aspecto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aspecto-opentelemetry-instrumentation-aws_sdk
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.8
27
- - !ruby/object:Gem::Dependency
28
- name: faraday
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.8'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.8'
41
- - !ruby/object:Gem::Dependency
42
- name: faraday_middleware
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.2'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: opentelemetry-exporter-otlp
57
29
  requirement: !ruby/object:Gem::Requirement