-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Otel needs a root spans, if that is not passed from external service, we should start one ourselves. Also jobs shall retrieve these spans and not start new one.
- Loading branch information
1 parent
ac740ed
commit fb2173d
Showing
5 changed files
with
50 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/RHEnVision/provisioning-backend/internal/logging" | ||
"github.com/RHEnVision/provisioning-backend/internal/telemetry" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
const TraceName = telemetry.TracePrefix + "internal/middleware" | ||
|
||
// Telemetry middleware starts a new telemetry span for this request, | ||
// it tries to find the parent trace in the request, | ||
// if none is found, it starts new root span. | ||
func Telemetry(next http.Handler) http.Handler { | ||
fn := func(w http.ResponseWriter, r *http.Request) { | ||
var span trace.Span | ||
ctx := r.Context() | ||
|
||
// Edge request id | ||
edgeId := r.Header.Get("X-Rh-Edge-Request-Id") | ||
if edgeId != "" { | ||
ctx = logging.WithEdgeRequestId(ctx, edgeId) | ||
} | ||
|
||
ctx, span = otel.Tracer(TraceName).Start(ctx, r.URL.Path) | ||
|
||
// Store TraceID in response headers for easier debugging | ||
w.Header().Set("X-Trace-Id", span.SpanContext().TraceID().String()) | ||
|
||
next.ServeHTTP(w, r.WithContext(ctx)) | ||
} | ||
return http.HandlerFunc(fn) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters