1111
1212@mock .patch .object (detector , "get_ci_provider" , return_value = "github_actions" )
1313@mock .patch .object (detector , "get_job_name" , return_value = "JOB" )
14+ @mock .patch .object (detector , "get_cicd_pipeline_run_id" , return_value = 123 )
15+ @mock .patch .object (detector , "get_cicd_pipeline_run_attempt" , return_value = 1 )
1416@mock .patch .object (
1517 detector ,
1618 "get_head_sha" ,
@@ -20,6 +22,8 @@ async def test_parse(
2022 _get_ci_provider : mock .Mock ,
2123 _get_job_name : mock .Mock ,
2224 _get_head_sha : mock .Mock ,
25+ _get_cicd_pipeline_run_id : mock .Mock ,
26+ _get_cicd_pipeline_run_attempt : mock .Mock ,
2327) -> None :
2428 filename = pathlib .Path (__file__ ).parent / "junit_example.xml"
2529 spans = await junit .junit_to_spans (
@@ -32,6 +36,17 @@ async def test_parse(
3236 trace_id = "0x" + opentelemetry .trace .span .format_trace_id (
3337 spans [1 ].context .trace_id ,
3438 )
39+ resource_attributes = {
40+ "cicd.pipeline.name" : "JOB" ,
41+ "cicd.pipeline.run.id" : 123 ,
42+ "cicd.pipeline.run.attempt" : 1 ,
43+ "cicd.provider.name" : "github_actions" ,
44+ "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
45+ "service.name" : "unknown_service" ,
46+ "telemetry.sdk.language" : "python" ,
47+ "telemetry.sdk.name" : "opentelemetry" ,
48+ "telemetry.sdk.version" : anys .ANY_STR ,
49+ }
3550 assert dictified_spans == [
3651 {
3752 "attributes" : {
@@ -52,15 +67,7 @@ async def test_parse(
5267 "name" : "Tests.Registration" ,
5368 "parent_id" : None ,
5469 "resource" : {
55- "attributes" : {
56- "cicd.pipeline.name" : "JOB" ,
57- "cicd.provider.name" : "github_actions" ,
58- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
59- "service.name" : "unknown_service" ,
60- "telemetry.sdk.language" : "python" ,
61- "telemetry.sdk.name" : "opentelemetry" ,
62- "telemetry.sdk.version" : anys .ANY_STR ,
63- },
70+ "attributes" : resource_attributes ,
6471 "schema_url" : "" ,
6572 },
6673 "start_time" : anys .ANY_DATETIME_STR ,
@@ -88,15 +95,7 @@ async def test_parse(
8895 "name" : "Tests.Registration.testCase1" ,
8996 "parent_id" : anys .ANY_STR ,
9097 "resource" : {
91- "attributes" : {
92- "cicd.pipeline.name" : "JOB" ,
93- "cicd.provider.name" : "github_actions" ,
94- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
95- "service.name" : "unknown_service" ,
96- "telemetry.sdk.language" : "python" ,
97- "telemetry.sdk.name" : "opentelemetry" ,
98- "telemetry.sdk.version" : anys .ANY_STR ,
99- },
98+ "attributes" : resource_attributes ,
10099 "schema_url" : "" ,
101100 },
102101 "start_time" : anys .ANY_DATETIME_STR ,
@@ -124,15 +123,7 @@ async def test_parse(
124123 "name" : "Tests.Registration.testCase2" ,
125124 "parent_id" : anys .ANY_STR ,
126125 "resource" : {
127- "attributes" : {
128- "cicd.pipeline.name" : "JOB" ,
129- "cicd.provider.name" : "github_actions" ,
130- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
131- "service.name" : "unknown_service" ,
132- "telemetry.sdk.language" : "python" ,
133- "telemetry.sdk.name" : "opentelemetry" ,
134- "telemetry.sdk.version" : anys .ANY_STR ,
135- },
126+ "attributes" : resource_attributes ,
136127 "schema_url" : "" ,
137128 },
138129 "start_time" : anys .ANY_DATETIME_STR ,
@@ -163,15 +154,7 @@ async def test_parse(
163154 "name" : "Tests.Registration.testCase3" ,
164155 "parent_id" : anys .ANY_STR ,
165156 "resource" : {
166- "attributes" : {
167- "cicd.pipeline.name" : "JOB" ,
168- "cicd.provider.name" : "github_actions" ,
169- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
170- "service.name" : "unknown_service" ,
171- "telemetry.sdk.language" : "python" ,
172- "telemetry.sdk.name" : "opentelemetry" ,
173- "telemetry.sdk.version" : anys .ANY_STR ,
174- },
157+ "attributes" : resource_attributes ,
175158 "schema_url" : "" ,
176159 },
177160 "start_time" : anys .ANY_DATETIME_STR ,
@@ -198,15 +181,7 @@ async def test_parse(
198181 "name" : "Tests.Authentication" ,
199182 "parent_id" : None ,
200183 "resource" : {
201- "attributes" : {
202- "cicd.pipeline.name" : "JOB" ,
203- "cicd.provider.name" : "github_actions" ,
204- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
205- "service.name" : "unknown_service" ,
206- "telemetry.sdk.language" : "python" ,
207- "telemetry.sdk.name" : "opentelemetry" ,
208- "telemetry.sdk.version" : anys .ANY_STR ,
209- },
184+ "attributes" : resource_attributes ,
210185 "schema_url" : "" ,
211186 },
212187 "start_time" : anys .ANY_DATETIME_STR ,
@@ -234,15 +209,7 @@ async def test_parse(
234209 "name" : "Tests.Authentication.testCase7" ,
235210 "parent_id" : anys .ANY_STR ,
236211 "resource" : {
237- "attributes" : {
238- "cicd.pipeline.name" : "JOB" ,
239- "cicd.provider.name" : "github_actions" ,
240- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
241- "service.name" : "unknown_service" ,
242- "telemetry.sdk.language" : "python" ,
243- "telemetry.sdk.name" : "opentelemetry" ,
244- "telemetry.sdk.version" : anys .ANY_STR ,
245- },
212+ "attributes" : resource_attributes ,
246213 "schema_url" : "" ,
247214 },
248215 "start_time" : anys .ANY_DATETIME_STR ,
@@ -270,15 +237,7 @@ async def test_parse(
270237 "name" : "Tests.Authentication.testCase8" ,
271238 "parent_id" : anys .ANY_STR ,
272239 "resource" : {
273- "attributes" : {
274- "cicd.pipeline.name" : "JOB" ,
275- "cicd.provider.name" : "github_actions" ,
276- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
277- "service.name" : "unknown_service" ,
278- "telemetry.sdk.language" : "python" ,
279- "telemetry.sdk.name" : "opentelemetry" ,
280- "telemetry.sdk.version" : anys .ANY_STR ,
281- },
240+ "attributes" : resource_attributes ,
282241 "schema_url" : "" ,
283242 },
284243 "start_time" : anys .ANY_DATETIME_STR ,
@@ -309,15 +268,7 @@ async def test_parse(
309268 "name" : "Tests.Authentication.testCase9" ,
310269 "parent_id" : anys .ANY_STR ,
311270 "resource" : {
312- "attributes" : {
313- "cicd.pipeline.name" : "JOB" ,
314- "cicd.provider.name" : "github_actions" ,
315- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
316- "service.name" : "unknown_service" ,
317- "telemetry.sdk.language" : "python" ,
318- "telemetry.sdk.name" : "opentelemetry" ,
319- "telemetry.sdk.version" : anys .ANY_STR ,
320- },
271+ "attributes" : resource_attributes ,
321272 "schema_url" : "" ,
322273 },
323274 "start_time" : anys .ANY_DATETIME_STR ,
@@ -349,15 +300,7 @@ async def test_parse(
349300 "name" : "Tests.Permission.testCase10" ,
350301 "parent_id" : anys .ANY_STR ,
351302 "resource" : {
352- "attributes" : {
353- "cicd.pipeline.name" : "JOB" ,
354- "cicd.provider.name" : "github_actions" ,
355- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
356- "service.name" : "unknown_service" ,
357- "telemetry.sdk.language" : "python" ,
358- "telemetry.sdk.name" : "opentelemetry" ,
359- "telemetry.sdk.version" : anys .ANY_STR ,
360- },
303+ "attributes" : resource_attributes ,
361304 "schema_url" : "" ,
362305 },
363306 "start_time" : anys .ANY_DATETIME_STR ,
@@ -384,15 +327,7 @@ async def test_parse(
384327 "name" : "Tests.Authentication.Login" ,
385328 "parent_id" : None ,
386329 "resource" : {
387- "attributes" : {
388- "cicd.pipeline.name" : "JOB" ,
389- "cicd.provider.name" : "github_actions" ,
390- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
391- "service.name" : "unknown_service" ,
392- "telemetry.sdk.language" : "python" ,
393- "telemetry.sdk.name" : "opentelemetry" ,
394- "telemetry.sdk.version" : anys .ANY_STR ,
395- },
330+ "attributes" : resource_attributes ,
396331 "schema_url" : "" ,
397332 },
398333 "start_time" : anys .ANY_DATETIME_STR ,
@@ -420,15 +355,7 @@ async def test_parse(
420355 "name" : "Tests.Authentication.Login.testCase4" ,
421356 "parent_id" : anys .ANY_STR ,
422357 "resource" : {
423- "attributes" : {
424- "cicd.pipeline.name" : "JOB" ,
425- "cicd.provider.name" : "github_actions" ,
426- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
427- "service.name" : "unknown_service" ,
428- "telemetry.sdk.language" : "python" ,
429- "telemetry.sdk.name" : "opentelemetry" ,
430- "telemetry.sdk.version" : anys .ANY_STR ,
431- },
358+ "attributes" : resource_attributes ,
432359 "schema_url" : "" ,
433360 },
434361 "start_time" : anys .ANY_DATETIME_STR ,
@@ -459,15 +386,7 @@ async def test_parse(
459386 "name" : "Tests.Authentication.Login.testCase5" ,
460387 "parent_id" : anys .ANY_STR ,
461388 "resource" : {
462- "attributes" : {
463- "service.name" : "unknown_service" ,
464- "telemetry.sdk.language" : "python" ,
465- "telemetry.sdk.name" : "opentelemetry" ,
466- "telemetry.sdk.version" : anys .ANY_STR ,
467- "cicd.pipeline.name" : "JOB" ,
468- "cicd.provider.name" : "github_actions" ,
469- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
470- },
389+ "attributes" : resource_attributes ,
471390 "schema_url" : "" ,
472391 },
473392 "start_time" : anys .ANY_DATETIME_STR ,
@@ -495,15 +414,7 @@ async def test_parse(
495414 "name" : "Tests.Authentication.Login.testCase6" ,
496415 "parent_id" : anys .ANY_STR ,
497416 "resource" : {
498- "attributes" : {
499- "cicd.pipeline.name" : "JOB" ,
500- "cicd.provider.name" : "github_actions" ,
501- "vcs.ref.head.revision" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
502- "service.name" : "unknown_service" ,
503- "telemetry.sdk.language" : "python" ,
504- "telemetry.sdk.name" : "opentelemetry" ,
505- "telemetry.sdk.version" : anys .ANY_STR ,
506- },
417+ "attributes" : resource_attributes ,
507418 "schema_url" : "" ,
508419 },
509420 "start_time" : anys .ANY_DATETIME_STR ,
0 commit comments