Skip to content
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

[Resources.Gcp] Add Google Cloud Platform resource detector #1691

Merged
merged 44 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4e0d7ac
initial setup
matt-hensley Apr 22, 2024
1f6a758
Merge branch 'main' into gcpdetector
matt-hensley Apr 22, 2024
151886b
Merge branch 'main' into gcpdetector
matt-hensley Apr 23, 2024
0cbfb14
extract for testing
matt-hensley Apr 23, 2024
40599ad
resource attr extraction tests
matt-hensley Apr 24, 2024
fe9a3e8
align with other test projects
matt-hensley Apr 24, 2024
7498807
follow naming convention
matt-hensley Apr 24, 2024
43aab6b
Merge branch 'main' into gcpdetector
matt-hensley Apr 24, 2024
6fbf780
mirror existing CI setup
matt-hensley Apr 24, 2024
4e305ae
add missing host.id attribute
matt-hensley Apr 24, 2024
919e64f
WIP README
matt-hensley Apr 24, 2024
adcf23c
Merge branch 'main' into gcpdetector
matt-hensley Apr 24, 2024
566677e
CHANGELOG entry
matt-hensley Apr 24, 2024
105ee7e
code example
matt-hensley Apr 24, 2024
ba4f7f9
update to AZ attribute
matt-hensley Apr 24, 2024
fbf0300
fix formatting
matt-hensley Apr 30, 2024
8eab542
rework attribute listing
matt-hensley Apr 30, 2024
eae5a89
Merge branch 'main' into gcpdetector
matt-hensley Apr 30, 2024
063aff7
missing solution section
matt-hensley May 1, 2024
a526638
missing proj
matt-hensley May 1, 2024
2d2f2de
resource builder extension method
matt-hensley May 1, 2024
e84b13f
rename per #1610
matt-hensley May 1, 2024
abbcb0e
missed file when renaming
matt-hensley May 1, 2024
90ede06
linter error
matt-hensley May 1, 2024
f0e54f1
another missed name
matt-hensley May 1, 2024
f32e81f
improve CHANGELOG
matt-hensley May 1, 2024
2b8f97e
add meter and log resource examples
matt-hensley May 1, 2024
c456ce3
mark as codeowner
matt-hensley May 2, 2024
827271f
rename
matt-hensley May 2, 2024
c6621b2
remove used package
matt-hensley May 2, 2024
9b0b80d
mark detector internal, remove from API
matt-hensley May 2, 2024
d226d87
add issue template
matt-hensley May 6, 2024
59441be
test component owner
matt-hensley May 6, 2024
5b945da
Update src/OpenTelemetry.Resources.Gcp/CHANGELOG.md
matt-hensley May 6, 2024
ee8d0bd
Merge branch 'gcpdetector' of https://github.com/matt-hensley/opentel…
matt-hensley May 6, 2024
947a7a8
add second owner
matt-hensley May 8, 2024
d2faea1
Merge branch 'main' into gcpdetector
matt-hensley May 8, 2024
2493a50
Merge branch 'main' into gcpdetector
cijothomas May 8, 2024
3bc5fe6
unify public api specs
matt-hensley May 10, 2024
08dbf6b
Merge branch 'main' into gcpdetector
Kielek May 13, 2024
e54df32
Handles changes on main
Kielek May 13, 2024
10027dd
Handle changes from main - part 2
Kielek May 13, 2024
fdd245f
Merge branch 'main' into gcpdetector
vishweshbankwar May 13, 2024
bd37f89
Merge branch 'main' into gcpdetector
Kielek May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ flags:
paths:
- src/OpenTelemetry.ResourceDetectors.Azure

unittests-ResourceDetectors.Gcp:
carryforward: true
paths:
- src/OpenTelemetry.ResourceDetectors.Gcp

