-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for GHA resource attributes
Change-Id: Ia8791aa527ccc8e0420a86bb023bdf7ae43f5775
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
from opentelemetry.sdk.resources import Resource, ResourceDetector | ||
|
||
from opentelemetry.semconv._incubating.attributes import cicd_attributes | ||
from opentelemetry.semconv._incubating.attributes import vcs_attributes | ||
|
||
from pytest_mergify import utils | ||
|
||
|
||
class GitHubActionsResourceDetector(ResourceDetector): | ||
"""Detects OpenTelemetry Resource attributes for GitHub Actions.""" | ||
|
||
def detect(self) -> Resource: | ||
if utils.get_ci_provider() != "github_actions": | ||
return Resource({}) | ||
|
||
if "GITHUB_SERVER_URL" in os.environ and "GITHUB_REPOSITORY" in os.environ: | ||
url = os.environ.get("GITHUB_SERVER_URL") + os.environ.get("GITHUB_REPOSITORY") | ||
else: | ||
url = None | ||
|
||
return Resource( | ||
{ | ||
cicd_attributes.CICD_PIPELINE_NAME: os.environ.get("GITHUB_JOB"), | ||
cicd_attributes.CICD_PIPELINE_RUN_ID: os.environ.get( | ||
"GITHUB_RUN_ID" | ||
), | ||
cicd_attributes.CICD_PIPELINE_TASK_NAME: os.environ.get( | ||
"GITHUB_ACTION" | ||
), | ||
vcs_attributes.VCS_REPOSITORY_URL_FULL: url, | ||
vcs_attributes.VCS_REF_HEAD_NAME: os.environ.get("GITHUB_REF_NAME"), | ||
vcs_attributes.VCS_REF_HEAD_TYPE: os.environ.get("GITHUB_REF_TYPE"), | ||
vcs_attributes.VCS_REF_BASE_NAME: os.environ.get("GITHUB_BASE_REF"), | ||
"vcs.repository.name": os.environ.get("GITHUB_REPOSITORY"), | ||
"vcs.repository.id": os.environ.get("GITHUB_REPOSITORY_ID"), | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters