argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
16.73k stars 5.07k forks source link

DataDog RUM Integration #16784

Open zhammer opened 6 months ago

zhammer commented 6 months ago

Summary

Similarly to #738 (Google analytics integration), it should be possible to enable dd rum tracking. Rum ID and client token should be specified in argocd-cm config map and accessible via API

Motivation

DataDog RUM is a useful analytics/insights alternative to Google Analytics, especially for platform teams that are less familiar with and may not have access to a GA account.

Proposal

Follow the same pattern as laid out in #1848

zhammer commented 4 months ago

From discussion in the argo contributor meeting, we're going to try implementing this as an extension

zhammer commented 4 months ago

We've implemented this using a UI extension. Happy to open source though it's a little unclear what the best way to do that is since it requires custom configuration on the rum sdk (and also optional configuration). Anyway here's the extension index.ts we run:

import { datadogRum } from '@datadog/browser-rum';

async function setUser() {
    const res = await fetch(`/api/v1/session/userinfo`)
    if (res.status !== 200) {
        throw new Error(`Failed to get user info: ${res.status}`);
    }
    const { username } = await res.json();
    datadogRum.setUser({ id: username });
}

function initDDRum() {
    datadogRum.init({
        applicationId: '<application_id>',
        clientToken: '<client_token>',
        service: 'argocd',
        traceSampleRate: 100,
        telemetrySampleRate: 100,
        sessionSampleRate: 100,
        sessionReplaySampleRate: 100,
        trackUserInteractions: true,
    })

    setUser().catch(e => console.warn('Failed to set user:', e));
}

initDDRum();

we build it with webpack into a dist file that gets installed to argocd.