Skip to content

Commit 5d8635a

Browse files
authored
Add support for read-only metadata (#28)
1 parent b46fe0a commit 5d8635a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/OpenTracing.Contrib.Grpc/GrpcTraceLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void ResponseHeader(Metadata metadata)
3535
_span.Log(new Dictionary<string, object>
3636
{
3737
{ LogFields.Event, "Response headers received" },
38-
{ "data", metadata }
38+
{ "data", metadata?.ToReadableString() }
3939
});
4040
}
4141

src/OpenTracing.Contrib.Grpc/Handler/InterceptedClientHandler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Globalization;
3+
using System.Linq;
34
using System.Threading.Tasks;
45
using Grpc.Core;
56
using Grpc.Core.Interceptors;
@@ -45,10 +46,19 @@ public InterceptedClientHandler(ClientTracingConfiguration configuration, Client
4546

4647
private CallOptions ApplyConfigToCallOptions(CallOptions callOptions)
4748
{
48-
if (callOptions.Headers == null)
49+
var headers = callOptions.Headers;
50+
if (headers == null || headers.IsReadOnly)
4951
{
50-
// Add empty metadata to options:
51-
callOptions = callOptions.WithHeaders(new Metadata());
52+
// Use empty, writable metadata as base:
53+
var metadata = new Metadata();
54+
55+
// Copy elements since it was read-only if it had elements:
56+
foreach (var header in headers ?? Enumerable.Empty<Metadata.Entry>())
57+
{
58+
metadata.Add(header);
59+
}
60+
61+
callOptions = callOptions.WithHeaders(metadata);
5262
}
5363

5464
if (_configuration.WaitForReady && callOptions.IsWaitForReady != _configuration.WaitForReady)

0 commit comments

Comments
 (0)