Skip to content

Commit de3d6ac

Browse files
committed
Add external trace ID to the run details inspector
1 parent 68bc5b7 commit de3d6ac

File tree

2 files changed

+34
-1
lines changed
  • apps/webapp/app

2 files changed

+34
-1
lines changed

apps/webapp/app/presenters/v3/SpanPresenter.server.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import {
44
SemanticInternalAttributes,
55
TaskRunContext,
66
TaskRunError,
7+
TriggerTraceContext,
78
V3TaskRunContext,
89
} from "@trigger.dev/core/v3";
9-
import { AttemptId, getMaxDuration } from "@trigger.dev/core/v3/isomorphic";
10+
import { AttemptId, getMaxDuration, parseTraceparent } from "@trigger.dev/core/v3/isomorphic";
1011
import { RUNNING_STATUSES } from "~/components/runs/v3/TaskRunStatus";
1112
import { logger } from "~/services/logger.server";
1213
import { eventRepository, rehydrateAttribute } from "~/v3/eventRepository.server";
@@ -173,6 +174,8 @@ export class SpanPresenter extends BasePresenter {
173174

174175
const context = await this.#getTaskRunContext({ run, machine: machine ?? undefined });
175176

177+
const externalTraceId = this.#getExternalTraceId(run.traceContext);
178+
176179
return {
177180
id: run.id,
178181
friendlyId: run.friendlyId,
@@ -234,6 +237,7 @@ export class SpanPresenter extends BasePresenter {
234237
spanId: run.spanId,
235238
isCached: !!span.originalRun,
236239
machinePreset: machine?.name,
240+
externalTraceId,
237241
};
238242
}
239243

@@ -272,6 +276,7 @@ export class SpanPresenter extends BasePresenter {
272276
id: true,
273277
spanId: true,
274278
traceId: true,
279+
traceContext: true,
275280
//metadata
276281
number: true,
277282
taskIdentifier: true,
@@ -574,4 +579,26 @@ export class SpanPresenter extends BasePresenter {
574579
async #getV4TaskRunContext({ run }: { run: FindRunResult }): Promise<TaskRunContext> {
575580
return engine.resolveTaskRunContext(run.id);
576581
}
582+
583+
#getExternalTraceId(traceContext: unknown) {
584+
if (!traceContext) {
585+
return;
586+
}
587+
588+
const parsedTraceContext = TriggerTraceContext.safeParse(traceContext);
589+
590+
if (!parsedTraceContext.success) {
591+
return;
592+
}
593+
594+
const externalTraceparent = parsedTraceContext.data.external?.traceparent;
595+
596+
if (!externalTraceparent) {
597+
return;
598+
}
599+
600+
const parsedTraceparent = parseTraceparent(externalTraceparent);
601+
602+
return parsedTraceparent?.traceId;
603+
}
577604
}

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,12 @@ function RunBody({
738738
<Property.Label>Run Engine</Property.Label>
739739
<Property.Value>{run.engine}</Property.Value>
740740
</Property.Item>
741+
{run.externalTraceId && (
742+
<Property.Item>
743+
<Property.Label>External Trace ID</Property.Label>
744+
<Property.Value>{run.externalTraceId}</Property.Value>
745+
</Property.Item>
746+
)}
741747
{isAdmin && (
742748
<div className="border-t border-yellow-500/50 pt-2">
743749
<Paragraph spacing variant="small" className="text-yellow-500">

0 commit comments

Comments
 (0)