Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit d115846

Browse files
authored
cody-gateway: treat incoming traces as links instead of parents (#54235)
Lately I've noticed many (most?) of our Sentry events come with `TraceId` that 404's on Cloud Trace, which kind of defeats the whole purpose of our tracing. I've spot-checked and see that all our traces in Cloud Trace have corresponding `Request` logs, but when attempting the inverse we often get a 404 in Cloud Trace. I think the problem is that we are treating incoming traces as parents instead of linked traces. Treating the incoming request as a parent is cool because you get to see the whole thing end-to-end across projects, but it has the issue where half our traces are missing parents, and I think this is what causes logs to include traces that 404 when you query it on Cloud Trace Was thinking of performing the parent/linking based on whether the request emits a ShouldTrace policy, but we have the same issue with on-prem customers etc if they enable tracing we'll end up with traces missing parents on our end that causes misbehaviour in Cloud Trace. I think I'm going to revert our usage of having remote traces be treated as parents, and just preserve them as links instead. This still gives us some bidirectional linking: - In Sourcegraph/App/etc, we keep the return trace/span in trace attributes and also send it back to clients. - In Cody Gateway, the span link will point us to the Sourcegraph trace ## Test plan CI
1 parent 9f598ab commit d115846

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

enterprise/cmd/cody-gateway/internal/httpapi/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/cmd/cody-gateway/internal/httpapi/diagnostics.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/sourcegraph/log"
1010
"github.com/sourcegraph/log/hook"
1111
"github.com/sourcegraph/log/output"
12+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1213

1314
"github.com/sourcegraph/sourcegraph/enterprise/cmd/cody-gateway/internal/actor"
1415
"github.com/sourcegraph/sourcegraph/enterprise/cmd/cody-gateway/internal/auth"
@@ -96,8 +97,11 @@ func NewDiagnosticsHandler(baseLogger log.Logger, next http.Handler, secret stri
9697

9798
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9899
if strings.HasPrefix(r.URL.Path, "/-/") {
99-
instrumentation.HTTPMiddleware("diagnostics", requestlogger.Middleware(baseLogger, handler)).
100-
ServeHTTP(w, r)
100+
instrumentation.HTTPMiddleware(
101+
"diagnostics",
102+
requestlogger.Middleware(baseLogger, handler),
103+
otelhttp.WithPublicEndpoint(),
104+
).ServeHTTP(w, r)
101105
return
102106
}
103107

enterprise/cmd/cody-gateway/internal/httpapi/handler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/gorilla/mux"
77
"github.com/sourcegraph/log"
8+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
89

910
"github.com/sourcegraph/sourcegraph/enterprise/cmd/cody-gateway/internal/auth"
1011
"github.com/sourcegraph/sourcegraph/enterprise/cmd/cody-gateway/internal/events"
@@ -51,6 +52,7 @@ func NewHandler(logger log.Logger, eventLogger events.Logger, rs limiter.RedisSt
5152
),
5253
),
5354
),
55+
otelhttp.WithPublicEndpoint(),
5456
),
5557
)
5658
}
@@ -71,6 +73,7 @@ func NewHandler(logger log.Logger, eventLogger events.Logger, rs limiter.RedisSt
7173
),
7274
),
7375
),
76+
otelhttp.WithPublicEndpoint(),
7477
),
7578
)
7679

@@ -82,6 +85,7 @@ func NewHandler(logger log.Logger, eventLogger events.Logger, rs limiter.RedisSt
8285
embeddings.NewListHandler(),
8386
),
8487
),
88+
otelhttp.WithPublicEndpoint(),
8589
),
8690
)
8791

@@ -102,6 +106,7 @@ func NewHandler(logger log.Logger, eventLogger events.Logger, rs limiter.RedisSt
102106
),
103107
),
104108
),
109+
otelhttp.WithPublicEndpoint(),
105110
),
106111
)
107112
}

0 commit comments

Comments
 (0)