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

Add tracing for query start #20195

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import io.airlift.log.Logger;
import io.airlift.units.DataSize;
import io.airlift.units.Duration;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.trino.ExceededCpuLimitException;
import io.trino.ExceededScanLimitException;
import io.trino.Session;
Expand Down Expand Up @@ -55,6 +57,7 @@
import static io.trino.SystemSessionProperties.getQueryMaxScanPhysicalBytes;
import static io.trino.execution.QueryState.RUNNING;
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.trino.tracing.ScopedSpan.scopedSpan;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newCachedThreadPool;
Expand All @@ -67,6 +70,7 @@ public class SqlQueryManager
private static final Logger log = Logger.get(SqlQueryManager.class);

private final ClusterMemoryManager memoryManager;
private final Tracer tracer;
private final QueryTracker<QueryExecution> queryTracker;

private final Duration maxQueryCpuTime;
Expand All @@ -79,9 +83,10 @@ public class SqlQueryManager
private final ThreadPoolExecutorMBean queryManagementExecutorMBean;

@Inject
public SqlQueryManager(ClusterMemoryManager memoryManager, QueryManagerConfig queryManagerConfig)
public SqlQueryManager(ClusterMemoryManager memoryManager, Tracer tracer, QueryManagerConfig queryManagerConfig)
{
this.memoryManager = requireNonNull(memoryManager, "memoryManager is null");
this.tracer = requireNonNull(tracer, "tracer is null");

this.maxQueryCpuTime = queryManagerConfig.getQueryMaxCpuTime();
this.maxQueryScanPhysicalBytes = queryManagerConfig.getQueryMaxScanPhysicalBytes();
Expand Down Expand Up @@ -253,7 +258,11 @@ public void createQuery(QueryExecution queryExecution)
});

try (SetThreadName ignored = new SetThreadName("Query-%s", queryExecution.getQueryId())) {
queryExecution.start();
try (var ignoredStartScope = scopedSpan(tracer.spanBuilder("query-start")
.setParent(Context.current().with(queryExecution.getSession().getQuerySpan()))
.startSpan())) {
queryExecution.start();
}
}
}

Expand Down
Loading