Skip to content

Commit 3b675df

Browse files
authored
Adapt the new trace v2 query protocol (#225)
1 parent 77b4c49 commit 3b675df

File tree

15 files changed

+358
-48
lines changed

15 files changed

+358
-48
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Release Notes.
1212
* Add the sub-command `alarm autocomplete-keys` and `alarm auto-complete-values` for alarm query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
1313
* Adapt the alarm message query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
1414
* Add the owner field in the `metrics exec` query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
15+
* Add the `trace-v2 list` command for adapt the new trace query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/225
16+
* Add the duration field in the `trace list` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/225
17+
* Remove the oldest `queryTraceFromColdStage` query call in the `trace list` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/225
1518

1619
### Bug Fixes
1720

assets/graphqls/trace/Trace.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
query ($traceId: ID!) {
19-
result: queryTrace(traceId: $traceId) {
18+
query ($traceId: ID!, $duration: Duration) {
19+
result: queryTrace(traceId: $traceId, duration: $duration) {
2020
spans {
2121
traceId
2222
segmentId

assets/graphqls/trace/ColdTrace.graphql renamed to assets/graphqls/trace/TraceWithoutDuration.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
query ($traceId: ID!, $duration: Duration!) {
19-
result: queryTraceFromColdStage(traceId: $traceId, duration: $duration) {
18+
query ($traceId: ID!) {
19+
result: queryTrace(traceId: $traceId) {
2020
spans {
2121
traceId
2222
segmentId
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
query ($condition: TraceQueryCondition){
19+
result: queryTraces(condition: $condition){
20+
traces {
21+
spans {
22+
traceId
23+
segmentId
24+
spanId
25+
parentSpanId
26+
refs {
27+
traceId
28+
parentSegmentId
29+
parentSpanId
30+
type
31+
}
32+
serviceCode
33+
serviceInstanceName
34+
startTime
35+
endTime
36+
endpointName
37+
type
38+
peer
39+
component
40+
isError
41+
layer
42+
tags {
43+
key value
44+
}
45+
logs {
46+
time data {
47+
key value
48+
}
49+
}
50+
attachedEvents {
51+
startTime {
52+
seconds nanos
53+
}
54+
event
55+
endTime {
56+
seconds nanos
57+
}
58+
tags {
59+
key value
60+
}
61+
summary {
62+
key value
63+
}
64+
}
65+
}
66+
}
67+
retrievedTimeRange {
68+
startTime endTime
69+
}
70+
}
71+
}

cmd/swctl/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/apache/skywalking-cli/internal/commands/records"
4444
"github.com/apache/skywalking-cli/internal/commands/service"
4545
"github.com/apache/skywalking-cli/internal/commands/trace"
46+
"github.com/apache/skywalking-cli/internal/commands/tracev2"
4647
intutil "github.com/apache/skywalking-cli/internal/util"
4748
"github.com/apache/skywalking-cli/pkg/logger"
4849
"github.com/apache/skywalking-cli/pkg/util"
@@ -99,6 +100,7 @@ services, service instances, etc.`
99100
service.Command,
100101
metrics.Command,
101102
trace.Command,
103+
tracev2.Command,
102104
healthcheck.Command,
103105
dashboard.Command,
104106
install.Command,

dist/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ The text of each license is also included at licenses/license-[project].txt.
200200
github.com/spf13/afero v1.2.2 Apache-2.0
201201
gomodules.xyz/jsonpatch/v2 v2.5.0 Apache-2.0
202202
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2 Apache-2.0
203-
google.golang.org/grpc v1.72.0 Apache-2.0
203+
google.golang.org/grpc v1.73.0 Apache-2.0
204204
gopkg.in/ini.v1 v1.51.0 Apache-2.0
205205
gopkg.in/yaml.v2 v2.4.0 Apache-2.0
206206
k8s.io/api v0.33.1 Apache-2.0
@@ -213,7 +213,7 @@ The text of each license is also included at licenses/license-[project].txt.
213213
sigs.k8s.io/controller-runtime v0.20.4 Apache-2.0
214214
sigs.k8s.io/randfill v1.0.0 Apache-2.0
215215
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 Apache-2.0
216-
skywalking.apache.org/repo/goapi v0.0.0-20250516073621-c1d2fb980695 Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc Apache-2.0
217217

218218
========================================================================
219219
Apache-2.0 and BSD-3-Clause licenses

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ require (
1414
github.com/spf13/viper v1.7.0
1515
github.com/urfave/cli/v2 v2.3.0
1616
golang.org/x/text v0.25.0
17-
google.golang.org/grpc v1.72.0
17+
google.golang.org/grpc v1.73.0
1818
gopkg.in/yaml.v2 v2.4.0
1919
k8s.io/apimachinery v0.33.1
2020
sigs.k8s.io/controller-runtime v0.20.4
21-
skywalking.apache.org/repo/goapi v0.0.0-20250516073621-c1d2fb980695
21+
skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc
2222
)
2323

2424
require (

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,16 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
326326
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
327327
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
328328
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
329-
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
330-
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
331-
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
332-
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
333-
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
334-
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
335-
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
336-
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
337-
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
338-
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
329+
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
330+
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
331+
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
332+
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
333+
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
334+
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
335+
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
336+
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
337+
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
338+
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
339339
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
340340
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
341341
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
@@ -487,8 +487,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2/go.
487487
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
488488
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
489489
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
490-
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
491-
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
490+
google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
491+
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
492492
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
493493
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
494494
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
@@ -543,5 +543,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.7.0 h1:qPeWmscJcXP0snki5IYF79Z8xrl8ETFxg
543543
sigs.k8s.io/structured-merge-diff/v4 v4.7.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps=
544544
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
545545
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
546-
skywalking.apache.org/repo/goapi v0.0.0-20250516073621-c1d2fb980695 h1:ED9fRO1rV5K3Kr5HQa1pQ87/xtXBmjYvT1EQfQ1VV3Y=
547-
skywalking.apache.org/repo/goapi v0.0.0-20250516073621-c1d2fb980695/go.mod h1:rTNGn2QrS+p1i2OaIBxlwQ/VrDSDc7OwRk/iWV+mU0k=
546+
skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc h1:HhlLDl0aOIgiIdJl9p0a7PHHdZbs9epKEnewB7AWdZs=
547+
skywalking.apache.org/repo/goapi v0.0.0-20250918024206-7be91673cadc/go.mod h1:Vj9vINJYsTQASPsbQ1i81YgH8nFC/Xds4GjcXvmRYwM=

internal/commands/trace/list.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ $ swctl trace ls --trace-id "321661b1-9a31-4e12-ad64-c8f6711f108d" --cold
102102
traceID := ctx.String("trace-id")
103103
tagStr := ctx.String("tags")
104104

105-
if coldStage && traceID != "" {
106-
trace, err := trace.ColdTrace(ctx.Context, duration, traceID)
107-
if err != nil {
108-
return err
109-
}
110-
return display.Display(ctx.Context, &displayable.Displayable{Data: trace})
111-
}
112-
113105
var tags []*api.SpanTag = nil
114106
if tagStr != "" {
115107
tagArr := strings.SplitSeq(tagStr, ",")

internal/commands/trace/trace.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222

2323
"github.com/urfave/cli/v2"
2424

25+
api "skywalking.apache.org/repo/goapi/query"
26+
27+
"github.com/apache/skywalking-cli/internal/commands/interceptor"
28+
"github.com/apache/skywalking-cli/internal/flags"
29+
"github.com/apache/skywalking-cli/internal/model"
2530
"github.com/apache/skywalking-cli/pkg/display"
2631
"github.com/apache/skywalking-cli/pkg/display/displayable"
2732
"github.com/apache/skywalking-cli/pkg/graphql/trace"
@@ -39,12 +44,33 @@ with specified options, like service name, endpoint name, etc.
3944
Examples:
4045
1. Query the trace details (spans) of id "321661b1-9a31-4e12-ad64-c8f6711f108d":
4146
$ swctl trace "321661b1-9a31-4e12-ad64-c8f6711f108d"`,
47+
Flags: flags.Flags(flags.DurationFlags),
4248
Action: func(ctx *cli.Context) error {
4349
if ctx.NArg() == 0 {
4450
return fmt.Errorf("command trace without sub command requires 1 trace id as argument")
4551
}
4652

47-
trace, err := trace.Trace(ctx.Context, ctx.Args().First())
53+
// if the user has set start or end, then we use the duration
54+
var duration *api.Duration
55+
start := ctx.String("start")
56+
end := ctx.String("end")
57+
if start != "" || end != "" {
58+
if err := interceptor.DurationInterceptor(ctx); err != nil {
59+
return err
60+
}
61+
step := ctx.Generic("step")
62+
coldStage := ctx.Bool("cold")
63+
start = ctx.String("start")
64+
end = ctx.String("end")
65+
duration = &api.Duration{
66+
Start: start,
67+
End: end,
68+
Step: step.(*model.StepEnumValue).Selected,
69+
ColdStage: &coldStage,
70+
}
71+
}
72+
73+
trace, err := trace.Trace(ctx.Context, duration, ctx.Args().First())
4874
if err != nil {
4975
return err
5076
}

0 commit comments

Comments
 (0)