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

feat(tracing): support linking to upstream targets in span attributes #1838

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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 @@ -74,6 +74,7 @@ const ATTRIBUTE_KEY_TO_ENTITY = {
[SPAN_ATTRIBUTES.KONG_ROUTE_ID.name]: 'routes',
[SPAN_ATTRIBUTES.KONG_CONSUMER_ID.name]: 'consumers',
[SPAN_ATTRIBUTES.KONG_PLUGIN_ID.name]: 'plugins',
[SPAN_ATTRIBUTES.KONG_TARGET_ID.name]: 'targets',
[SPAN_ATTRIBUTES.KONG_UPSTREAM_ID.name]: 'upstreams',
}

Expand Down Expand Up @@ -103,15 +104,29 @@ const entityRequest = computed(() => {
entityId: value,
}

// Check if this is a plugin ID attribute
if (props.keyValue.key === SPAN_ATTRIBUTES.KONG_PLUGIN_ID.name) {
// We will need to parse the plugin name from the span name
request.plugin = getPhaseAndPlugin(props.span.name)?.[1]
if (!request.plugin) {
// Missing plugin name
console.warn(`Failed to parse plugin name from span name "${props.span.name}"`)
return undefined
switch (props.keyValue.key) {
case SPAN_ATTRIBUTES.KONG_PLUGIN_ID.name: {
// We will need to parse the plugin name from the span name
request.plugin = getPhaseAndPlugin(props.span.name)?.[1]
if (!request.plugin) {
// Missing plugin name
console.warn(`Failed to parse plugin name from span name "${props.span.name}"`)
return undefined
}
break
}
case SPAN_ATTRIBUTES.KONG_TARGET_ID.name: {
const upstreamIdAttrValue = props.span.attributes?.find((attr) => attr.key === SPAN_ATTRIBUTES.KONG_UPSTREAM_ID.name)?.value
const upstreamId = upstreamIdAttrValue && unwrapAnyValue<string>(upstreamIdAttrValue)
if (!upstreamId) {
console.warn(`Failed to look up the upstream ID for the upstream target in the span "${props.span.name}"`)
return undefined
}
request.upstream = upstreamId
break
}
sumimakito marked this conversation as resolved.
Show resolved Hide resolved
default:
break
}

return request
Expand Down
5 changes: 5 additions & 0 deletions packages/core/tracing/src/types/trace-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface EntityRequest {
* This field is only available for entities of the 'plugins' type.
*/
plugin?: string
/**
* The ID of the upstream.
* This field is only available for entities of the 'targets' type.
*/
upstream?: string
}

export interface TraceViewerConfig {
Expand Down
Loading