|
6 | 6 | import io.grpc.Context;
|
7 | 7 | import io.grpc.stub.StreamObserver;
|
8 | 8 | import io.reactivex.rxjava3.core.Observable;
|
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.Collection; |
9 | 11 | import java.util.Map;
|
10 | 12 | import java.util.Map.Entry;
|
11 | 13 | import java.util.Optional;
|
@@ -37,10 +39,12 @@ private DefaultGraphQlGrpcContext(
|
37 | 39 | GraphQlRequestContext requestContext,
|
38 | 40 | PlatformRequestContextBuilder platformRequestContextBuilder) {
|
39 | 41 | Map<String, String> grpcHeaders =
|
40 |
| - this.flattenOptionalMap( |
41 |
| - Map.of( |
42 |
| - AUTHORIZATION_HEADER, this.extractAuthorizationHeader(requestContext), |
43 |
| - TENANT_ID_HEADER_KEY, this.extractTenantId(requestContext))); |
| 42 | + this.mergeMaps( |
| 43 | + requestContext.getTracingContextHeaders(), |
| 44 | + this.flattenOptionalMap( |
| 45 | + Map.of( |
| 46 | + AUTHORIZATION_HEADER, this.extractAuthorizationHeader(requestContext), |
| 47 | + TENANT_ID_HEADER_KEY, this.extractTenantId(requestContext)))); |
44 | 48 |
|
45 | 49 | RequestContext platformContext = platformRequestContextBuilder.build(grpcHeaders);
|
46 | 50 | this.grpcContext = this.buildGrpcContext(platformContext);
|
@@ -87,5 +91,13 @@ private Map<String, String> flattenOptionalMap(Map<String, Optional<String>> opt
|
87 | 91 | .flatMap(Optional::stream)
|
88 | 92 | .collect(Collectors.toUnmodifiableMap(Entry::getKey, Entry::getValue));
|
89 | 93 | }
|
| 94 | + |
| 95 | + @SafeVarargs |
| 96 | + private Map<String, String> mergeMaps(Map<String, String>... maps) { |
| 97 | + return Arrays.stream(maps) |
| 98 | + .map(Map::entrySet) |
| 99 | + .flatMap(Collection::stream) |
| 100 | + .collect(Collectors.toUnmodifiableMap(Entry::getKey, Entry::getValue)); |
| 101 | + } |
90 | 102 | }
|
91 | 103 | }
|
0 commit comments