@@ -18,21 +18,26 @@ import (
18
18
"github.com/jaegertracing/jaeger/model"
19
19
"github.com/jaegertracing/jaeger/pkg/bearertoken"
20
20
_ "github.com/jaegertracing/jaeger/pkg/gogocodec" // force gogo codec registration
21
+ "github.com/jaegertracing/jaeger/pkg/tenancy"
21
22
"github.com/jaegertracing/jaeger/proto-gen/storage_v1"
22
23
"github.com/jaegertracing/jaeger/storage/dependencystore"
23
24
"github.com/jaegertracing/jaeger/storage/spanstore"
24
25
)
25
26
26
- // BearerTokenKey is the key name for the bearer token context value.
27
- const BearerTokenKey = "bearer.token"
27
+ const (
28
+ // BearerTokenKey is the key name for the bearer token context value.
29
+ BearerTokenKey = "bearer.token"
30
+ // TenantKey is the key name for the x-tenant context value.
31
+ TenantKey = "x.tenant"
32
+ )
28
33
29
34
var (
30
35
_ StoragePlugin = (* GRPCClient )(nil )
31
36
_ ArchiveStoragePlugin = (* GRPCClient )(nil )
32
37
_ PluginCapabilities = (* GRPCClient )(nil )
33
38
34
39
// upgradeContext composites several steps of upgrading context
35
- upgradeContext = composeContextUpgradeFuncs (upgradeContextWithBearerToken )
40
+ upgradeContext = composeContextUpgradeFuncs (upgradeContextWithBearerToken , upgradeContextWithXTenant )
36
41
)
37
42
38
43
// GRPCClient implements shared.StoragePlugin and reads/writes spans and dependencies
@@ -88,6 +93,22 @@ func upgradeContextWithBearerToken(ctx context.Context) context.Context {
88
93
return ctx
89
94
}
90
95
96
+ // upgradeContextWithXTenant turns the context into a gRPC outgoing context with x tenant
97
+ // in the request metadata, if the original context has x-tenant attached.
98
+ // Otherwise returns original context.
99
+ func upgradeContextWithXTenant (ctx context.Context ) context.Context {
100
+ tenant := tenancy .GetTenant (ctx )
101
+ if tenant != "" {
102
+ md , ok := metadata .FromOutgoingContext (ctx )
103
+ if ! ok {
104
+ md = metadata .New (nil )
105
+ }
106
+ md .Set (TenantKey , tenant )
107
+ return metadata .NewOutgoingContext (ctx , md )
108
+ }
109
+ return ctx
110
+ }
111
+
91
112
// DependencyReader implements shared.StoragePlugin.
92
113
func (c * GRPCClient ) DependencyReader () dependencystore.Reader {
93
114
return c
0 commit comments