flare 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcfa9283973a11f13fd17397781c76cc03d3e39c9bd08a92025417397eb74eb9
4
- data.tar.gz: 30e2f84a92f9689aabdd64b7c6839598dc0c3c2bb1dd32a31e2ab9b3a6f5f85a
3
+ metadata.gz: 1adc85107fcbe273da78049b6882bda0f234913b743b5c67988b8b90f53261ae
4
+ data.tar.gz: c46bca41c454100e57ea005ad2a83af2bb7ada763ba48a9cb2ffb19e0811198f
5
5
  SHA512:
6
- metadata.gz: 581e6e9ed512b82ac086ab76644ff0d618408649a110ef3b623a3bf4a1648e3695dfcedcefad01bd54b7a11687a1c5ed154ed01e74f2cf14c27fa400bf97f73a
7
- data.tar.gz: 4a407b09a229f512d6cb1f35ab04dfb8de7ecaa982837fd356c41435c7758d3c4e05ad33812670b2e570830bef5a21e9bdffe297234cec9e33f9ab5250c42af1
6
+ metadata.gz: 76e48757e0e4dedffd5363b6cbb671271f2e1447cc1b06f1f1d1518315ab775a9198f72c522cbb74fc3969c54e93b2baca82d65919855025247e28897f015f9f
7
+ data.tar.gz: 89661ee1a5b0a1aa90cd21d410c087c359351b2714211f55d4a33bb35a739ef943348771fb7bf3a9cb7f4e8fd66446b0f213ac34f1c4da0e9f54b0babea74ec5
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "socket"
4
+
5
+ require_relative "version"
6
+
7
+ module Flare
8
+ # Single source of truth for the headers that identify this client and its
9
+ # version to the Flare API. The server parses the gem version out of the
10
+ # User-Agent ("Flare Ruby/X.Y.Z") to gate version-dependent features, and
11
+ # uses the X-Client-* headers to build a per-client picture.
12
+ #
13
+ # Safe to send on any request that targets the Flare API (metrics POST,
14
+ # rules GET, trace-notify POST). Do NOT send these on the presigned R2 blob
15
+ # PUT -- they're meaningless to R2 and can invalidate the signed-header set.
16
+ #
17
+ # Excludes Authorization / Flare-Project / Flare-Environment -- callers add
18
+ # those since they're request- or context-specific.
19
+ module ClientHeaders
20
+ USER_AGENT = "Flare Ruby/#{Flare::VERSION}"
21
+
22
+ def self.to_h
23
+ {
24
+ "User-Agent" => USER_AGENT,
25
+ "X-Client-Language" => "ruby",
26
+ "X-Client-Language-Version" => RUBY_VERSION,
27
+ "X-Client-Platform" => RUBY_PLATFORM,
28
+ "X-Client-Pid" => Process.pid.to_s,
29
+ "X-Client-Hostname" => hostname
30
+ }
31
+ end
32
+
33
+ def self.hostname
34
+ Socket.gethostname
35
+ rescue StandardError
36
+ "unknown"
37
+ end
38
+ end
39
+ end
@@ -5,7 +5,8 @@ require "json"
5
5
  require "zlib"
6
6
  require "stringio"
7
7
  require "securerandom"
8
- require "socket"
8
+
9
+ require_relative "client_headers"
9
10
 
10
11
  module Flare
11
12
  # Submits metrics to the Flare metrics service via HTTP.
@@ -13,7 +14,6 @@ module Flare
13
14
  class MetricSubmitter
14
15
  SCHEMA_VERSION = "V1"
15
16
  GZIP_ENCODING = "gzip"
16
- USER_AGENT = "Flare Ruby/#{Flare::VERSION}"
17
17
 
18
18
  # Default timeouts (in seconds)
19
19
  DEFAULT_OPEN_TIMEOUT = 2
@@ -123,16 +123,11 @@ module Flare
123
123
  request["Content-Type"] = "application/json"
124
124
  request["Content-Encoding"] = GZIP_ENCODING
125
125
  request["Authorization"] = "Bearer #{@api_key}"
126
- request["User-Agent"] = USER_AGENT
127
126
  request["X-Request-Id"] = request_id
128
127
  request["X-Schema-Version"] = SCHEMA_VERSION
129
128
 
130
- # Client metadata headers (like Flipper)
131
- request["X-Client-Language"] = "ruby"
132
- request["X-Client-Language-Version"] = RUBY_VERSION
133
- request["X-Client-Platform"] = RUBY_PLATFORM
134
- request["X-Client-Pid"] = Process.pid.to_s
135
- request["X-Client-Hostname"] = Socket.gethostname rescue "unknown"
129
+ # Client + version identifying headers, shared across every Flare-API request.
130
+ ClientHeaders.to_h.each { |name, value| request[name] = value }
136
131
 
137
132
  request.body = body
138
133
  response = http.request(request)
@@ -5,6 +5,7 @@ require "logger"
5
5
  require "concurrent/timer_task"
6
6
  require "concurrent/atomic/atomic_fixnum"
7
7
 
8
+ require_relative "client_headers"
8
9
  require_relative "http_transport"
9
10
 
10
11
  module Flare
@@ -118,11 +119,11 @@ module Flare
118
119
  end
119
120
 
120
121
  def request_headers
121
- headers = {
122
+ headers = ClientHeaders.to_h.merge(
122
123
  "Authorization" => "Bearer #{@api_key}",
123
124
  "Flare-Project" => @project,
124
125
  "Flare-Environment" => @environment
125
- }
126
+ )
126
127
  headers["If-None-Match"] = @etag if @etag
127
128
  headers
128
129
  end
@@ -8,6 +8,7 @@ require "uri"
8
8
  require "concurrent/atomic/atomic_fixnum"
9
9
  require "opentelemetry/sdk"
10
10
 
11
+ require_relative "client_headers"
11
12
  require_relative "sampler"
12
13
  require_relative "trace_blob"
13
14
  require_relative "http_transport"
@@ -117,13 +118,16 @@ module Flare
117
118
  @logger.warn("[Flare::TraceExporter] notify exception: #{e.class}: #{e.message}")
118
119
  end
119
120
 
121
+ # Identifies the client on the Flare-API notify POST. The presigned R2
122
+ # PUT in #ship deliberately uses PUT_HEADERS only -- adding these there
123
+ # could invalidate the signed-header set.
120
124
  def notify_headers
121
- {
125
+ ClientHeaders.to_h.merge(
122
126
  "Content-Type" => "application/json",
123
127
  "Authorization" => "Bearer #{@api_key}",
124
128
  "Flare-Project" => @project,
125
129
  "Flare-Environment" => @environment
126
- }
130
+ )
127
131
  end
128
132
 
129
133
  def record_put_failure(response)
data/lib/flare/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flare
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/flare.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "flare/configuration"
5
5
 
6
6
  require "opentelemetry/sdk"
7
7
 
8
+ require_relative "flare/client_headers"
8
9
  require_relative "flare/source_location"
9
10
  require_relative "flare/metric_key"
10
11
  require_relative "flare/metric_storage"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -196,6 +196,7 @@ files:
196
196
  - lib/flare/cli/output.rb
197
197
  - lib/flare/cli/setup_command.rb
198
198
  - lib/flare/cli/status_command.rb
199
+ - lib/flare/client_headers.rb
199
200
  - lib/flare/configuration.rb
200
201
  - lib/flare/engine.rb
201
202
  - lib/flare/filtering_span_processor.rb