Skip to content

Commit 1ce3370

Browse files
authored
Show service name and operation name (#77)
* Don't throw when parent can't be found. * Show service name and operation name
1 parent 8150c82 commit 1ce3370

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

scripts/create-depth-trace.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ const log = (...xs) => console.info(new Date().toISOString(), ...xs);
1111
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1212
const rndFloat = (min, max) => Math.random() * (max - min) + min;
1313

14+
const operations = [
15+
'Assault Weathertop',
16+
'Siege Dol Guldur',
17+
'Cross the Misty Mountains',
18+
'Guard the Argonath',
19+
'Seek the Arkenstone',
20+
'Unearth Moria',
21+
"Hold Helm's Deep",
22+
'Reclaim Erebor',
23+
'Venture into Mirkwood',
24+
'Pursue the Orc-pack',
25+
'Rally the Rohirrim',
26+
'Scout the Black Gate',
27+
'Defend Minas Tirith',
28+
'Bind the Nine',
29+
'Forge Andúril',
30+
'Break the Siege',
31+
'Illuminate the Path',
32+
'Whisper to Eagles',
33+
'Secure the Shire',
34+
'Journey to Mount Doom',
35+
];
36+
37+
let currentOperationIndex = 0;
38+
39+
export function getOperation() {
40+
const operation = operations[currentOperationIndex];
41+
currentOperationIndex = (currentOperationIndex + 1) % operations.length; // Cycle through the array
42+
return operation;
43+
}
44+
1445
// ---------- parameters ----------
1546
const NUM_SERVICES = 3;
1647
const CHILDREN = 5;
@@ -74,7 +105,7 @@ async function main() {
74105

75106
for (let i = 0; i < NUM_SERVICES; i++) {
76107
// Use the service tracer to create service spans with proper namespace
77-
const serviceSpan = tracers[i].startSpan(`service_${i + 1}`, undefined, rootCtx);
108+
const serviceSpan = tracers[i].startSpan(`${getOperation()} (s${i + 1})`, undefined, rootCtx);
78109
serviceSpan.setAttribute('k8s.container.name', `service-container-${i + 1}`);
79110

80111
// Add 3 events to service span
@@ -92,7 +123,7 @@ async function main() {
92123

93124
for (let j = 0; j < CHILDREN; j++) {
94125
// Use the same service tracer for child spans to maintain namespace
95-
const childSpan = tracers[i].startSpan(`service_${i + 1}_child_${j + 1}`, undefined, serviceCtx);
126+
const childSpan = tracers[i].startSpan(`${getOperation()} (s${i + 1} c${j + 1})`, undefined, serviceCtx);
96127
childSpan.setAttribute('child-span-attribute-xyz', 456);
97128
childSpan.setAttribute('k8s.container.name', `container-${i + 1}-${j + 1}`);
98129

src/components/Span/Span.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ export const Span = (props: SpanNodeProps) => {
8080
<Expand childStatus={props.childStatus} action={() => props.updateChildStatus(props)}></Expand>
8181
{props.childCount !== undefined && props.childCount > 0 && (
8282
<strong
83-
style={{ backgroundColor: getColourForValue(props.serviceNamespace || 'default') }}
83+
style={{ backgroundColor: getColourForValue(props.serviceName || 'default') }}
8484
className="block p-[3px] min-w-5 mr-1 rounded font-mono font-thin leading-none text-gray-900 dark:text-black text-center"
8585
>
8686
{props.childCount}
8787
</strong>
8888
)}
89-
<span className="text-gray-900 dark:text-white">{props.name}</span>
89+
<span className="text-gray-900 dark:text-white">{props.serviceName}</span>
90+
<span className="text-gray-400">{props.name}</span>
9091
</div>
9192
</div>
9293
<div
@@ -101,7 +102,7 @@ export const Span = (props: SpanNodeProps) => {
101102
style={{
102103
left: `${offset}%`,
103104
width: `${Math.max(width, 0.1)}%`,
104-
backgroundColor: getColourForValue(props.serviceNamespace || 'default'),
105+
backgroundColor: getColourForValue(props.serviceName || 'default'),
105106
}} // Limitation in tailwind dynamic class construction: Check README.md for more details
106107
title={`Duration: ${props.endTimeUnixNano - props.startTimeUnixNano}ns`}
107108
></div>

src/components/TraceDetail.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async function extractSpans(
9292
} else {
9393
let parentLevel = idToLevelMap.get(parentSpanId);
9494
if (parentLevel === undefined) {
95-
throw new Error(`Parent level not found for ${span.spanID}`);
95+
// If traces are linked, there might be a parentId from another trace.
96+
// In this case, we consider it a root span.
97+
parentLevel = 0;
9698
}
9799
idToLevelMap.set(span.spanID, parentLevel + 1);
98100
}
@@ -110,12 +112,7 @@ async function extractSpans(
110112
childCount = await fetchChildCountViaAPI(datasourceUid, traceId, span.spanID, startTimeUnixNano, endTimeUnixNano);
111113
}
112114

113-
const serviceNamespace =
114-
span.attributes?.find((a) => a.key === 'service.namespace')?.value?.stringValue || undefined;
115-
116-
// Using k8s.container.name as the service name since this is specific to our Kubernetes environment.
117-
// Jaeger UI is pulling this info from the process object which is in our case translated to this attribute.
118-
const serviceName = span.attributes?.find((a) => a.key === 'k8s.container.name')?.value?.stringValue || undefined;
115+
const serviceName = span.attributes?.find((a) => a.key === 'service.name')?.value?.stringValue || undefined;
119116

120117
spans.push({
121118
spanId: span.spanID,
@@ -126,8 +123,8 @@ async function extractSpans(
126123
endTimeUnixNano: endTimeUnixNano,
127124
childStatus: childCount !== undefined && childCount > 0 ? ChildStatus.RemoteChildren : ChildStatus.NoChildren,
128125
childCount,
129-
name: serviceName || span.name || '',
130-
serviceNamespace,
126+
name: span.name || '',
127+
serviceName,
131128
});
132129
}
133130
return spans;
@@ -141,9 +138,7 @@ async function loadMoreSpans(
141138
): Promise<SpanInfo[]> {
142139
const q = `{ trace:id = "${traceId}" && span:parentID = "${
143140
span.spanId
144-
}" } | select (span:parentID, span:name, span.k8s.container.name, resource.service.namespace${
145-
supportsChildCount ? ', childCount' : ''
146-
})`;
141+
}" } | select (span:parentID, span:name, resource.service.name${supportsChildCount ? ', childCount' : ''})`;
147142
const start = mkUnixEpochFromNanoSeconds(span.startTimeUnixNano);
148143
// As a precaution, we add 1 second to the end time.
149144
// This is to avoid any rounding errors where the microseconds or nanoseconds are not included in the end time.
@@ -184,7 +179,7 @@ function TraceDetail({
184179
queryFn: async () => {
185180
const start = mkUnixEpochFromMiliseconds(startTimeInMs);
186181
const end = start + 1;
187-
const q = `{ trace:id = "${traceId}" && nestedSetParent = -1 } | select (span:name, span.k8s.container.name, resource.service.namespace${
182+
const q = `{ trace:id = "${traceId}" && nestedSetParent = -1 } | select (span:name, resource.service.name${
188183
supportsChildCount ? ', childCount' : ''
189184
})`;
190185
const data = await search(datasourceUid, q, start, end);

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type SpanInfo = {
1919
name: string;
2020
childStatus: ChildStatus;
2121
childCount?: number;
22-
serviceNamespace?: string;
22+
serviceName?: string;
2323
};
2424

2525
export type TraceViewerHeaderProps = {

0 commit comments

Comments
 (0)