Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
Log 404 in ingress proxy at INFO level
Improve Godocs
  • Loading branch information
bw19 committed Jun 1, 2024
1 parent 8af91af commit 8bc6e94
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
4 changes: 1 addition & 3 deletions connector/muffler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func (smp *muffler) ShouldSample(p sdktrace.SamplingParameters) sdktrace.Samplin
} else {
// Do not sample Prometheus requests to the metrics core microservice
// :8080/metrics.sys/collect or :8080/metrics.sys:443/collect
slash := strings.Index(p.Name, "/")
if slash >= 0 {
path := p.Name[slash+1:]
if _, path, ok := strings.Cut(p.Name, "/"); ok {
if path == "metrics.sys/collect" || path == "metrics.sys:443/collect" {
sample = false
}
Expand Down
10 changes: 6 additions & 4 deletions coreservices/httpingress/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,13 @@ func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else {
ww.Write([]byte(http.StatusText(statusCode) + " {" + span.TraceID() + "}"))
}
if statusCode < 500 {
svc.LogWarn(ctx, "Serving", log.Error(err), log.String("url", urlStr), log.Int("status", statusCode))
} else {
svc.LogError(ctx, "Serving", log.Error(err), log.String("url", urlStr), log.Int("status", statusCode))
logFunc := svc.LogError
if statusCode == http.StatusNotFound {
logFunc = svc.LogInfo
} else if statusCode < 500 {
logFunc = svc.LogWarn
}
logFunc(ctx, "Serving", log.Error(err), log.String("url", urlStr), log.Int("status", statusCode))

// OpenTelemetry: record the error, adding the request attributes
span.SetRequest(r)
Expand Down
12 changes: 6 additions & 6 deletions coreservices/httpingress/version-gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions trc/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,33 @@ var _ = Span(SpanImpl{}) // Ensure interface

// Span represents an operation that is being traced.
type Span interface {
// End completes the span.
// Updates to the span are not allowed after this method has been called.
End()
// SetError sets the status of the span to error.
SetError(err error)
// SetOK sets the status of the span to OK, with the indicated response status code.
SetOK(statusCode int)
// Log records a log event on the span.
Log(severity string, message string, fields ...log.Field)
// SetString tags the span during its creation.
SetString(k string, v string)
// SetStrings tags the span during its creation.
SetStrings(k string, v []string)
// SetBool tags the span during its creation.
SetBool(k string, v bool)
// SetInt tags the span during its creation.
SetInt(k string, v int)
// SetFloat tags the span during its creation.
SetFloat(k string, v float64)
// SetRequest tags the span with the request data.
// Warning: this has a large memory footprint.
SetRequest(r *http.Request)
// SetClientIP tags the span during its creation with the IP address and port number of the client.
SetClientIP(ip string)
// IsEmpty indicates if the span is not initialized.
IsEmpty() bool
// TraceID is an identifier that groups related spans together.
TraceID() string
}

Expand All @@ -52,10 +67,8 @@ func NewSpan(ts trace.Span) Span {
return SpanImpl{Span: ts}
}

// End completes the Span. The Span is considered complete and ready to be
// delivered through the rest of the telemetry pipeline after this method
// is called. Therefore, updates to the Span are not allowed after this
// method has been called.
// End completes the span.
// Updates to the span are not allowed after this method has been called.
func (s SpanImpl) End() {
if s.Span == nil {
return
Expand Down Expand Up @@ -184,7 +197,8 @@ func (s SpanImpl) SetFloat(k string, v float64) {
s.Span.SetAttributes(attribute.Float64(k, v))
}

// SetRequest tags the span during its creation with the request data.
// SetRequest tags the span with the request data.
// Warning: this has a large memory footprint.
func (s SpanImpl) SetRequest(r *http.Request) {
if s.Span == nil {
return
Expand Down

0 comments on commit 8bc6e94

Please sign in to comment.