openreplay
openreplay copied to clipboard
Ability to serve OpenReplay script from deployed OpenReplay instance
It would be nice to be able to serve OpenReplay script from deployed OpenReplay instance. If we server script from our own custom domain it is less likely it gets blocked by anti-trackers.
I'd argue embedding the script (via NPM package and bundle into your JS) is better.
While waiting for an official solution, the way I did it (the ugly way, just to skip anti-trackers), I proxified static.openreplay.com through nginx on OpenReplay instance.
It works only if you are in >= 1.6.0 because it requires nginx-ingress.
Put that in a static-latest.yaml file
kind: Service
apiVersion: v1
metadata:
name: openreplay-static
spec:
type: ExternalName
externalName: static.openreplay.com
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: openreplay-static-ingress
annotations:
nginx.ingress.kubernetes.io/backend-protocol: https
nginx.ingress.kubernetes.io/rewrite-target: '/latest/$1'
nginx.ingress.kubernetes.io/upstream-vhost: static.openreplay.com
nginx.ingress.kubernetes.io/proxy-body-size: 8m
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/server-snippet: |
proxy_ssl_name static.openreplay.com;
proxy_ssl_server_name on;
spec:
ingressClassName: openreplay
tls:
- hosts:
- openreplay.mycompany.com
secretName: openreplay-ssl
rules:
- host: openreplay.mycompany.com
http:
paths:
- path: /static-latest/(.*)
pathType: Prefix
backend:
service:
name: openreplay-static
port:
number: 443
Change openreplay.mycompany.com
(2 times) by your domain
Then run kubectl apply -f static-latest.yaml
Everything hosted on https://static.openreplay.com/latest/
will be served from your instance url https://openreplay.mycompany.com/static-latest/
.
Then you'll be able to replace
https://static.openreplay.com/latest/openreplay-assist.js
by
https://openreplay.mycompany.com/static-latest/openreplay-assist.js
in your tracker script
Additionaly, if you want to add cache to proxified files :
In your vars.yaml, add this line inside ingress-nginx
section config
:
http-snippet: "proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=static-cache:10m max_size=1g inactive=60m use_temp_path=off;"
Run openreplay-cli -I
to apply the config
In static-latest.yaml, add these lines inside nginx.ingress.kubernetes.io/server-snippet
proxy_cache static-cache;
proxy_cache_valid any 60m;
add_header X-Cache-Status $upstream_cache_status;
run kubectl apply -f static-latest.yaml
to apply this config
You can check if you hit the cache with
curl -k -I https://openreplay.mycompany.com/static-latest/openreplay-assist.js | grep x-cache-status
(try that command multiple times)
It will return x-cache-status: MISS
(if the file was not in cache yet) or x-cache-status: HIT
(if the file is returned directly from cache).
@carsso Your solution is sound.
- You don't have to maintain the JS, as it's proxied from upstream, and you'll always get fixes and perf improvements without any changes.
- Because you're using caching, this is better performant.
What do you think ?
@rjshrjndrn Yup 👍🏻 Feel free to integrate that in the helm config if you want :) Maybe the thing to improve is the path (/static-latest). That part is up to you, I did not want to use something too generic in my workaround to avoid collisions with future updates.
I just edited my message earlier in this conversation to add two lines in my config :
nginx.ingress.kubernetes.io/proxy-body-size: 8m nginx.ingress.kubernetes.io/proxy-buffering: "on"
Because nginx caching was not working anymore, these two lined fixed it.
Closing due to inactivity. Feel free to open if needed.
Closing due to inactivity. Feel free to open if needed.
@rjshrjndrn Do you plan to include that feature/proxy thing by default in openreplay ?
Sure @carsso. I'll add to the milestone for next release
Added in OpenReplay v1.11.0
.
🎉
Scripts are proxified throuhgh the following paths (from v1.11.0) :
https://openreplay.mycompany.com/script/latest/openreplay-assist.js
https://openreplay.mycompany.com/script/latest/openreplay.js