mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
add http method to span name
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
This commit is contained in:
parent
02154293c7
commit
1aeb0ba314
@ -39,7 +39,7 @@ func WithTracing(handler http.Handler, tp trace.TracerProvider) http.Handler {
|
||||
if !exist {
|
||||
return "KubernetesAPI"
|
||||
}
|
||||
return getSpanNameFromRequestInfo(info)
|
||||
return getSpanNameFromRequestInfo(info, r)
|
||||
}),
|
||||
}
|
||||
wrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -55,9 +55,9 @@ func WithTracing(handler http.Handler, tp trace.TracerProvider) http.Handler {
|
||||
return otelhttp.NewHandler(wrappedHandler, "KubernetesAPI", opts...)
|
||||
}
|
||||
|
||||
func getSpanNameFromRequestInfo(info *request.RequestInfo) string {
|
||||
func getSpanNameFromRequestInfo(info *request.RequestInfo, r *http.Request) string {
|
||||
if !info.IsResourceRequest {
|
||||
return info.Path
|
||||
return r.Method + " " + info.Path
|
||||
}
|
||||
|
||||
spanName := "/" + info.APIPrefix
|
||||
@ -75,5 +75,5 @@ func getSpanNameFromRequestInfo(info *request.RequestInfo) string {
|
||||
if info.Subresource != "" {
|
||||
spanName += "/" + info.Subresource
|
||||
}
|
||||
return spanName
|
||||
return r.Method + " " + spanName
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes",
|
||||
name: "POST /api/v1/nodes",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
@ -428,7 +428,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes/{:name}",
|
||||
name: "GET /api/v1/nodes/{:name}",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
@ -518,7 +518,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes",
|
||||
name: "GET /api/v1/nodes",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
@ -636,7 +636,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes/{:name}",
|
||||
name: "PUT /api/v1/nodes/{:name}",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
@ -780,7 +780,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes/{:name}",
|
||||
name: "PATCH /api/v1/nodes/{:name}",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
@ -901,7 +901,7 @@ endpoint: %s`, listener.Addr().String())), os.FileMode(0755)); err != nil {
|
||||
},
|
||||
expectedTrace: []*spanExpectation{
|
||||
{
|
||||
name: "/api/v1/nodes/{:name}",
|
||||
name: "DELETE /api/v1/nodes/{:name}",
|
||||
attributes: map[string]func(*commonv1.AnyValue) bool{
|
||||
"http.user_agent": func(v *commonv1.AnyValue) bool {
|
||||
return strings.HasPrefix(v.GetStringValue(), "tracing.test")
|
||||
|
Loading…
Reference in New Issue
Block a user