Skip to content

feat(gcp-detector): add Cloud Run support with faas.* and cloud.platform #2818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kaspernissen
Copy link

@kaspernissen kaspernissen commented May 9, 2025

Which problem is this PR solving?

The resource detector for gcp did not previously support Cloud Run–specific resource attributes, although these are supported in other SDKs (e.g. Go, Java). This PR adds support for setting the faas.* along with cloud.platform resource attributes when running in a Cloud Run environment.

Short description of the changes

  • Detects faas.name from K_SERVICE environment variable.
  • Detects faas.version from K_REVISION environment variable
  • Detects faas.instance from GCP metadata server (/instance/id) reusing the existing method.
  • Sets cloud.platform using the semantic conventions static variables.
  • Adds unit test for Cloud Run detection, following existing patterns
  • Keeps full backward compatibility and aligns behavior with the Go SDK implementation (using env vars)

For more information, see the container runtime contract: https://cloud.google.com/run/docs/container-contract#env-vars.

This is my first PR 🙏

I've added another PR for the extension of the assertCloudResource helper with cloud.platform. For now just manually asserting in the test case.

* feat(gcp-detector): add Cloud Run support with faas.name, faas.version, and faas.instance

Signed-off-by: Kasper Borg Nissen <[email protected]>

* chore(lint): remove newlines

Signed-off-by: Kasper Borg Nissen <[email protected]>

* chore(comment): write comment on moving the assertions

* test(gcp-detector): fix Cloud Run tests

---------

Signed-off-by: Kasper Borg Nissen <[email protected]>
@kaspernissen kaspernissen changed the title feat(gcp-detector): add Cloud Run support with faas.* (#1) feat(gcp-detector): add Cloud Run support with faas.* and cloud.platform (#1) May 13, 2025
@mmanciop
Copy link
Contributor

I am looking forward to seeing this merged :-)

@kaspernissen kaspernissen changed the title feat(gcp-detector): add Cloud Run support with faas.* and cloud.platform (#1) feat(gcp-detector): add Cloud Run support with faas.* and cloud.platform May 14, 2025
@pichlermarc
Copy link
Member

cc @punya and @aabmass (component owners)

@punya
Copy link
Member

punya commented May 20, 2025

I am no longer working in this area, @aabmass could you please take a look, and also update component owners?

@david-luna
Copy link
Contributor

@aabmass could you have a look at this one? I could volunteer to review it but I think you feedback would be better

@aabmass
Copy link
Member

aabmass commented Jun 4, 2025

Hey, apologies for the confusion. We have already implemented this in @google-cloud/opentelemetry-resource-util detector.

I would actually like to make the resource detector here in contrib just re-expose the one from @google-cloud/opentelemetry-resource-util: GoogleCloudPlatform/opentelemetry-operations-js#518

I previously discussed this with the maintainers and it wasn't contentious but haven't found the time to do it. To recap, the reason to use it as a library vs copying the code is that we have a bunch of integration tests that would be really difficult to move to this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants