highlight_io 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -1
- data/CHANGELOG.md +27 -14
- data/Gemfile.lock +8 -8
- data/highlight.gemspec +10 -8
- data/lib/highlight/version.rb +1 -1
- data/lib/highlight.rb +168 -131
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ad24593b8967d78ebfde045dfa62cc8cec035d749d0a8ac6519235ba93dca48
|
4
|
+
data.tar.gz: 99812349e8cf1768432f03eeee493c44897a257e71a19295845f1607ed29e128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b95ccd4ac96b1e247b83471cfbcfe72b94404ad96150998503f3062aaa7decdfe2af702912e22fce9addaf864d48bf9a355e3bc7899fb77e80d764a7febee4a5
|
7
|
+
data.tar.gz: bfc55d53ba492eab3b5298f6629ff2c5a5f6ddd79de3954f57454c20ae1e8cd05593284ec40b65674fc01183919fe4d4fa5daf86e00ec688bb4181b2dea444f8
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 3.0
|
3
|
+
EnabledByDefault: true
|
4
|
+
|
5
|
+
Bundler/GemComment:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Bundler/GemVersion:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Lint/ConstantResolution:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/ConstantVisibility:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/Copyright:
|
18
|
+
Enabled: false
|
3
19
|
|
4
20
|
Style/FrozenStringLiteralComment:
|
5
21
|
Enabled: false
|
@@ -7,11 +23,32 @@ Style/FrozenStringLiteralComment:
|
|
7
23
|
Style/Documentation:
|
8
24
|
Enabled: false
|
9
25
|
|
26
|
+
Style/DocumentationMethod:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/ImplicitRuntimeError:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/InlineComment:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/MissingElse:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/OpenStructUse:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/StringHashKeys:
|
42
|
+
Enabled: false
|
43
|
+
|
10
44
|
Metrics/MethodLength:
|
11
45
|
Enabled: false
|
12
46
|
|
13
47
|
Metrics/CyclomaticComplexity:
|
14
|
-
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/PerceivedComplexity:
|
51
|
+
Enabled: false
|
15
52
|
|
16
53
|
Naming/MethodParameterName:
|
17
54
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,40 @@
|
|
1
|
-
## 0.1
|
1
|
+
## 0.5.1
|
2
2
|
|
3
|
-
-
|
3
|
+
- Fix bug with SDK controller instrumentation
|
4
|
+
- Fix `Highlight::VERSION` error
|
4
5
|
|
5
|
-
## 0.
|
6
|
+
## 0.5.0
|
6
7
|
|
7
|
-
-
|
8
|
-
-
|
8
|
+
- Fix bug with SDK initialization
|
9
|
+
- Fix bug with `service.name` and `deployment.environment` not being set
|
10
|
+
- Adds `telemetry.distro.*` attributes as resource spans
|
11
|
+
- Add `highlight_traceparent_meta` Rails tag helper
|
12
|
+
- Fixes up the Rubocop configs and addresses new issues reported
|
9
13
|
|
10
|
-
## 0.
|
14
|
+
## 0.4.0
|
11
15
|
|
12
|
-
-
|
13
|
-
-
|
16
|
+
- Add `H.init` alias
|
17
|
+
- Auto instrument Rails requests and eliminate need for `around_action`
|
18
|
+
- Fix warning about incompatibility with `ActiveSupport::LoggerSilence`
|
19
|
+
|
20
|
+
## 0.2.2
|
21
|
+
|
22
|
+
- Fix duplicate errors recorded on traces.
|
14
23
|
|
15
24
|
## 0.2.1
|
16
25
|
|
17
26
|
- Ensure `message` on logs is always a string.
|
18
27
|
|
19
|
-
## 0.2.
|
28
|
+
## 0.2.0
|
20
29
|
|
21
|
-
-
|
30
|
+
- Support setting `environment` attribute to SDK initialization.
|
31
|
+
- `otlp_endpoint` updated to keyword parameter when initializing.
|
22
32
|
|
23
|
-
## 0.4
|
33
|
+
## 0.1.4
|
24
34
|
|
25
|
-
-
|
26
|
-
-
|
27
|
-
|
35
|
+
- Tune settings of opentelemetry SDK to reduce memory usage.
|
36
|
+
- Enable GZIP compression of exported data.
|
37
|
+
|
38
|
+
## 0.1.2
|
39
|
+
|
40
|
+
- Add ability to set `service_name` and `service_version`
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
highlight_io (0.
|
5
|
-
grpc (~> 1.
|
4
|
+
highlight_io (0.5.1)
|
5
|
+
grpc (~> 1.66)
|
6
6
|
opentelemetry-exporter-otlp (~> 0.28.1)
|
7
7
|
opentelemetry-instrumentation-all (~> 0.62.1)
|
8
8
|
opentelemetry-sdk (~> 1.5.0)
|
@@ -14,18 +14,18 @@ GEM
|
|
14
14
|
ast (2.4.2)
|
15
15
|
google-protobuf (3.25.4-arm64-darwin)
|
16
16
|
google-protobuf (3.25.4-x86_64-linux)
|
17
|
-
googleapis-common-protos-types (1.
|
17
|
+
googleapis-common-protos-types (1.16.0)
|
18
18
|
google-protobuf (>= 3.18, < 5.a)
|
19
|
-
grpc (1.
|
19
|
+
grpc (1.66.0-arm64-darwin)
|
20
20
|
google-protobuf (>= 3.25, < 5.0)
|
21
21
|
googleapis-common-protos-types (~> 1.0)
|
22
|
-
grpc (1.
|
22
|
+
grpc (1.66.0-x86_64-linux)
|
23
23
|
google-protobuf (>= 3.25, < 5.0)
|
24
24
|
googleapis-common-protos-types (~> 1.0)
|
25
25
|
json (2.6.3)
|
26
26
|
language_server-protocol (3.17.0.3)
|
27
27
|
minitest (5.18.0)
|
28
|
-
opentelemetry-api (1.
|
28
|
+
opentelemetry-api (1.4.0)
|
29
29
|
opentelemetry-common (0.21.0)
|
30
30
|
opentelemetry-api (~> 1.0)
|
31
31
|
opentelemetry-exporter-otlp (0.28.1)
|
@@ -48,9 +48,9 @@ GEM
|
|
48
48
|
opentelemetry-api (~> 1.0)
|
49
49
|
opentelemetry-instrumentation-base (~> 0.22.1)
|
50
50
|
opentelemetry-instrumentation-rack (~> 0.21)
|
51
|
-
opentelemetry-instrumentation-action_view (0.7.
|
51
|
+
opentelemetry-instrumentation-action_view (0.7.3)
|
52
52
|
opentelemetry-api (~> 1.0)
|
53
|
-
opentelemetry-instrumentation-active_support (~> 0.
|
53
|
+
opentelemetry-instrumentation-active_support (~> 0.6)
|
54
54
|
opentelemetry-instrumentation-base (~> 0.22.1)
|
55
55
|
opentelemetry-instrumentation-active_job (0.7.7)
|
56
56
|
opentelemetry-api (~> 1.0)
|
data/highlight.gemspec
CHANGED
@@ -15,16 +15,18 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
17
17
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files =
|
19
|
-
|
20
|
-
|
18
|
+
spec.files =
|
19
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
21
22
|
spec.bindir = 'exe'
|
22
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
24
|
spec.require_paths = ['lib']
|
24
25
|
|
25
|
-
spec.
|
26
|
-
spec.
|
27
|
-
spec.
|
28
|
-
spec.
|
29
|
-
spec.
|
26
|
+
spec.add_dependency('grpc', '~> 1.66')
|
27
|
+
spec.add_dependency('opentelemetry-exporter-otlp', '~> 0.28.1')
|
28
|
+
spec.add_dependency('opentelemetry-instrumentation-all', '~> 0.62.1')
|
29
|
+
spec.add_dependency('opentelemetry-sdk', '~> 1.5.0')
|
30
|
+
spec.add_dependency('opentelemetry-semantic_conventions', '~> 1.10.1')
|
31
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
30
32
|
end
|
data/lib/highlight/version.rb
CHANGED
data/lib/highlight.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'opentelemetry/sdk'
|
2
|
-
require 'opentelemetry/exporter/otlp'
|
3
|
-
require 'opentelemetry/instrumentation/all'
|
4
|
-
require 'opentelemetry/semantic_conventions'
|
5
1
|
require 'date'
|
2
|
+
require 'highlight/version'
|
6
3
|
require 'json'
|
7
4
|
require 'logger'
|
5
|
+
require 'opentelemetry/exporter/otlp'
|
6
|
+
require 'opentelemetry/instrumentation/all'
|
7
|
+
require 'opentelemetry/sdk'
|
8
|
+
require 'opentelemetry/semantic_conventions'
|
8
9
|
require 'securerandom'
|
9
10
|
|
10
11
|
module Highlight
|
@@ -18,33 +19,58 @@ module Highlight
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
def self.init(project_id, environment: '', otlp_endpoint: OTLP_HTTP, &block)
|
22
|
+
def self.init(project_id, environment: '', otlp_endpoint: H::OTLP_HTTP, &block)
|
22
23
|
H.new(project_id, environment: environment, otlp_endpoint: otlp_endpoint, &block)
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.start_span(name, attrs = {}, &block)
|
26
|
-
if
|
27
|
+
if H.initialized?
|
27
28
|
H.instance.start_span(name, attrs, &block)
|
28
|
-
|
29
|
-
|
29
|
+
elsif block_given?
|
30
|
+
yield(OpenTelemetry::Trace::Span::INVALID)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def self.log(level, message, attrs = {})
|
34
|
-
H.
|
35
|
+
return unless H.initialized?
|
36
|
+
|
37
|
+
H.instance&.record_log(nil, nil, level, message, attrs)
|
35
38
|
end
|
36
39
|
|
37
40
|
def self.exception(error, attrs = {})
|
38
|
-
H.
|
41
|
+
return unless H.initialized?
|
42
|
+
|
43
|
+
H.instance&.record_exception(error, attrs)
|
39
44
|
end
|
40
45
|
|
41
46
|
def self.traceparent_meta
|
47
|
+
return unless H.initialized?
|
48
|
+
|
42
49
|
Helpers.traceparent_meta
|
43
50
|
end
|
44
51
|
|
52
|
+
def self.traceparent_meta_tag
|
53
|
+
return unless H.initialized?
|
54
|
+
|
55
|
+
Helpers.traceparent_meta_tag
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.flush
|
59
|
+
return unless H.initialized?
|
60
|
+
|
61
|
+
H.instance.flush
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.shutdown
|
65
|
+
return unless H.initialized?
|
66
|
+
|
67
|
+
H.instance.shutdown
|
68
|
+
end
|
69
|
+
|
45
70
|
class H
|
46
|
-
|
71
|
+
SDK_NAME = 'highlight-ruby'.freeze
|
47
72
|
OTLP_HTTP = 'https://otel.highlight.io:4318'.freeze
|
73
|
+
HIGHLIGHT_REQUEST_HEADER = 'X-Highlight-Request'.freeze
|
48
74
|
HIGHLIGHT_PROJECT_ATTRIBUTE = 'highlight.project_id'.freeze
|
49
75
|
HIGHLIGHT_SESSION_ATTRIBUTE = 'highlight.session_id'.freeze
|
50
76
|
HIGHLIGHT_TRACE_ATTRIBUTE = 'highlight.trace_id'.freeze
|
@@ -54,147 +80,149 @@ module Highlight
|
|
54
80
|
CODE_FILEPATH = OpenTelemetry::SemanticConventions::Trace::CODE_FILEPATH
|
55
81
|
CODE_LINENO = OpenTelemetry::SemanticConventions::Trace::CODE_LINENO
|
56
82
|
CODE_FUNCTION = OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION
|
83
|
+
DEPLOYMENT_ENVIRONMENT_ATTRIBUTE = OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT
|
84
|
+
HIGHLIGHT_SDK_VERSION_ATTRIBUTE = 'telemetry.distro.version'.freeze
|
85
|
+
HIGHLIGHT_SDK_NAME_ATTRIBUTE = 'telemetry.distro.name'.freeze
|
57
86
|
|
58
|
-
|
59
|
-
|
87
|
+
class << self
|
88
|
+
attr_reader :instance
|
60
89
|
end
|
61
90
|
|
62
|
-
def
|
63
|
-
|
91
|
+
def self.initialized?
|
92
|
+
!@instance.nil?
|
93
|
+
end
|
64
94
|
|
65
|
-
|
66
|
-
|
95
|
+
def self.parse_headers(headers)
|
96
|
+
return HighlightHeaders.new(nil, nil) if headers.nil? || !headers.key?(HIGHLIGHT_REQUEST_HEADER)
|
67
97
|
|
68
|
-
|
69
|
-
|
98
|
+
session_id, request_id = headers[HIGHLIGHT_REQUEST_HEADER].split('/')
|
99
|
+
traceparent = headers['traceparent']
|
100
|
+
trace_id = traceparent&.split('-')&.[](1) || request_id
|
101
|
+
HighlightHeaders.new(session_id, trace_id)
|
102
|
+
end
|
70
103
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
)
|
104
|
+
def self.log_level_string(level)
|
105
|
+
case level
|
106
|
+
when Logger::FATAL then 'FATAL'
|
107
|
+
when Logger::ERROR then 'ERROR'
|
108
|
+
when Logger::WARN then 'WARN'
|
109
|
+
when Logger::INFO then 'INFO'
|
110
|
+
when Logger::DEBUG then 'DEBUG'
|
111
|
+
else 'UNKNOWN'
|
112
|
+
end
|
113
|
+
end
|
82
114
|
|
83
|
-
|
84
|
-
|
85
|
-
OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => environment,
|
86
|
-
OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT => environment
|
87
|
-
)
|
115
|
+
def initialize(project_id, environment: '', otlp_endpoint: OTLP_HTTP, &block)
|
116
|
+
self.class.instance_variable_set(:@instance, self)
|
88
117
|
|
89
|
-
|
118
|
+
@project_id = project_id
|
119
|
+
@otlp_endpoint = otlp_endpoint
|
120
|
+
@environment = environment
|
90
121
|
|
91
|
-
|
92
|
-
end
|
122
|
+
configure_opentelemetry(&block)
|
93
123
|
|
94
124
|
@tracer_provider = OpenTelemetry.tracer_provider
|
95
125
|
@tracer = @tracer_provider.tracer('highlight-tracer')
|
96
126
|
end
|
97
127
|
|
98
128
|
def initialized?
|
99
|
-
|
129
|
+
!@tracer_provider.nil?
|
100
130
|
end
|
101
131
|
|
102
132
|
def flush
|
103
|
-
|
133
|
+
@tracer_provider&.force_flush
|
134
|
+
end
|
104
135
|
|
105
|
-
|
136
|
+
def shutdown
|
137
|
+
@tracer_provider&.shutdown
|
106
138
|
end
|
107
139
|
|
108
140
|
def trace(session_id, request_id, attrs = {}, name: 'highlight.span', &block)
|
109
141
|
return unless initialized?
|
110
142
|
|
111
|
-
# Passed along by the BaggageSpanProcessor to child spans as attributes.
|
112
143
|
ctx = OpenTelemetry::Baggage.set_value(HIGHLIGHT_SESSION_ATTRIBUTE, session_id || '')
|
113
144
|
ctx = OpenTelemetry::Baggage.set_value(HIGHLIGHT_TRACE_ATTRIBUTE, request_id || '', context: ctx)
|
114
|
-
|
115
|
-
OpenTelemetry::Context.with_current(ctx) do
|
116
|
-
start_span(name, attrs, &block)
|
117
|
-
end
|
145
|
+
OpenTelemetry::Context.with_current(ctx) { start_span(name, attrs, &block) }
|
118
146
|
end
|
119
147
|
|
120
|
-
def start_span(name, attrs = {}
|
148
|
+
def start_span(name, attrs = {})
|
121
149
|
return unless initialized?
|
122
150
|
|
123
|
-
if block_given?
|
124
|
-
@tracer.in_span(name, attributes: attrs, &block)
|
125
|
-
else
|
126
|
-
@tracer.in_span(name, attributes: attrs) { |_| }
|
127
|
-
end
|
151
|
+
@tracer.in_span(name, attributes: attrs.transform_keys(&:to_s)) { |span| yield(span) if block_given? }
|
128
152
|
end
|
129
153
|
|
130
154
|
def record_exception(e, attrs = {})
|
131
155
|
return unless initialized?
|
132
156
|
|
133
|
-
|
134
|
-
return unless span
|
135
|
-
|
136
|
-
span.record_exception(e, attributes: attrs)
|
157
|
+
OpenTelemetry::Trace.current_span&.record_exception(e, attributes: attrs.transform_keys(&:to_s))
|
137
158
|
end
|
138
159
|
|
139
160
|
def record_log(session_id, request_id, level, message, attrs = {})
|
140
161
|
return unless initialized?
|
141
162
|
|
142
|
-
|
143
|
-
function = caller_info[2]
|
144
|
-
if function
|
145
|
-
# format: "in `<function_name>""
|
146
|
-
function.delete_prefix!('in `')
|
147
|
-
function.delete_suffix!('"')
|
148
|
-
end
|
163
|
+
log_attributes = create_log_attributes(level, message, attrs)
|
149
164
|
|
150
|
-
@tracer.in_span(
|
151
|
-
|
152
|
-
|
153
|
-
|
165
|
+
@tracer.in_span(
|
166
|
+
'highlight.log',
|
167
|
+
attributes: {
|
168
|
+
HIGHLIGHT_SESSION_ATTRIBUTE => session_id || '',
|
169
|
+
HIGHLIGHT_TRACE_ATTRIBUTE => request_id || ''
|
170
|
+
}.compact
|
171
|
+
) do |span|
|
154
172
|
span.status = OpenTelemetry::Trace::Status.error(message) if [Logger::ERROR, Logger::FATAL].include?(level)
|
155
|
-
span.add_event(LOG_EVENT, attributes:
|
156
|
-
LOG_SEVERITY_ATTRIBUTE => H.log_level_string(level),
|
157
|
-
LOG_MESSAGE_ATTRIBUTE => message.to_s,
|
158
|
-
CODE_FILEPATH => caller_info[0],
|
159
|
-
CODE_LINENO => caller_info[1],
|
160
|
-
CODE_FUNCTION => function
|
161
|
-
}.merge(attrs))
|
173
|
+
span.add_event(LOG_EVENT, attributes: log_attributes)
|
162
174
|
end
|
163
175
|
end
|
164
176
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
177
|
+
private
|
178
|
+
|
179
|
+
def configure_opentelemetry
|
180
|
+
OpenTelemetry::SDK.configure do |c|
|
181
|
+
c.add_span_processor(Highlight::Tracing::BaggageSpanProcessor.new)
|
182
|
+
c.add_span_processor(create_batch_span_processor)
|
183
|
+
c.resource = create_resource
|
184
|
+
c.use_all
|
185
|
+
yield(c) if block_given?
|
171
186
|
end
|
172
|
-
HighlightHeaders.new(nil, nil)
|
173
187
|
end
|
174
188
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
when Logger::INFO
|
186
|
-
'INFO'
|
187
|
-
when Logger::DEBUG
|
188
|
-
'DEBUG'
|
189
|
-
else
|
190
|
-
'UNKNOWN'
|
191
|
-
end
|
189
|
+
def create_batch_span_processor
|
190
|
+
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
|
191
|
+
OpenTelemetry::Exporter::OTLP::Exporter.new(
|
192
|
+
endpoint: "#{@otlp_endpoint}/v1/traces",
|
193
|
+
compression: 'gzip'
|
194
|
+
),
|
195
|
+
schedule_delay: 1000,
|
196
|
+
max_export_batch_size: 128,
|
197
|
+
max_queue_size: 1024
|
198
|
+
)
|
192
199
|
end
|
193
200
|
|
194
|
-
|
201
|
+
def create_resource
|
202
|
+
OpenTelemetry::SDK::Resources::Resource.create(
|
203
|
+
HIGHLIGHT_PROJECT_ATTRIBUTE => @project_id,
|
204
|
+
HIGHLIGHT_SDK_VERSION_ATTRIBUTE => Highlight::VERSION,
|
205
|
+
HIGHLIGHT_SDK_NAME_ATTRIBUTE => SDK_NAME,
|
206
|
+
DEPLOYMENT_ENVIRONMENT_ATTRIBUTE => @environment
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
def create_log_attributes(level, message, attrs)
|
211
|
+
caller_info = parse_caller_info
|
212
|
+
|
213
|
+
{
|
214
|
+
LOG_SEVERITY_ATTRIBUTE => self.class.log_level_string(level),
|
215
|
+
LOG_MESSAGE_ATTRIBUTE => message.to_s,
|
216
|
+
CODE_FILEPATH => caller_info.first,
|
217
|
+
CODE_LINENO => caller_info[1],
|
218
|
+
CODE_FUNCTION => caller_info[2]
|
219
|
+
}.merge(attrs).transform_keys(&:to_s)
|
220
|
+
end
|
195
221
|
|
196
|
-
def
|
197
|
-
|
222
|
+
def parse_caller_info
|
223
|
+
caller_info = caller.first.split(':', 3)
|
224
|
+
function = caller_info[2]&.gsub(/^in `|'$/, '')
|
225
|
+
[caller_info.first, caller_info[1], function]
|
198
226
|
end
|
199
227
|
end
|
200
228
|
|
@@ -207,20 +235,15 @@ module Highlight
|
|
207
235
|
end
|
208
236
|
|
209
237
|
def add(severity, message = nil, progname = nil, &block)
|
210
|
-
severity ||= UNKNOWN
|
238
|
+
severity ||= ::Logger::UNKNOWN
|
211
239
|
return true if @logdev.nil? || severity < level
|
212
240
|
|
213
|
-
progname
|
214
|
-
if message.nil?
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
progname = @progname
|
220
|
-
end
|
221
|
-
end
|
222
|
-
super(severity, message, progname, &block)
|
223
|
-
H.instance.record_log(nil, nil, severity, message)
|
241
|
+
progname ||= @progname
|
242
|
+
message = yield if message.nil? && block_given?
|
243
|
+
message = progname if message.nil?
|
244
|
+
|
245
|
+
super
|
246
|
+
H.instance&.record_log(nil, nil, severity, message)
|
224
247
|
end
|
225
248
|
end
|
226
249
|
|
@@ -230,11 +253,13 @@ module Highlight
|
|
230
253
|
base.extend(ClassMethods)
|
231
254
|
base.helper_method(:highlight_headers)
|
232
255
|
base.around_action(:with_highlight_context)
|
256
|
+
base.helper(ViewHelpers)
|
233
257
|
end
|
234
258
|
|
235
259
|
def with_highlight_context(&block)
|
236
|
-
|
260
|
+
return yield unless H.initialized?
|
237
261
|
|
262
|
+
set_highlight_headers
|
238
263
|
H.instance.trace(
|
239
264
|
highlight_headers.session_id,
|
240
265
|
highlight_headers.request_id,
|
@@ -247,29 +272,31 @@ module Highlight
|
|
247
272
|
|
248
273
|
def set_highlight_headers
|
249
274
|
@highlight_headers = H.parse_headers(request.headers)
|
250
|
-
return
|
275
|
+
return if @highlight_headers.session_id
|
251
276
|
|
252
277
|
session_id = request.cookies['sessionID'].presence || SecureRandom.alphanumeric(28)
|
253
|
-
|
254
278
|
session_data_key = "sessionData_#{session_id}"
|
255
|
-
@session_data = request.cookies[session_data_key] ||
|
279
|
+
@session_data = request.cookies[session_data_key] || create_session_data(session_id)
|
280
|
+
|
281
|
+
set_cookies(session_id, session_data_key)
|
282
|
+
@highlight_headers = HighlightHeaders.new(session_id, nil)
|
283
|
+
end
|
284
|
+
|
285
|
+
def create_session_data(session_id)
|
286
|
+
{
|
256
287
|
sessionSecureID: session_id,
|
257
288
|
projectID: @project_id,
|
258
289
|
payloadID: 1,
|
259
|
-
sessionStartTime:
|
260
|
-
lastPushTime:
|
290
|
+
sessionStartTime: Time.now.strftime('%Q'),
|
291
|
+
lastPushTime: Time.now.strftime('%Q')
|
261
292
|
}
|
293
|
+
end
|
262
294
|
|
263
|
-
|
264
|
-
|
265
|
-
expires: 15.minutes.from_now
|
266
|
-
}
|
267
|
-
cookies[session_data_key] = {
|
268
|
-
value: @session_data.to_json,
|
269
|
-
expires: 15.minutes.from_now
|
270
|
-
}
|
295
|
+
def set_cookies(session_id, session_data_key)
|
296
|
+
expiration = 15.minutes.from_now
|
271
297
|
|
272
|
-
|
298
|
+
cookies[:sessionID] = { value: session_id, expires: expiration }
|
299
|
+
cookies[session_data_key] = { value: @session_data.to_json, expires: expiration }
|
273
300
|
end
|
274
301
|
|
275
302
|
def highlight_headers
|
@@ -278,6 +305,12 @@ module Highlight
|
|
278
305
|
|
279
306
|
module ClassMethods
|
280
307
|
end
|
308
|
+
|
309
|
+
module ViewHelpers
|
310
|
+
def highlight_traceparent_meta
|
311
|
+
tag.meta(name: 'traceparent', content: Helpers.traceparent_meta)
|
312
|
+
end
|
313
|
+
end
|
281
314
|
end
|
282
315
|
end
|
283
316
|
|
@@ -291,10 +324,14 @@ module Highlight
|
|
291
324
|
current_trace = OpenTelemetry::Trace.current_span
|
292
325
|
trace_id = current_trace&.context&.trace_id
|
293
326
|
span_id = current_trace&.context&.span_id
|
294
|
-
hex_trace_id = trace_id&.unpack1('H*') || '
|
295
|
-
hex_span_id = span_id&.unpack1('H*') || '
|
327
|
+
hex_trace_id = trace_id&.unpack1('H*') || ('0' * 32)
|
328
|
+
hex_span_id = span_id&.unpack1('H*') || ('0' * 16)
|
329
|
+
|
330
|
+
"00-#{hex_trace_id}-#{hex_span_id}-01"
|
331
|
+
end
|
296
332
|
|
297
|
-
|
333
|
+
def self.traceparent_meta_tag
|
334
|
+
"<meta name=\"traceparent\" content=\"#{traceparent_meta}\">"
|
298
335
|
end
|
299
336
|
end
|
300
337
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highlight_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Highlight
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.66'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.66'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: opentelemetry-exporter-otlp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ licenses:
|
|
106
106
|
- MIT
|
107
107
|
metadata:
|
108
108
|
homepage_uri: https://www.highlight.io
|
109
|
+
rubygems_mfa_required: 'true'
|
109
110
|
post_install_message:
|
110
111
|
rdoc_options: []
|
111
112
|
require_paths:
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
123
124
|
requirements: []
|
124
|
-
rubygems_version: 3.5.
|
125
|
+
rubygems_version: 3.5.16
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: The Highlight SDK for Ruby
|