Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real User Monitoring (RUM) with Otel metrics #3500

Closed
hxtpoe opened this issue Dec 21, 2022 · 2 comments
Closed

Real User Monitoring (RUM) with Otel metrics #3500

hxtpoe opened this issue Dec 21, 2022 · 2 comments
Labels

Comments

@hxtpoe
Copy link

hxtpoe commented Dec 21, 2022

I need to collect browser metrics that represent user experience.
There are Web Vitals signals that I wanted to use. This is pretty easy to collect them on the user side.
My first idea was to use https://github.com/weaveworks/prom-aggregation-gateway
That works fine, but the prom-aggregation-gateway is not maintained, and the official Docker image contains some security vulnerabilities. So I need to build it on my own.

I gave a chance to use Otel because metrics feature is now stable in opentelemetry-js.
The following code demonstrates Otel usage. There is also a opentelementry-collector configured that has otlp-http receiver and prometheusremotewrite exporter. All those pieces work fine but I feel it produces invalid results.

I don't feel that the concept is correct. Shouldn't I create a simple web-exporter on server side that maintains the histogram and on every request it does myHistogram.record(value). It means that I send only metrics values to the server and client is not aware of Otel. WebVitals returns values once at page load, so having metricsReader that exports metrics in constant interval makes no sense. I thought about shooting down the reader after exporting values.

Is open-telemetry-collector able to deal with many concurrent histograms from multiple browser sessions?
Aggregation is needed to avoid high cardinality.

import { getTTFB, Metric } from "web-vitals";
import { metrics } from "@opentelemetry/api";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
import {
  MeterProvider,
  PeriodicExportingMetricReader,
  View,
  ExplicitBucketHistogramAggregation,
} from "@opentelemetry/sdk-metrics";

const TTFB = "web_ttfb";
const meterName = "webvitals.meter";
const exportIntervalMillis = 5000;

const meterProvider = new MeterProvider({
  views: [
    new View({
      aggregation: new ExplicitBucketHistogramAggregation([
        0, 5, 10, 15, 25, 35, 50, 75, 100, 150, 200,
      ]),
      instrumentName: TTFB,
      meterName: meterName,
    }),
  ],
});

metrics.setGlobalMeterProvider(meterProvider);
meterProvider.addMetricReader(
  new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter({
      url: "http://localhost/o11y/metrics/v1/metrics",
    }),
    exportIntervalMillis: exportIntervalMillis,
  })
);

const meter = meterProvider.getMeter(meterName);

const ttfbHistogram = meter.createHistogram(TTFB, {
  description: "Time to First Byte (TTFB)",
  unit: "ms",
});

const attributes = {
  environment: "dev",
  path: window.location.pathname,
};

getTTFB(({ delta }: Metric) => {
  ttfbHistogram.record(Math.floor(delta), attributes);
});
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Feb 20, 2023
@github-actions
Copy link

github-actions bot commented Mar 6, 2023

This issue was closed because it has been stale for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant