Skip to content

Commit f04146d

Browse files
committed
add a bunch of enrich_span functions
1 parent 591b61d commit f04146d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/log/trace_async.ml

+64
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,67 @@ let with_span ?(level = Trace.get_default_level ()) ?parent ?data ?__FUNCTION__
7070
f
7171
else
7272
f Trace.Collector.dummy_explicit_span
73+
74+
open struct
75+
let cons_assoc_opt_ name x l =
76+
match x with
77+
| None -> l
78+
| Some v -> (name, v) :: l
79+
end
80+
81+
let enrich_span_process (span : Trace.explicit_span) : unit =
82+
Trace.add_data_to_manual_span span
83+
[
84+
"process.runtime.name", `String "ocaml";
85+
"process.runtime.version", `String Sys.ocaml_version;
86+
]
87+
88+
let enrich_span_service ~name ~namespace ~instance_id ~version
89+
(span : Trace.explicit_span) : unit =
90+
Trace.add_data_to_manual_span span
91+
[
92+
"service.name", `String name;
93+
"service.namespace", `String namespace;
94+
"service.instance.id", `String instance_id;
95+
"service.version", `String version;
96+
]
97+
98+
let enrich_span_deployment ?id ?name ~deployment (span : Trace.explicit_span) :
99+
unit =
100+
let data =
101+
[ "deployment.environment.name", `String deployment ]
102+
|> cons_assoc_opt_ "deployment.id" id
103+
|> cons_assoc_opt_ "deployment.name" name
104+
in
105+
Trace.add_data_to_manual_span span data
106+
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

0 commit comments

Comments
 (0)