From 3b859ba3980307f62ae9b3fa27df83e3a48c45bf Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 14 Oct 2024 10:40:29 +0100 Subject: [PATCH] Add headers to outgoing http requests for Open Telemetry (#141) * Add otel headers to outgoing http client requests * format --- src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs | 1 + src/Speckle.Sdk/Logging/ISdkActivity.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs b/src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs index 998ad743..4998252d 100644 --- a/src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs +++ b/src/Speckle.Sdk/Helpers/SpeckleHttpClientHandler.cs @@ -39,6 +39,7 @@ CancellationToken cancellationToken context.Add("retryCount", 0); request.Headers.Add("x-request-id", context.CorrelationId.ToString()); + activity?.InjectHeaders((k, v) => request.Headers.TryAddWithoutValidation(k, v)); var policyResult = await _resiliencePolicy .ExecuteAndCaptureAsync( diff --git a/src/Speckle.Sdk/Logging/ISdkActivity.cs b/src/Speckle.Sdk/Logging/ISdkActivity.cs index c7cccaa3..d832c769 100644 --- a/src/Speckle.Sdk/Logging/ISdkActivity.cs +++ b/src/Speckle.Sdk/Logging/ISdkActivity.cs @@ -6,6 +6,8 @@ public interface ISdkActivity : IDisposable void RecordException(Exception e); string TraceId { get; } void SetStatus(SdkActivityStatusCode code); + + void InjectHeaders(Action header); } public enum SdkActivityStatusCode