@@ -23,6 +23,9 @@ let add_exn_to_span (sp : Trace.explicit_span) (exn : exn)
23
23
]
24
24
25
25
open struct
26
+ let auto_enrich_span_l_ : (Trace.explicit_span -> unit) list Atomic.t =
27
+ Atomic. make []
28
+
26
29
let with_span_real_ ~level ?parent ?data ?__FUNCTION__ ~__FILE__ ~__LINE__
27
30
name f =
28
31
let span =
@@ -43,6 +46,10 @@ open struct
43
46
(* set current span as parent, for children *)
44
47
LS. set_in_local_hmap k_parent_scope span;
45
48
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
+
46
53
(* cleanup *)
47
54
let finally () =
48
55
(* restore previous parent span *)
@@ -104,33 +111,11 @@ let enrich_span_deployment ?id ?name ~deployment (span : Trace.explicit_span) :
104
111
in
105
112
Trace. add_data_to_manual_span span data
106
113
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