Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Newdigate <andrew@gitlab.com>2018-12-10 13:41:20 +0300
committerAndrew Newdigate <andrew@gitlab.com>2018-12-10 18:47:44 +0300
commitd901fa88ae47428576c36bf8ebc99d9978042f9e (patch)
treea0cc04e58afb77fec7826a1ee908109e83be5319
parent52d67af596f75e82305f16ff0f27a9e0e77d57e1 (diff)
Log correlation_id field in structured logging outputpatch-1.7.1
-rw-r--r--changelogs/unreleased/add-correlation_id.yml5
-rw-r--r--internal/middleware/metadatahandler/metadatahandler.go9
-rw-r--r--internal/server/server.go4
3 files changed, 16 insertions, 2 deletions
diff --git a/changelogs/unreleased/add-correlation_id.yml b/changelogs/unreleased/add-correlation_id.yml
new file mode 100644
index 000000000..f88776ea9
--- /dev/null
+++ b/changelogs/unreleased/add-correlation_id.yml
@@ -0,0 +1,5 @@
+---
+title: Log correlation_id field in structured logging output
+merge_request: 995
+author:
+type: other
diff --git a/internal/middleware/metadatahandler/metadatahandler.go b/internal/middleware/metadatahandler/metadatahandler.go
index 06b67b945..5091e6654 100644
--- a/internal/middleware/metadatahandler/metadatahandler.go
+++ b/internal/middleware/metadatahandler/metadatahandler.go
@@ -5,6 +5,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/internal/helper"
+ "gitlab.com/gitlab-org/labkit/correlation"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
@@ -41,6 +42,8 @@ const ClientNameKey = "grpc.meta.client_name"
// AuthVersionKey is the key used in ctx_tags to store the auth version
const AuthVersionKey = "grpc.meta.auth_version"
+const correlationIDKey = "correlation_id"
+
// Unknown client and feature. Matches the prometheus grpc unknown value
const unknownValue = "unknown"
@@ -88,6 +91,12 @@ func addMetadataTags(ctx context.Context) metadataTags {
tags.Set(AuthVersionKey, authInfo.Version)
}
+ // This is a stop-gap approach to logging correlation_ids
+ correlationID := correlation.ExtractFromContext(ctx)
+ if correlationID != "" {
+ tags.Set(correlationIDKey, correlationID)
+ }
+
return metaTags
}
diff --git a/internal/server/server.go b/internal/server/server.go
index a29405c0d..cf5630bad 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -74,6 +74,7 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
opts := []grpc.ServerOption{
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_ctxtags.StreamServerInterceptor(ctxTagOpts...),
+ grpccorrelation.StreamServerCorrelationInterceptor(), // Must be above the metadata handler
metadatahandler.StreamInterceptor,
grpc_prometheus.StreamServerInterceptor,
grpc_logrus.StreamServerInterceptor(logrusEntry),
@@ -81,13 +82,13 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
cancelhandler.Stream, // Should be below LogHandler
lh.StreamInterceptor(),
auth.StreamServerInterceptor(),
- grpccorrelation.StreamServerCorrelationInterceptor(),
// Panic handler should remain last so that application panics will be
// converted to errors and logged
panichandler.StreamPanicHandler,
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_ctxtags.UnaryServerInterceptor(ctxTagOpts...),
+ grpccorrelation.UnaryServerCorrelationInterceptor(), // Must be above the metadata handler
metadatahandler.UnaryInterceptor,
grpc_prometheus.UnaryServerInterceptor,
grpc_logrus.UnaryServerInterceptor(logrusEntry),
@@ -95,7 +96,6 @@ func createNewServer(rubyServer *rubyserver.Server, secure bool) *grpc.Server {
cancelhandler.Unary, // Should be below LogHandler
lh.UnaryInterceptor(),
auth.UnaryServerInterceptor(),
- grpccorrelation.UnaryServerCorrelationInterceptor(),
// Panic handler should remain last so that application panics will be
// converted to errors and logged
panichandler.UnaryPanicHandler,