koderift-rails 2.0.0 → 2.1.0
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 +4 -4
- data/CHANGELOG.md +32 -0
- data/README.md +32 -2
- data/lib/koderift/rails/configuration.rb +9 -0
- data/lib/koderift/rails/rum_helper.rb +60 -4
- data/lib/koderift/rails/version.rb +1 -1
- data/lib/koderift/rails.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b77962b847bf6127f3029ab4cab2eb3f71ae3cf0d0041c6d2df6ad1108449c7e
|
|
4
|
+
data.tar.gz: cc0a1ab9373ca3544bf3d9b48bf08ea1afa269236d4385e9873a139ea258fb0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 274e3e08f2d325ef30063547658668b955eb32607c6705829c5de531b8ac40d63701d199a3fffb9d537f3298a29816dd491ba897a0ec93dc0237eebaa2964b24
|
|
7
|
+
data.tar.gz: d409cd77d3f77b28d86fb526ddff9b096314b8b12e4af3e1e687b281a98d811fabcb775b164eed5a785433ee6455697faabd1a25c3cb5953a8c8fadd3ccb1425
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,38 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
Releases before 1.3.4 were installed from git and were never published to
|
|
7
7
|
RubyGems; they are listed for continuity.
|
|
8
8
|
|
|
9
|
+
## [2.1.0] - 2026-11-06
|
|
10
|
+
|
|
11
|
+
Security fix: the Browser RUM meta tag no longer publishes your project token.
|
|
12
|
+
|
|
13
|
+
### Security
|
|
14
|
+
- `koderift_rum_meta_tag` used to render `config.project_token` into page HTML.
|
|
15
|
+
That token is the log agent's ingest secret, so anyone reading your page
|
|
16
|
+
source could use it to send log lines to your Koderift project, including
|
|
17
|
+
lines that count against its log quota. The tag now renders only the new
|
|
18
|
+
`config.rum_token`, a public token that can only send browser RUM data.
|
|
19
|
+
- If you rendered the RUM tag on 2.0 or older, treat your project token as
|
|
20
|
+
public. Once this version is deployed with `rum_token` set, rotate the ingest
|
|
21
|
+
token in Koderift (Log Analytics settings, "Rotate ingest token"), then update
|
|
22
|
+
`webhook_url` in the agent's `agent.yml` and `KODERIFT_PROJECT_TOKEN` in your
|
|
23
|
+
app, and restart the agent.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- `config.rum_token`: your project's public RUM token, from the Log Analytics
|
|
27
|
+
setup page in Koderift. It starts with `rum_`.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- **Action needed if you use Browser RUM:** set `config.rum_token`. Without it
|
|
31
|
+
the meta tag renders nothing, and the gem logs one warning per process the
|
|
32
|
+
first time a page renders it. There is deliberately no fallback to
|
|
33
|
+
`project_token`. The tag also refuses a `rum_token` equal to `project_token`.
|
|
34
|
+
|
|
35
|
+
### Notes
|
|
36
|
+
- Koderift keeps accepting RUM data sent with the old token until
|
|
37
|
+
1 February 2027, so pages not yet upgraded keep reporting until then.
|
|
38
|
+
- `project_token` is still required to turn the gem on. The gem never sends it
|
|
39
|
+
anywhere; the log agent uses its own copy in `agent.yml`.
|
|
40
|
+
|
|
9
41
|
## [2.0.0] - 2026-11-04
|
|
10
42
|
|
|
11
43
|
Manual error reporting, with a Sentry-compatible API.
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Requires Ruby >= 2.7 and Rails 7.1-8.x.
|
|
|
12
12
|
Add to your `Gemfile`:
|
|
13
13
|
|
|
14
14
|
```ruby
|
|
15
|
-
gem 'koderift-rails', '~> 2.
|
|
15
|
+
gem 'koderift-rails', '~> 2.1'
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Run `bundle install`. Lograge is a dependency of this gem and is installed
|
|
@@ -32,7 +32,37 @@ end
|
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
Set `KODERIFT_PROJECT_TOKEN` in your environment to the token from your
|
|
35
|
-
project's Log Analytics settings page in Koderift.
|
|
35
|
+
project's Log Analytics settings page in Koderift. It is the log agent's
|
|
36
|
+
ingest secret: keep it out of your repository and your page HTML.
|
|
37
|
+
|
|
38
|
+
## Browser RUM
|
|
39
|
+
|
|
40
|
+
To collect Core Web Vitals and JS error counts from real browsers, set your
|
|
41
|
+
project's public RUM token (from the Log Analytics setup page; it starts with
|
|
42
|
+
`rum_`) and add the meta tag and snippet inside your layout's `<head>`:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
Koderift::Rails.configure do |config|
|
|
46
|
+
config.project_token = ENV['KODERIFT_PROJECT_TOKEN']
|
|
47
|
+
config.rum_token = 'rum_...'
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```erb
|
|
52
|
+
<%= koderift_rum_meta_tag %>
|
|
53
|
+
<script src="https://<your Koderift host>/ingest/rum.js" async defer></script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The meta tag publishes `rum_token` only. It can only send browser RUM data, so
|
|
57
|
+
it is safe in page HTML and safe to commit. The gem never renders
|
|
58
|
+
`project_token`, and it refuses a `rum_token` equal to it. Without a
|
|
59
|
+
`rum_token` the tag renders nothing and the gem logs one warning per process.
|
|
60
|
+
Set `config.rum_enabled = false` for API-only apps.
|
|
61
|
+
|
|
62
|
+
Upgrading from 2.0 or older with RUM in use? Those versions published
|
|
63
|
+
`project_token` in the meta tag. Set `rum_token`, deploy, then rotate the
|
|
64
|
+
ingest token in Koderift (Log Analytics settings) and update `webhook_url` in
|
|
65
|
+
the agent's `agent.yml`. See the [changelog](CHANGELOG.md).
|
|
36
66
|
|
|
37
67
|
## What it captures
|
|
38
68
|
|
|
@@ -7,6 +7,14 @@ module Koderift
|
|
|
7
7
|
# Set from an environment variable in the initializer.
|
|
8
8
|
attr_accessor :project_token
|
|
9
9
|
|
|
10
|
+
# Public token for Browser RUM, rendered into page HTML by
|
|
11
|
+
# koderift_rum_meta_tag. It can only send browser RUM data, so it is safe
|
|
12
|
+
# to publish (and to commit). Copy it from your project's Log Analytics
|
|
13
|
+
# setup page in Koderift; it starts with "rum_". Never set it to
|
|
14
|
+
# project_token: that is the log agent's ingest secret, and anyone who
|
|
15
|
+
# reads it from your page source can send log lines to your project.
|
|
16
|
+
attr_accessor :rum_token
|
|
17
|
+
|
|
10
18
|
# Lambda called with the controller instance to get the current user.
|
|
11
19
|
# Default tries common patterns. Override if your app is different.
|
|
12
20
|
# Example: ->(controller) { controller.current_user }
|
|
@@ -65,6 +73,7 @@ module Koderift
|
|
|
65
73
|
|
|
66
74
|
def initialize
|
|
67
75
|
@project_token = nil
|
|
76
|
+
@rum_token = nil
|
|
68
77
|
@current_user = default_current_user
|
|
69
78
|
@filter_params = %w[
|
|
70
79
|
password password_confirmation
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
module Koderift
|
|
4
4
|
module Rails
|
|
5
5
|
module RumHelper
|
|
6
|
+
MISSING_RUM_TOKEN_WARNING =
|
|
7
|
+
'[Koderift] Browser RUM is off: koderift_rum_meta_tag renders nothing until ' \
|
|
8
|
+
'config.rum_token is set. Since koderift-rails 2.1 the tag no longer publishes ' \
|
|
9
|
+
'config.project_token, which is a secret. Copy the public RUM token (it starts ' \
|
|
10
|
+
"with rum_) from your project's Log Analytics setup page in Koderift, or set " \
|
|
11
|
+
'config.rum_enabled = false.'
|
|
12
|
+
|
|
13
|
+
SECRET_RUM_TOKEN_WARNING =
|
|
14
|
+
'[Koderift] Browser RUM is off: config.rum_token is set to your project token, ' \
|
|
15
|
+
'which is a secret and must not appear in page HTML. Use the public RUM token ' \
|
|
16
|
+
"(it starts with rum_) from your project's Log Analytics setup page in Koderift."
|
|
17
|
+
|
|
6
18
|
# Renders the meta tag that rum.js reads for initialisation.
|
|
7
19
|
# Place once inside <head> in your application layout.
|
|
8
20
|
#
|
|
@@ -11,24 +23,68 @@ module Koderift
|
|
|
11
23
|
#
|
|
12
24
|
# Renders:
|
|
13
25
|
# <meta name="koderift-rum-token"
|
|
14
|
-
# content="
|
|
26
|
+
# content="rum_abc123"
|
|
15
27
|
# data-rum-sampling-rate="0.1"
|
|
16
28
|
# data-environment="production">
|
|
17
29
|
#
|
|
18
|
-
#
|
|
30
|
+
# Publishes config.rum_token only, never config.project_token. Returns an
|
|
31
|
+
# empty string when RUM is disabled or there is no publishable token.
|
|
19
32
|
def koderift_rum_meta_tag
|
|
20
33
|
config = Koderift::Rails.configuration
|
|
21
|
-
return ''.html_safe unless config.rum_enabled
|
|
34
|
+
return ''.html_safe unless config.rum_enabled
|
|
35
|
+
|
|
36
|
+
token = RumHelper.publishable_rum_token(config)
|
|
37
|
+
return ''.html_safe unless token
|
|
22
38
|
|
|
23
39
|
tag.meta(
|
|
24
40
|
name: 'koderift-rum-token',
|
|
25
|
-
content:
|
|
41
|
+
content: token,
|
|
26
42
|
data: {
|
|
27
43
|
rum_sampling_rate: config.rum_sampling_rate.to_f,
|
|
28
44
|
environment: (defined?(::Rails) && ::Rails.respond_to?(:env) ? ::Rails.env.to_s : 'production')
|
|
29
45
|
}
|
|
30
46
|
)
|
|
31
47
|
end
|
|
48
|
+
|
|
49
|
+
class << self
|
|
50
|
+
# The token the meta tag may publish, or nil. Up to 2.0 the tag published
|
|
51
|
+
# project_token, the log agent's ingest secret. It never does now, and a
|
|
52
|
+
# rum_token equal to it is refused for the same reason. There is
|
|
53
|
+
# deliberately no fallback: an app that set up RUM before 2.1 and has
|
|
54
|
+
# not set rum_token gets one warning per process instead.
|
|
55
|
+
def publishable_rum_token(config)
|
|
56
|
+
token = config.rum_token.to_s
|
|
57
|
+
secret = config.project_token.to_s
|
|
58
|
+
|
|
59
|
+
if token.empty?
|
|
60
|
+
warn_once(MISSING_RUM_TOKEN_WARNING) unless secret.empty?
|
|
61
|
+
return nil
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
if token == secret
|
|
65
|
+
warn_once(SECRET_RUM_TOKEN_WARNING)
|
|
66
|
+
return nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
token
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def reset_warnings!
|
|
73
|
+
@warned = false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def warn_once(message)
|
|
79
|
+
return if @warned
|
|
80
|
+
|
|
81
|
+
@warned = true
|
|
82
|
+
logger = defined?(::Rails) && ::Rails.respond_to?(:logger) ? ::Rails.logger : nil
|
|
83
|
+
logger&.warn(message)
|
|
84
|
+
rescue StandardError
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
end
|
|
32
88
|
end
|
|
33
89
|
end
|
|
34
90
|
end
|
data/lib/koderift/rails.rb
CHANGED