openreplay icon indicating copy to clipboard operation
openreplay copied to clipboard

Ability to serve OpenReplay script from deployed OpenReplay instance

Open Filipeue opened this issue 2 years ago • 5 comments

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.

Filipeue avatar Apr 01 '22 14:04 Filipeue

I'd argue embedding the script (via NPM package and bundle into your JS) is better.

sandstrom avatar Apr 29 '22 17:04 sandstrom

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 avatar May 02 '22 03:05 carsso

@carsso Your solution is sound.

  1. 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.
  2. Because you're using caching, this is better performant.

What do you think ?

rjshrjndrn avatar May 16 '22 14:05 rjshrjndrn

@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.

carsso avatar May 16 '22 14:05 carsso

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.

carsso avatar Sep 04 '22 01:09 carsso

Closing due to inactivity. Feel free to open if needed.

rjshrjndrn avatar Feb 28 '23 13:02 rjshrjndrn

Closing due to inactivity. Feel free to open if needed.

@rjshrjndrn Do you plan to include that feature/proxy thing by default in openreplay ?

carsso avatar Feb 28 '23 13:02 carsso

Sure @carsso. I'll add to the milestone for next release

rjshrjndrn avatar Feb 28 '23 13:02 rjshrjndrn

Added in OpenReplay v1.11.0.

estradino avatar Mar 29 '23 15:03 estradino

🎉 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

carsso avatar Mar 31 '23 23:03 carsso