-
Notifications
You must be signed in to change notification settings - Fork 592
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
Accept both B3 and TraceContext style tracing #3388
Changes from 3 commits
eae9465
85c85b1
b5988cf
383799c
b864cac
e6b483b
f5e5f48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ import ( | |
"log" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
"go.opencensus.io/plugin/ochttp" | ||
"knative.dev/pkg/tracing/propagation/tracecontextb3" | ||
) | ||
|
||
var ( | ||
|
@@ -61,7 +63,11 @@ func main() { | |
// parse the command line flags | ||
flag.Parse() | ||
|
||
t, err := cloudevents.NewHTTP(cloudevents.WithPort(8080)) | ||
t, err := cloudevents.NewHTTP( | ||
cloudevents.WithPort(8080), | ||
cloudevents.WithRoundTripper(&ochttp.Transport{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This image uses only the receiver, so you don't need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Propagation: tracecontextb3.TraceContextEgress, | ||
})) | ||
if err != nil { | ||
log.Fatalf("failed to create transport, %v", err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,10 @@ import ( | |
"log" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
"go.opencensus.io/plugin/ochttp" | ||
"go.uber.org/zap" | ||
|
||
"knative.dev/eventing/pkg/tracing" | ||
"knative.dev/pkg/tracing/propagation/tracecontextb3" | ||
) | ||
|
||
var ( | ||
|
@@ -72,7 +73,11 @@ func main() { | |
log.Fatalf("Unable to setup trace publishing: %v", err) | ||
} | ||
|
||
t, err := cloudevents.NewHTTP(cloudevents.WithPort(8080)) | ||
t, err := cloudevents.NewHTTP( | ||
cloudevents.WithPort(8080), | ||
cloudevents.WithRoundTripper(&ochttp.Transport{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Propagation: tracecontextb3.TraceContextEgress, | ||
})) | ||
if err != nil { | ||
log.Fatalf("failed to create transport, %v", err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package propagation | ||
|
||
import ( | ||
"net/http" | ||
|
||
"go.opencensus.io/trace" | ||
"go.opencensus.io/trace/propagation" | ||
) | ||
|
||
// HTTPFormatSequence is a propagation.HTTPFormat that applies multiple other propagation formats. | ||
// For incoming requests, it will use the first SpanContext it can find, checked in the order of | ||
// HTTPFormatSequence.Ingress. | ||
// For outgoing requests, it will apply all the formats to the outgoing request, in the order of | ||
// HTTPFormatSequence.Egress. | ||
type HTTPFormatSequence struct { | ||
Ingress []propagation.HTTPFormat | ||
Egress []propagation.HTTPFormat | ||
} | ||
|
||
var _ propagation.HTTPFormat = (*HTTPFormatSequence)(nil) | ||
|
||
// SpanContextFromRequest satisfies the propagation.HTTPFormat interface. | ||
func (h *HTTPFormatSequence) SpanContextFromRequest(req *http.Request) (trace.SpanContext, bool) { | ||
for _, format := range h.Ingress { | ||
if sc, ok := format.SpanContextFromRequest(req); ok { | ||
return sc, true | ||
} | ||
} | ||
return trace.SpanContext{}, false | ||
} | ||
|
||
// SpanContextToRequest satisfies the propagation.HTTPFormat interface. | ||
func (h *HTTPFormatSequence) SpanContextToRequest(sc trace.SpanContext, req *http.Request) { | ||
for _, format := range h.Egress { | ||
format.SpanContextToRequest(sc, req) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need tracing in performance images, it's not even configured
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.