Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Remove ingestion requests and Oban queries from OTEL (#2543)
Vini Brasil10a976791261
diff --git a/lib/plausible/open_telemetry.ex b/lib/plausible/open_telemetry.exindex b12ea7582e..0bba304476 100644--- a/lib/plausible/open_telemetry.ex+++ b/lib/plausible/open_telemetry.ex@@ -50,12 +50,16 @@ enddefmodule Plausible.OpenTelemetry.Sampler do@moduledoc """[Custom OpenTelemetry sampler](https://hexdocs.pm/opentelemetry/readme.html#samplers)- implementation that ignores `/api/event` traces, while recording 100% of other traces.+ implementation that ignores particular traces to reduce noise. Ingestion+ HTTP requests and queries to Oban tables are ignored, for example."""@behaviour :otel_samplerrequire OpenTelemetry.Tracer, as: Tracer+ @routes_to_ignore ["/api/event", "/api/event/"]+ @tables_to_ignore ["oban_jobs"]+@impl truedef setup(_sampler_opts), do: []@@ -63,15 +67,18 @@ defmodule Plausible.OpenTelemetry.Sampler dodef description(_sampler_config), do: inspect(__MODULE__)@impl true- def should_sample(context, _trace_id, _links, _name, _kind, attributes, _config)- when attributes."http.target" == "/api/event" do+ def should_sample(context, _trace_id, _links, _name, _kind, attributes, _config) dotracestate = context |> Tracer.current_span_ctx() |> OpenTelemetry.Span.tracestate()- {:drop, [], tracestate}- end- @impl true- def should_sample(context, _trace_id, _links, _name, _kind, _attributes, _config) do- tracestate = context |> Tracer.current_span_ctx() |> OpenTelemetry.Span.tracestate()- {:record_and_sample, [], tracestate}+ case attributes do+ %{"db.instance": _db, source: source} when source in @tables_to_ignore ->+ {:drop, [], tracestate}++ %{"http.target": http_target} when http_target in @routes_to_ignore ->+ {:drop, [], tracestate}++ _any ->+ {:record_and_sample, [], tracestate}+ endendend