1616
1717CONFIG_DIR = "/etc/otelcol/config.d"
1818EXPORTER_NAME = "otlp/github_runner_optin"
19+ BATCH_PROCESSOR_NAME = "batch/github_runner_optin"
20+ SERVICE_NAME = "self-hosted-runner"
21+ LOKI_RESOURCE_LABELS = (
22+ "service.name" ,
23+ "github.repository" ,
24+ "github.runner" ,
25+ "github.workflow" ,
26+ "github.job" ,
27+ "github.run.id" ,
28+ "github.run.attempt" ,
29+ )
30+ LOKI_ATTRIBUTE_LABELS = (
31+ "log.file.name" ,
32+ "log.file.path" ,
33+ )
1934SNAP_CMD = Path ("/usr/bin/snap" )
2035SUDO_CMD = Path ("/usr/bin/sudo" )
2136MKDIR_CMD = Path ("/usr/bin/mkdir" )
@@ -174,16 +189,29 @@ def exporter_exists_in_config_dir(
174189def build_resource_attributes () -> list [dict [str , str ]]:
175190 """Build static GitHub resource attributes attached to forwarded logs."""
176191 attrs = [
192+ ("service.name" , SERVICE_NAME ),
177193 ("github.repository" , os .getenv ("GITHUB_REPOSITORY" , "unknown" )),
178194 ("github.runner" , os .getenv ("RUNNER_NAME" , "unknown" )),
179195 ("github.workflow" , os .getenv ("GITHUB_WORKFLOW" , "unknown" )),
180196 ("github.job" , os .getenv ("GITHUB_JOB" , "unknown" )),
181197 ("github.run.id" , os .getenv ("GITHUB_RUN_ID" , "unknown" )),
182198 ("github.run.attempt" , os .getenv ("GITHUB_RUN_ATTEMPT" , "unknown" )),
199+ ("loki.resource.labels" , ", " .join (LOKI_RESOURCE_LABELS )),
183200 ]
184201 return [{"key" : key , "value" : value , "action" : "upsert" } for key , value in attrs ]
185202
186203
204+ def build_log_attribute_actions () -> list [dict [str , str ]]:
205+ """Build log-attribute actions for Loki label promotion hints."""
206+ return [
207+ {
208+ "key" : "loki.attribute.labels" ,
209+ "value" : ", " .join (LOKI_ATTRIBUTE_LABELS ),
210+ "action" : "upsert" ,
211+ }
212+ ]
213+
214+
187215def build_config (
188216 files : Sequence [str ],
189217 resolved_endpoint : str ,
@@ -196,18 +224,28 @@ def build_config(
196224 "filelog/github_runner_optin" : {
197225 "include" : list (files ),
198226 "start_at" : "end" ,
227+ "include_file_name" : True ,
228+ "include_file_path" : True ,
199229 }
200230 },
201231 "processors" : {
202232 "resource/github_runner_optin" : {
203233 "attributes" : build_resource_attributes (),
204- }
234+ },
235+ "attributes/github_runner_optin" : {
236+ "actions" : build_log_attribute_actions (),
237+ },
238+ BATCH_PROCESSOR_NAME : {},
205239 },
206240 "service" : {
207241 "pipelines" : {
208242 "logs/github_runner_optin" : {
209243 "receivers" : ["filelog/github_runner_optin" ],
210- "processors" : ["resource/github_runner_optin" , "batch" ],
244+ "processors" : [
245+ "resource/github_runner_optin" ,
246+ "attributes/github_runner_optin" ,
247+ BATCH_PROCESSOR_NAME ,
248+ ],
211249 "exporters" : [exporter_name ],
212250 }
213251 }
@@ -378,4 +416,4 @@ def main():
378416
379417
380418if __name__ == "__main__" :
381- main ()
419+ main ()
0 commit comments