README.md in determinator-2.4.0 vs README.md in determinator-2.4.2
- old
+ new
@@ -287,16 +287,21 @@
# config/initializers/determinator.rb
require 'determinator/tracking'
Determinator::Tracking.on_request do |r|
- Rails.logger.info("tag=determinator_request type=#{r.type} request_time=#{r.time} error=#{r.error?} response_status=#{r.attributes[:status]} sidekiq_queue=#{r.attributes[:queue]}")
+ Rails.logger.info("tag=determinator_request endpoint=#{r.endpoint} type=#{r.type} request_time=#{r.time} error=#{r.error?} response_status=#{r.attributes[:status]} sidekiq_queue=#{r.attributes[:queue]}")
r.determinations.each do |d|
Rails.logger.info("tag=determination id=#{d.id} guid=#{d.guid} flag=#{d.feature_id} result=#{d.determination}")
end
end
+# The library sets the "endpoint" with information about the request or sidekiq job. If you
+# have environment variables that further identify the service, e.g. ENV['APP_NAME'],
+# you can configure the tracker to prepend it to the endpoint:
+Determinator::Tracking.endpoint_env_vars = ['APP_NAME']
+
# If using an APM, you can provide trace information on the request by providing a get_context hook: e.g.
Determinator::Tracking.get_context do
span = Datadog.tracer.active_root_span
return unless span
@@ -308,12 +313,10 @@
meta: span.meta
)
end
```
-NOTE: this is implemented by keeping the list of requests in a per-request thread-local variable, which means that determinations will only be tracked on the main thread.
-
-If your application is spinning out worker threads, you should make the determinations in the main thread if possible; or collect them from your worker threads and track them in the main thread with
+NOTE: determinations will only be recorded on the threads where Determinator::Tracking is initialised via the middleware. If offloading work away from these thread (for example, by spinning up new threads within a Rack request or a Sidekiq worker), make the determinations before, and pass them through to the new threads; or, if it's not possible, collect them manually and track them in the request's thread with
```
Determinator::Tracking.track(id, guid, feature, determination)
```
## Testing this library