Skip to content

Commit ca62a75

Browse files
authored
fix(gha): set the right type of data in attribute (#65)
Some of the attributes should be set as int, not as a str.
1 parent 31698b1 commit ca62a75

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pytest_mergify/resources/github_actions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def get_github_actions_head_sha() -> str | None:
2626
return os.getenv("GITHUB_SHA")
2727

2828
OPENTELEMETRY_GHA_MAPPING = {
29-
cicd_attributes.CICD_PIPELINE_NAME: "GITHUB_JOB",
30-
cicd_attributes.CICD_PIPELINE_RUN_ID: "GITHUB_RUN_ID",
31-
"cicd.pipeline.run.attempt": "GITHUB_RUN_ATTEMPT",
32-
cicd_attributes.CICD_PIPELINE_TASK_NAME: "GITHUB_ACTION",
33-
vcs_attributes.VCS_REF_HEAD_NAME: "GITHUB_REF_NAME",
34-
vcs_attributes.VCS_REF_HEAD_TYPE: "GITHUB_REF_TYPE",
35-
vcs_attributes.VCS_REF_BASE_NAME: "GITHUB_BASE_REF",
36-
"vcs.repository.name": "GITHUB_REPOSITORY",
37-
"vcs.repository.id": "GITHUB_REPOSITORY_ID",
29+
cicd_attributes.CICD_PIPELINE_NAME: (str, "GITHUB_JOB"),
30+
cicd_attributes.CICD_PIPELINE_RUN_ID: (int, "GITHUB_RUN_ID"),
31+
"cicd.pipeline.run.attempt": (int, "GITHUB_RUN_ATTEMPT"),
32+
cicd_attributes.CICD_PIPELINE_TASK_NAME: (str, "GITHUB_ACTION"),
33+
vcs_attributes.VCS_REF_HEAD_NAME: (str, "GITHUB_REF_NAME"),
34+
vcs_attributes.VCS_REF_HEAD_TYPE: (str, "GITHUB_REF_TYPE"),
35+
vcs_attributes.VCS_REF_BASE_NAME: (str, "GITHUB_BASE_REF"),
36+
"vcs.repository.name": (str, "GITHUB_REPOSITORY"),
37+
"vcs.repository.id": (int, "GITHUB_REPOSITORY_ID"),
3838
}
3939

4040
def detect(self) -> Resource:
@@ -52,8 +52,8 @@ def detect(self) -> Resource:
5252
if head_sha is not None:
5353
attributes[vcs_attributes.VCS_REF_HEAD_REVISION] = head_sha
5454

55-
for attribute_name, envvar in self.OPENTELEMETRY_GHA_MAPPING.items():
55+
for attribute_name, (type_, envvar) in self.OPENTELEMETRY_GHA_MAPPING.items():
5656
if envvar in os.environ:
57-
attributes[attribute_name] = os.environ[envvar]
57+
attributes[attribute_name] = type_(os.environ[envvar])
5858

5959
return Resource(attributes)

tests/test_resources.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_span_github_actions(
4040
monkeypatch.setenv("GITHUB_ACTIONS", "true")
4141
monkeypatch.setenv("GITHUB_REPOSITORY", "Mergifyio/pytest-mergify")
4242
monkeypatch.setenv("GITHUB_SERVER_URL", "https://github.com")
43+
monkeypatch.setenv("GITHUB_RUN_ID", "3213121312")
4344
result, spans = pytester_with_spans()
4445
assert all(
4546
span.resource.attributes["vcs.repository.name"] == "Mergifyio/pytest-mergify"
@@ -50,3 +51,7 @@ def test_span_github_actions(
5051
== "https://github.com/Mergifyio/pytest-mergify"
5152
for span in spans.values()
5253
)
54+
assert all(
55+
span.resource.attributes["cicd.pipeline.run.id"] == 3213121312
56+
for span in spans.values()
57+
)

0 commit comments

Comments
 (0)