Skip to content

Commit f6f4504

Browse files
committed
feat(trace_async): auto enrichment hooks
1 parent 1fef4bc commit f6f4504

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

src/log/trace_async.ml

+15-30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ let add_exn_to_span (sp : Trace.explicit_span) (exn : exn)
2323
]
2424

2525
open struct
26+
let auto_enrich_span_l_ : (Trace.explicit_span -> unit) list Atomic.t =
27+
Atomic.make []
28+
2629
let with_span_real_ ~level ?parent ?data ?__FUNCTION__ ~__FILE__ ~__LINE__
2730
name f =
2831
let span =
@@ -43,6 +46,10 @@ open struct
4346
(* set current span as parent, for children *)
4447
LS.set_in_local_hmap k_parent_scope span;
4548

49+
(* apply automatic enrichment *)
50+
if span.span != Trace.Collector.dummy_span then
51+
List.iter (fun f -> f span) (Atomic.get auto_enrich_span_l_);
52+
4653
(* cleanup *)
4754
let finally () =
4855
(* restore previous parent span *)
@@ -104,33 +111,11 @@ let enrich_span_deployment ?id ?name ~deployment (span : Trace.explicit_span) :
104111
in
105112
Trace.add_data_to_manual_span span data
106113

107-
module Attributes = struct
108-
module HTTP = struct
109-
let error_type = "error.type"
110-
let request_method = "http.request.method"
111-
let route = "http.route"
112-
let url_full = "url.full"
113-
114-
(** HTTP status code, int *)
115-
let response_status_code = "http.response.status_code"
116-
117-
let server_address = "server.address"
118-
let server_port = "server.port"
119-
120-
(** http or https *)
121-
let url_scheme = "url.scheme"
122-
end
123-
124-
(** https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/host.md *)
125-
module Host = struct
126-
let id = "host.id"
127-
let name = "host.name"
128-
let type_ = "host.type"
129-
let arch = "host.arch"
130-
let ip = "host.ip"
131-
let mac = "host.mac"
132-
let image_id = "host.image.id"
133-
let image_name = "host.image.name"
134-
let image_version = "host.image.version"
135-
end
136-
end
114+
(** Add a hook that will be called on every explicit span *)
115+
let add_auto_enrich_span (f : Trace.explicit_span -> unit) : unit =
116+
while
117+
let l = Atomic.get auto_enrich_span_l_ in
118+
not (Atomic.compare_and_set auto_enrich_span_l_ l (f :: l))
119+
do
120+
()
121+
done

0 commit comments

Comments
 (0)