unittests-ResourceDetectors.Host:
carryforward: true
paths:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
eventcounters: ['*/OpenTelemetry.Instrumentation.EventCounters*/**', 'examples/event-counters/**', '!**/*.md']
extensions: ['*/OpenTelemetry.Extensions/**', '*/OpenTelemetry.Extensions.Tests/**', '!**/*.md']
geneva: ['*/OpenTelemetry.Exporter.Geneva*/**', '!**/*.md']
gcp: ['*/OpenTelemetry.ResourceDetectors.Gcp*/**', '!**/*.md']
host: ['*/OpenTelemetry.ResourceDetectors.Host*/**', '!**/*.md']
http: ['*/OpenTelemetry.Instrumentation.Http*/**', '!**/*.md']
onecollector: ['*/OpenTelemetry.Instrumentation.OneCollector*/**', '!**/*.md']
Expand All @@ -51,6 +52,7 @@ jobs:
'!*/OpenTelemetry.Instrumentation.AspNet*/**',
'!examples/AspNet/**',
'!*/OpenTelemetry.ResourceDetectors.Azure*/**',
'!*/OpenTelemetry.ResourceDetectors.Gcp*/**',
'!*/OpenTelemetry.ResourceDetectors.Host*/**',
'!*/OpenTelemetry.ResourceDetectors.Process/**',
'!*/OpenTelemetry.ResourceDetectors.Process.Tests/**',
Expand Down Expand Up @@ -151,6 +153,17 @@ jobs:
project-name: OpenTelemetry.Exporter.Geneva
code-cov-name: Exporter.Geneva

build-test-gcp:
needs: detect-changes
if: |
contains(needs.detect-changes.outputs.changes, 'gcp')
|| contains(needs.detect-changes.outputs.changes, 'build')
|| contains(needs.detect-changes.outputs.changes, 'shared')
uses: ./.github/workflows/Component.BuildTest.yml
with:
project-name: OpenTelemetry.ResourceDetectors.Gcp
code-cov-name: ResourceDetectors.Gcp

build-test-host:
needs: detect-changes
if: |
Expand Down Expand Up @@ -348,6 +361,7 @@ jobs:
OpenTelemetry.Instrumentation.Wcf.Tests.csproj,
OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj,
OpenTelemetry.ResourceDetectors.Azure.Tests.csproj,
OpenTelemetry.ResourceDetectors.Gcp.Tests.csproj,
OpenTelemetry.ResourceDetectors.Host.Tests.csproj,
OpenTelemetry.ResourceDetectors.Process.Tests.csproj,
OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests.csproj
Expand Down Expand Up @@ -396,6 +410,7 @@ jobs:
|| contains(needs.detect-changes.outputs.changes, 'aws')
|| contains(needs.detect-changes.outputs.changes, 'azure')
|| contains(needs.detect-changes.outputs.changes, 'extensions')
|| contains(needs.detect-changes.outputs.changes, 'gcp')
|| contains(needs.detect-changes.outputs.changes, 'host')
|| contains(needs.detect-changes.outputs.changes, 'http')
|| contains(needs.detect-changes.outputs.changes, 'processdetector')
Expand All @@ -422,6 +437,7 @@ jobs:
build-test-eventcounters,
build-test-extensions,
build-test-geneva,
build-test-gcp,
build-test-host,
build-test-http,
build-test-onecollector,
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/package-ResourceDetectors.Gcp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Pack OpenTelemetry.ResourceDetectors.Gcp

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
push:
tags:
- 'ResourceDetectors.Gcp-*' # trigger when we create a tag with prefix "ResourceDetectors.Gcp-"

jobs:
call-build-test-pack:
permissions:
contents: write
uses: ./.github/workflows/Component.Package.yml
with:
project-name: OpenTelemetry.ResourceDetectors.Gcp
secrets: inherit
32 changes: 32 additions & 0 deletions build/Projects/OpenTelemetry.ResourceDetectors.Gcp.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project>

<PropertyGroup>
<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.Parent.FullName)</RepoRoot>
</PropertyGroup>

