Skip to content

Commit 8b97155

Browse files
authored
Distributed tracing functionality with Magento (#12)
1 parent 1d30361 commit 8b97155

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ This can be done in the configuration file like so:
100100
],
101101
```
102102

103+
## Linking frontend errors to Magento Errors (Distributed Tracing)
104+
105+
For full observability you may want to connect your frontend errors and sessions to the thrown Magento errors.
106+
This could give benefits like showing where in a Replay an error occurred in Magento.
107+
108+
For this you must first install the [Magento2 Sentry module](https://github.com/justbetter/magento2-sentry)
109+
110+
Then add the following to your Rapidez `.env`
111+
112+
```env
113+
SENTRY_VUE_SAMPLE_RATE=10 # A percentage is required here (0 is allowed as well)
114+
SENTRY_VUE_INTEGRATION_BROWSER_TRACING=true
115+
SENTRY_VUE_INTEGRATION_HTTP_CLIENT=true
116+
SENTRY_VUE_INTEGRATION_GRAPHQL_CLIENT=true
117+
SENTRY_VUE_INTEGRATION_REPLAY=true
118+
```
119+
120+
With this enabled you must make sure the `sentry-trace,baggage,traceparent` headers are allowed in your Magento (and if applicable Rapidez) CORS config
121+
122+
Then in Magento make sure to enable "Tracing", "Performance tracking", and to set a "Traces sample rate" (0 is allowed)
123+
124+
With this set up your Rapidez and Magento Sentry should be linked with each other.
125+
103126
## License
104127

105128
GNU General Public License v3. Please see [License File](LICENSE) for more information.

config/rapidez/sentry-vue.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
// Amount of errors to be logged to sentry (1.00 = 100%)
1010
'sampleRate' => env('SENTRY_VUE_SAMPLE_RATE', 100) / 100,
11+
// Amount of transactions to be logged to sentry (1.00 = 100%)
12+
'tracesSampleRate' => env('SENTRY_VUE_TRACES_SAMPLE_RATE', 10) / 100,
13+
// Which backends should sentry link transactions to, by default it'll be the Rapidez and Magento backend
14+
'tracePropagationTargets' => explode(' ', env('SENTRY_VUE_TRACES_PROPAGATION_TARGETS', '') ),
15+
// Amount of replays to be logged to sentry when no error occurs (1.00 = 100%)
16+
// https://docs.sentry.io/platforms/javascript/guides/vue/session-replay/#recommended-production-sample-rates
17+
'replaysSessionSampleRate' => env('SENTRY_VUE_REPLAY_SAMPLE_RATE', 10) / 100,
18+
// Amount of replays to be logged to sentry when errors have occured (1.00 = 100%)
19+
'replaysOnErrorSampleRate' => env('SENTRY_VUE_ERROR_REPLAY_SAMPLE_RATE', 100) / 100,
20+
21+
// Only report errors for matching urls, by default the shop url will be used
22+
'allowUrls' => explode(' ', env('SENTRY_VUE_ALLOW_URLS', '') ),
1123

1224
// See the Sentry documentation: https://docs.sentry.io/platforms/javascript/guides/vue/configuration/filtering/#using-ignore-errors
1325
'ignoreErrors' => [
@@ -42,6 +54,7 @@
4254
'debug' => env('SENTRY_VUE_INTEGRATION_DEBUG', false),
4355
'extraErrorData' => env('SENTRY_VUE_INTEGRATION_EXTRA_ERROR_DATA', false),
4456
'httpClient' => env('SENTRY_VUE_INTEGRATION_HTTP_CLIENT', false),
57+
'graphqlClient' => env('SENTRY_VUE_INTEGRATION_GRAPHQL_CLIENT', false),
4558
'moduleMetadata' => env('SENTRY_VUE_INTEGRATION_MODULE_METADATA', false),
4659
'rewriteFrames' => env('SENTRY_VUE_INTEGRATION_REWRITE_FRAMES', false),
4760
'replay' => env('SENTRY_VUE_INTEGRATION_REPLAY', false),

resources/js/sentry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ let integrations = Object.entries(window.config.sentry.integrations).map(([integ
1616
return value === true ? integrationFunction() : integrationFunction(value)
1717
}).filter((value) => value !== undefined)
1818

19+
window.config.sentry.configuration.allowUrls.push(window.app.config.base_url)
20+
window.config.sentry.configuration.tracePropagationTargets.push(window.app.config.base_url)
21+
window.config.sentry.configuration.tracePropagationTargets.push(window.app.config.magento_url)
22+
23+
window.config.sentry.configuration.allowUrls = window.config.sentry.configuration.allowUrls.filter((a) => a)
24+
window.config.sentry.configuration.tracePropagationTargets = window.config.sentry.configuration.tracePropagationTargets.filter((a) => a)
25+
1926
// Set up the Sentry configuration
2027
let configuration = Object.assign(
2128
{

0 commit comments

Comments
 (0)