-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add platform and version to log creator comment * feat: respect forwarded headers on incoming requests * feat: accept more json mime types and better handle form_urlencoded bodies * feat: allow custom uuid to be set; otherwise, generate one * docs: update docs * fix: update validation logic to make input options less strict * feat: support an ignore option #351
- Loading branch information
Ilias Tsangaris
authored
Jan 6, 2022
1 parent
1e15646
commit 50267ff
Showing
13 changed files
with
210 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ gem "rake", "~> 12.0" | |
gem "rspec", "~> 3.0" | ||
gem "standard" | ||
gem "webmock" | ||
gem "os" | ||
gem "uuid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,73 +25,72 @@ from the environment, or you may hardcode them. | |
If you're using Warden-based authentication like Devise, you may fetch the | ||
current_user for a given request from the environment. | ||
|
||
### Batching requests | ||
|
||
By default, the middleware will batch requests to the ReadMe API in groups of 10. | ||
For every 10 requests made to your application, the middleware will make a | ||
single request to ReadMe. If you wish to override this, provide a | ||
`buffer_length` option when configuring the middleware. | ||
|
||
### Sensitive Data | ||
|
||
If you have sensitive data you'd like to prevent from being sent to the Metrics | ||
API via headers, query params or payload bodies, you can specify a list of keys | ||
to filter via the `reject_params` option. Key-value pairs matching these keys | ||
will not be included in the request to the Metrics API. | ||
|
||
You are also able to specify a set of `allow_only` which should only be sent through. | ||
Any header or body values not matching these keys will be filtered out and not | ||
send to the API. | ||
|
||
You may only specify either `reject_params` or `allow_only` keys, not both. | ||
### SDK Options | ||
|
||
Option | Type | Description | ||
-----------------|------------------|--------- | ||
`reject_params` | Array of strings | If you have sensitive data you'd like to prevent from being sent to the Metrics API via headers, query params or payload bodies, you can specify a list of keys | ||
to filter via the `reject_params` option. NOTE: cannot be used in conjunction with `allow_only`. You may only specify either `reject_params` or `allow_only` keys, not both. | ||
`allow_only` | Array of strings | The inverse of `reject_params`. If included all parameters but those in this list will be redacted. NOTE: cannot be used in conjunction with `reject_params`. You may only specify either `reject_params` or `allow_only` keys, not both. | ||
`development` | bool | Defaults to `false`. When `true`, the log will be marked as a development log. This is great for separating staging or test data from data coming from customers. | ||
`buffer_length` | number | Defaults to `1`. This value should be a number representing the amount of requests to group up before sending them over the network. Increasing this value may increase performance by batching, but will also delay the time until logs show up in the dashboard given the buffer size needs to be reached in order for the logs to be sent. | ||
|
||
### Payload Data | ||
|
||
Option | Required? | Type | Description | ||
--------------------|-----------|------------------|---------- | ||
`api_key` | yes | string | API Key used to make the request. Note that this is different from the `readmeAPIKey` described above in the options data. This should be a value from your API that is unique to each of your users. | ||
`label` | no | string | This will be the user's display name in the API Metrics Dashboard, since it's much easier to remember a name than an API key. | ||
`email` | no | string | Email of the user that is making the call. | ||
`log_id` | no | string | A UUIDv4 identifier. If not provided this will be automatically generated for you. Providing your own `log_id` is useful if you want to know the URL of the log in advance, i.e. `{your_base_url}/logs/{your_log_id}`. | ||
`ignore` | no | bool | A flag that when set to `true` will suppress sending the log. | ||
|
||
### Rails | ||
|
||
```ruby | ||
# config/environments/development.rb or config/environments/production.rb | ||
require "readme/metrics" | ||
|
||
options = { | ||
sdk_options = { | ||
api_key: "<<apiKey>>", | ||
development: false, | ||
reject_params: ["not_included", "dont_send"], | ||
buffer_length: 5, | ||
} | ||
|
||
config.middleware.use Readme::Metrics, options do |env| | ||
config.middleware.use Readme::Metrics, sdk_options do |env| | ||
current_user = env['warden'].authenticate | ||
|
||
if current_user.present? | ||
{ | ||
api_key: current_user.api_key, # Not the same as the ReadMe API Key | ||
label: current_user.name, | ||
email: current_user.email | ||
} | ||
else | ||
{ | ||
api_key: "guest", | ||
label: "Guest User", | ||
email: "[email protected]" | ||
} | ||
end | ||
payload_data = current_user.present? ? { | ||
api_key: current_user.api_key, # Not the same as the ReadMe API Key | ||
label: current_user.name, | ||
email: current_user.email | ||
} : { | ||
api_key: "guest", | ||
label: "Guest User", | ||
email: "[email protected]" | ||
} | ||
|
||
payload_data | ||
end | ||
``` | ||
|
||
### Rack | ||
|
||
```ruby | ||
# config.ru | ||
options = { | ||
sdk_options = { | ||
api_key: "<<apiKey>>", | ||
development: false, | ||
reject_params: ["not_included", "dont_send"] | ||
} | ||
|
||
use Readme::Metrics, options do |env| | ||
use Readme::Metrics, sdk_options do |env| | ||
{ | ||
api_key: "owlbert_api_key" | ||
label: "Owlbert", | ||
email: "[email protected]" | ||
email: "[email protected]", | ||
log_id: SecureRandom.uuid | ||
} | ||
end | ||
|
||
|
@@ -104,6 +103,10 @@ run YourApp.new | |
- [Rack](https://github.com/readmeio/metrics-sdk-racks-sample) | ||
- [Sinatra](https://github.com/readmeio/metrics-sdk-sinatra-example) | ||
|
||
### Contributing | ||
|
||
Ensure you are running the version of ruby specified in the `Gemfile.lock`; use `rvm` to easy manage ruby versions. Run `bundle` to install dependencies, `rake` or `rspec` to ensure tests pass, and `bundle exec standardrb` to lint the code. | ||
|
||
## License | ||
|
||
[View our license here](https://github.com/readmeio/metrics-sdks/tree/main/packages/ruby/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.