<ItemGroup>
<SolutionProjects Include="$(RepoRoot)\src\OpenTelemetry.ResourceDetectors.Gcp\OpenTelemetry.ResourceDetectors.Gcp.csproj" />
<SolutionProjects Include="$(RepoRoot)\test\OpenTelemetry.ResourceDetectors.Gcp.Tests\OpenTelemetry.ResourceDetectors.Gcp.Tests.csproj" />

<PackProjects Include="$(RepoRoot)\src\OpenTelemetry.ResourceDetectors.Gcp\OpenTelemetry.ResourceDetectors.Gcp.csproj" />

<TestProjects Include="$(RepoRoot)\test\OpenTelemetry.ResourceDetectors.Gcp.Tests\OpenTelemetry.ResourceDetectors.Gcp.Tests.csproj" />
</ItemGroup>

<Target Name="Build">
<MSBuild Projects="@(SolutionProjects)" Targets="Build" ContinueOnError="ErrorAndStop" />
</Target>

<Target Name="Restore">
<MSBuild Projects="@(SolutionProjects)" Targets="Restore" ContinueOnError="ErrorAndStop" />
</Target>

<Target Name="Pack">
<MSBuild Projects="@(PackProjects)" Targets="Pack" ContinueOnError="ErrorAndStop" />
</Target>

<Target Name="VSTest">
<MSBuild Projects="@(TestProjects)" Targets="VSTest" ContinueOnError="ErrorAndStop" />
</Target>

