From 5e8affe508339ff6557da56319c4ecc4ebfd0365 Mon Sep 17 00:00:00 2001 From: Matt Bray Date: Thu, 24 Mar 2022 22:06:02 +0000 Subject: [PATCH] fix(cohttp): use correct scope for traceparent header --- .../cohttp/opentelemetry_cohttp_lwt.ml | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml index 6fb98ec4..57432fe4 100644 --- a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml +++ b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml @@ -162,17 +162,11 @@ let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client) let attrs = attrs_for ~uri ~meth () in (trace_id, parent, attrs) - let add_traceparent headers = - match scope with - | None -> headers - | Some scope -> - let module Traceparent = Otel.Trace_context.Traceparent in - let headers = match headers with | None -> Header.init () | Some headers -> headers in - let headers = - Header.add headers Traceparent.name - (Traceparent.to_value ~trace_id:scope.trace_id ~parent_id:scope.span_id ()) - in - Some headers + let add_traceparent (scope : Otel.Trace.scope) headers = + let module Traceparent = Otel.Trace_context.Traceparent in + let headers = match headers with | None -> Header.init () | Some headers -> headers in + Header.add headers Traceparent.name + (Traceparent.to_value ~trace_id:scope.trace_id ~parent_id:scope.span_id ()) let call ?ctx ?headers ?body ?chunked meth (uri : Uri.t) : (Response.t * Cohttp_lwt.Body.t) Lwt.t = let (trace_id, parent, attrs) = context_for ~uri ~meth in @@ -182,8 +176,8 @@ let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client) ?parent ~attrs (fun scope -> - let headers = add_traceparent headers in - let* (res, body) = C.call ?ctx ?headers ?body ?chunked meth uri in + let headers = add_traceparent scope headers in + let* (res, body) = C.call ?ctx ~headers ?body ?chunked meth uri in Otel.Trace.add_attrs scope (fun () -> let code = Response.status res in let code = Code.code_of_status code in