Skip to content

Commit

Permalink
feat(tracing): support linking to upstream targets in span attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sumimakito committed Dec 6, 2024
1 parent 67b1e8e commit 8b199c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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,14 +104,26 @@ 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
}
}
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

0 comments on commit 8b199c0

Please sign in to comment.