</Project>
15 changes: 15 additions & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projects", "Projects", "{04
build\Projects\OpenTelemetry.Instrumentation.Wcf.proj = build\Projects\OpenTelemetry.Instrumentation.Wcf.proj
build\Projects\OpenTelemetry.PersistentStorage.proj = build\Projects\OpenTelemetry.PersistentStorage.proj
build\Projects\OpenTelemetry.ResourceDetectors.Azure.proj = build\Projects\OpenTelemetry.ResourceDetectors.Azure.proj
build\Projects\OpenTelemetry.ResourceDetectors.Gcp.proj = build\Projects\OpenTelemetry.ResourceDetectors.Gcp.proj
build\Projects\OpenTelemetry.ResourceDetectors.Host.proj = build\Projects\OpenTelemetry.ResourceDetectors.Host.proj
build\Projects\OpenTelemetry.ResourceDetectors.Process.proj = build\Projects\OpenTelemetry.ResourceDetectors.Process.proj
build\Projects\OpenTelemetry.ResourceDetectors.ProcessRuntime.proj = build\Projects\OpenTelemetry.ResourceDetectors.ProcessRuntime.proj
Expand All @@ -351,6 +352,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetec
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.PersistentStorage.Abstractions.Tests", "test\OpenTelemetry.PersistentStorage.Abstractions.Tests\OpenTelemetry.PersistentStorage.Abstractions.Tests.csproj", "{7AD707F9-DC6D-430A-8834-D5DCD517BF6E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Gcp", "src\OpenTelemetry.ResourceDetectors.Gcp\OpenTelemetry.ResourceDetectors.Gcp.csproj", "{CBC6D677-D1FF-470E-A244-477E8616A245}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Gcp.Tests", "test\OpenTelemetry.ResourceDetectors.Gcp.Tests\OpenTelemetry.ResourceDetectors.Gcp.Tests.csproj", "{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.SqlClient", "src\OpenTelemetry.Instrumentation.SqlClient\OpenTelemetry.Instrumentation.SqlClient.csproj", "{737D1A9E-5A1A-4F4F-830B-E98ED100994C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.SqlClient.Tests", "test\OpenTelemetry.Instrumentation.SqlClient.Tests\OpenTelemetry.Instrumentation.SqlClient.Tests.csproj", "{9C996130-74D7-4FB7-8277-2EE6EBA2BFA6}"
Expand Down Expand Up @@ -733,6 +738,14 @@ Global
{1156D564-2E3C-47D6-97C1-FF3ADEDC41C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1156D564-2E3C-47D6-97C1-FF3ADEDC41C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1156D564-2E3C-47D6-97C1-FF3ADEDC41C8}.Release|Any CPU.Build.0 = Release|Any CPU
{CBC6D677-D1FF-470E-A244-477E8616A245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBC6D677-D1FF-470E-A244-477E8616A245}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBC6D677-D1FF-470E-A244-477E8616A245}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBC6D677-D1FF-470E-A244-477E8616A245}.Release|Any CPU.Build.0 = Release|Any CPU
{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -842,6 +855,8 @@ Global
{BE92357F-DE09-477D-AFDB-6AD1D7AC7BA1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{7371E920-ECD0-403A-A009-7A1A301D9763} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{1156D564-2E3C-47D6-97C1-FF3ADEDC41C8} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{CBC6D677-D1FF-470E-A244-477E8616A245} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{EECE8D5F-C319-42E8-B37C-A41D6FF43E4A} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector.GcpResourceDetector() -> void
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector.Detect() -> OpenTelemetry.Resources.Resource!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector.GcpResourceDetector() -> void
OpenTelemetry.ResourceDetectors.Gcp.GcpResourceDetector.Detect() -> OpenTelemetry.Resources.Resource!
10 changes: 10 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Gcp/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Runtime.CompilerServices;

#if SIGNED
[assembly: InternalsVisibleTo("OpenTelemetry.ResourceDetectors.Gcp.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
#else
[assembly: InternalsVisibleTo("OpenTelemetry.ResourceDetectors.Gcp.Tests")]
#endif
8 changes: 8 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Gcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## Unreleased

* Add Google Cloud Platform resource detector for GKE, GAE, GCR, and GCE.
([#1691](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1691))

For more details, please refer to the [README](README.md).
93 changes: 93 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Gcp/GcpResourceDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
using Google.Api.Gax;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace OpenTelemetry.ResourceDetectors.Gcp;
matt-hensley marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Resource detector for Google Cloud Platform (GCP).
/// </summary>
public sealed class GcpResourceDetector : IResourceDetector
{
/// <inheritdoc/>
public Resource Detect()
{
var platform = Platform.Instance();

if (platform == null || platform.ProjectId == null)
{
return Resource.Empty;
}

var attributeList = platform.Type switch
{
PlatformType.Gke => ExtractGkeResourceAttributes(platform),
PlatformType.CloudRun => ExtractCloudRunResourceAttributes(platform),
PlatformType.Gae => ExtractGaeResourceAttributes(platform),
PlatformType.Gce => ExtractGceResourceAttributes(platform),
_ => ExtractGceResourceAttributes(platform),
};

return new Resource(attributeList);
}

internal static List<KeyValuePair<string, object>> ExtractGkeResourceAttributes(Platform platform)
{
List<KeyValuePair<string, object>> attributeList = new()
{
new(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.GcpCloudProviderValue),
new(ResourceSemanticConventions.AttributeCloudAccount, platform.ProjectId),
new(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.GcpGkePlatformValue),
new(ResourceSemanticConventions.AttributeCloudZone, platform.GkeDetails.Zone),
new(ResourceSemanticConventions.AttributeHostId, platform.GkeDetails.InstanceId),
new(ResourceSemanticConventions.AttributeK8sCluster, platform.GkeDetails.ClusterName),
new(ResourceSemanticConventions.AttributeK8sNamespace, platform.GkeDetails.NamespaceId),
new(ResourceSemanticConventions.AttributeK8sPod, platform.GkeDetails.HostName),
};

return attributeList;
}

internal static List<KeyValuePair<string, object>> ExtractCloudRunResourceAttributes(Platform platform)
{
List<KeyValuePair<string, object>> attributeList = new()
{
new(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.GcpCloudProviderValue),
new(ResourceSemanticConventions.AttributeCloudAccount, platform.ProjectId),
new(ResourceSemanticConventions.AttributeCloudAvailabilityZone, platform.CloudRunDetails.Zone),
new(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.GcpCloudRunPlatformValue),
new(ResourceSemanticConventions.AttributeCloudRegion, platform.CloudRunDetails.Region),
};

return attributeList;
}

internal static List<KeyValuePair<string, object>> ExtractGaeResourceAttributes(Platform platform)
{
List<KeyValuePair<string, object>> attributeList = new()
{
new(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.GcpCloudProviderValue),
new(ResourceSemanticConventions.AttributeCloudAccount, platform.ProjectId),
new(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.GcpGaePlatformValue),
};
return attributeList;
}

internal static List<KeyValuePair<string, object>> ExtractGceResourceAttributes(Platform platform)
{
List<KeyValuePair<string, object>> attributeList = new()
{
new(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.GcpCloudProviderValue),
new(ResourceSemanticConventions.AttributeCloudAccount, platform.ProjectId),
new(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.GcpGcePlatformValue),
new(ResourceSemanticConventions.AttributeHostId, platform.GceDetails.InstanceId),
new(ResourceSemanticConventions.AttributeCloudAvailabilityZone, platform.GceDetails.Location),
};

return attributeList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<Description>OpenTelemetry Resource Detectors for Google Cloud Platform environments</Description>
<PackageTags>$(PackageTags);ResourceDetector</PackageTags>
<MinVerTagPrefix>ResourceDetectors.GCP-</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Api.Gax" Version="4.8.0" />
<PackageReference Include="Grpc.Core.Api" Version="2.62.0" />
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ResourceSemanticConventions.cs" Link="Includes\ResourceSemanticConventions.cs" />
</ItemGroup>
</Project>
71 changes: 71 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Gcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Resource Detectors for Google Cloud Platform environments

[![NuGet version badge](https://img.shields.io/nuget/v/OpenTelemetry.ResourceDetectors.Gcp)](https://www.nuget.org/packages/OpenTelemetry.ResourceDetectors.Gcp)
[![NuGet download count badge](https://img.shields.io/nuget/dt/OpenTelemetry.ResourceDetectors.Azure)](https://www.nuget.org/packages/OpenTelemetry.ResourceDetectors.Azure)

This package contains [Resource
Detectors](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#detecting-resource-information-from-the-environment)
for applications running in Google Cloud Platform environments.

## Installation

```shell
dotnet add package --prerelease OpenTelemetry.ResourceDetectors.Gcp
```

```csharp
using OpenTelemetry;
using OpenTelemetry.ResourceDetectors.Gcp;
using OpenTelemetry.Resources;

var tracerProvider = Sdk.CreateTracerProviderBuilder()
// other configurations
.ConfigureResource(resource => resource.AddDetector(new GcpResourceDetector()))
.Build();
```

## Resource Attributes

The following OpenTelemetry semantic conventions will be detected depending on
which Google Cloud Platform environment an application is running in.

### Google Kubernetes Engine

|-------------------------|-----------------------|
| Attribute | Value |
| cloud.provider | gcp |
| cloud.platform | gcp_kubernetes_engine |
| cloud.account.id | auto |
| cloud.availability_zone | auto |
| host.id | auto |
| k8s.cluster.name | auto |
| k8s.namespace.name | auto |
| k8s.pod.name | auto |

### Google App Engine

|-------------------------|----------------|
| Attribute | Value |
| cloud.provider | gcp |
| cloud.platform | gcp_app_engine |
| cloud.account.id | auto |

### Google Cloud Run

|-------------------------|---------------|
| Attribute | Value |
| cloud.provider | gcp |
| cloud.platform | gcp_cloud_run |
| cloud.account.id | auto |
| cloud.availability_zone | auto |
| cloud.region | auto |

### Google Compute Engine

|-------------------------|--------------------|
| Attribute | Value |
| cloud.provider | gcp |
| cloud.platform | gcp_compute_engine |
| cloud.account.id | auto |
| cloud.availability_zone | auto |
| host.id | auto |
Loading
Loading