From 8582fc0ec82dbb3e2a3f309a40211cf24ac22fd0 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 18 Jan 2024 08:17:11 +0100 Subject: [PATCH] Carry log_comment context into parallel queries --- lib/plausible/clickhouse_repo.ex | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/plausible/clickhouse_repo.ex b/lib/plausible/clickhouse_repo.ex index a2bc05148..31dc910f8 100644 --- a/lib/plausible/clickhouse_repo.ex +++ b/lib/plausible/clickhouse_repo.ex @@ -59,14 +59,17 @@ defmodule Plausible.ClickhouseRepo do @task_timeout 60_000 def parallel_tasks(queries) do - ctx = OpenTelemetry.Ctx.get_current() + otel_ctx = OpenTelemetry.Ctx.get_current() + ch_ctx = get_context() + + context_carrier = fn fun -> + OpenTelemetry.Ctx.attach(otel_ctx) + set_context(ch_ctx) - execute_with_tracing = fn fun -> - OpenTelemetry.Ctx.attach(ctx) fun.() end - Task.async_stream(queries, execute_with_tracing, max_concurrency: 3, timeout: @task_timeout) + Task.async_stream(queries, context_carrier, max_concurrency: 3, timeout: @task_timeout) |> Enum.to_list() |> Keyword.values() end