Skip to content

Commit 1f5a927

Browse files
authored
Add all resource detectors from the .NET contrib repository (#85)
* Add all .NET supported resource detectors * De-activate container detector by default * Fix tests * Format issues * Format fixes * Add tests * Add changelog entry * Fix changelog entry * Add documentation and AWS resource * Fix linting * Fix broken link
1 parent 75fae46 commit 1f5a927

17 files changed

Lines changed: 299 additions & 12 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
* [#81](https://github.com/grafana/grafana-opentelemetry-dotnet/pull/81)
88
Adds a .NET 8 test project and integrates it into the OATS test matrix.
9+
* [#85](https://github.com/grafana/grafana-opentelemetry-dotnet/pull/85)
10+
Adds resource detectors for Azure, host, process, process runtime, and
11+
container resource attributes.
912

1013
## 0.7.0-beta.3
1114

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ To disable self-diagnostics, delete the above file.
106106
To engage with the Grafana Application Observability community:
107107

108108
* Chat with us on our community Slack channel. To invite yourself to the
109-
Grafana Slack, visit [https://slack.grafana.com/](https://slack.grafana.com)
109+
Grafana Slack, visit [https://grafana.slack.com/](https://grafana.slack.com)
110110
and join the [#application-observability](https://grafana.slack.com/archives/C05E87XRK3J)
111111
channel.
112112
* Ask questions on the [Discussions page](https://github.com/grafana/grafana-opentelemetry-dotnet/discussions).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
matrix:
2+
- name: default
3+
docker-compose:
4+
generator: lgtm
5+
files:
6+
- ../docker-compose.oats.yml
7+
- name: self-contained
8+
docker-compose:
9+
generator: lgtm
10+
files:
11+
- ../docker-compose.self-contained.oats.yml
12+
- name: net8
13+
docker-compose:
14+
generator: lgtm
15+
files:
16+
- ../docker-compose.net8.oats.yml
17+
interval: 500ms
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include:
2+
- ./oats-template.yml
3+
input:
4+
- path: /api/HttpClient/Get
5+
expected:
6+
traces:
7+
- traceql: '{ name =~ "api/HttpClient/Get" }'
8+
spans:
9+
- name: 'GET'
10+
attributes:
11+
service.name: aspnetcore
12+
service.version: 1.0.0.0
13+
telemetry.distro.name: grafana-opentelemetry-dotnet
14+
telemetry.distro.version: regex:.+
15+
deployment.environment: production
16+
process.runtime.description: regex:.NET.+
17+
process.runtime.name: .NET
18+
process.runtime.version: regex:.+
19+
host.name: regex:.+
20+
telemetry.sdk.name: opentelemetry
21+
telemetry.sdk.language: dotnet
22+
telemetry.sdk.version: regex:.+
23+
- traceql: '{ resource.process.pid > 0 }'
24+
spans:
25+
- name: 'GET'

docs/supported-instrumentations.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ and [minimal](./installation.md#install-the-base-package) dependencies:
1010
| `AspNetCore` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.AspNetCore](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNetCore) |
1111
| `AWS` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.AWS](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AWS) |
1212
| `AWSLambda` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.AWSLambda](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AWSLambda) |
13+
| `AWSResource` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.AWS](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.AWS) |
14+
| `AzureResource` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.Azure](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.Azure) |
1315
| `Cassandra` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.Cassandra](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Cassandra) |
16+
| `ContainerResource` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.Container](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.Container) |
1417
| `ElasticsearchClient` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.ElasticsearchClient](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.ElasticsearchClient) |
1518
| `EntityFrameworkCore` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.EntityFrameworkCore](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.EntityFrameworkCore) |
1619
| `GrpcNetClient` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.Instrumentation.GrpcNetClient](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.GrpcNetClient) |
1720
| `Hangfire` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.Hangfire](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Hangfire) |
1821
| `HttpClient` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.Instrumentation.Http](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Http) |
22+
| `HostResource` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.Host](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.Host) |
1923
| `NetRuntime` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.Instrumentation.Runtime](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Runtime) |
2024
| `Process` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.Instrumentation.Process](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) |
25+
| `ProcessResource` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.Process](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.Process) |
26+
| `ProcessRuntimeResource`| :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.ResourceDetectors.ProcessRuntime](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.ResourceDetectors.ProcessRuntime) |
2127
| `MySqlData` | :heavy_check_mark: | :heavy_check_mark: | [OpenTelemetry.Instrumentation.MySqlData](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.MySqlData) |
2228
| | :heavy_check_mark: | | [MySql.Data.OpenTelemetry](https://www.nuget.org/packages/MySql.Data.OpenTelemetry) |
2329
| `Owin` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.Owin](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Owin) |
@@ -26,5 +32,8 @@ and [minimal](./installation.md#install-the-base-package) dependencies:
2632
| `StackExchangeRedis` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.StackExchangeRedis](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.StackExchangeRedis) |
2733
| `Wcf` | :heavy_check_mark: | | [OpenTelemetry.Instrumentation.Wcf](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Wcf) |
2834

29-
The `AWSLambda` instrumentation is included but needs to be explicitly
30-
activated, as activating it in non-AWS scenarios causes errors.
35+
* The `AWSLambda` instrumentation is included but needs to be explicitly
36+
activated, as activating it in non-AWS scenarios causes errors.
37+
* The `ContainerResource` instrumentation is included but needs to be explicitly
38+
activated, as it currently adds container resource attributes for processes
39+
running not in containers.

src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" />
4444
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.3" />
4545
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.6.0-beta.3" />
46+
47+
<PackageReference Include="OpenTelemetry.ResourceDetectors.AWS" Version="1.4.0-beta.1" />
48+
<PackageReference Include="OpenTelemetry.ResourceDetectors.Azure" Version="1.0.0-beta.4" />
49+
<PackageReference Include="OpenTelemetry.ResourceDetectors.Container" Version="1.0.0-beta.5" />
50+
</ItemGroup>
51+
52+
<!-- Non-stable instrumentation packages with no dependencies, non netstandard2.0 -->
53+
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
54+
<PackageReference Include="OpenTelemetry.ResourceDetectors.Host" Version="0.1.0-alpha.2" />
55+
<PackageReference Include="OpenTelemetry.ResourceDetectors.Process" Version="0.1.0-alpha.2" />
56+
<PackageReference Include="OpenTelemetry.ResourceDetectors.ProcessRuntime" Version="0.1.0-alpha.2" />
4657
</ItemGroup>
4758

4859
<ItemGroup>

src/Grafana.OpenTelemetry.Base/GrafanaOpenTelemetrySettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ internal GrafanaOpenTelemetrySettings(IConfiguration configuration)
103103
// De-activate it until the related issue is resolved: https://github.com/grafana/app-o11y/issues/378
104104
Instrumentations.Remove(Instrumentation.AWSLambda);
105105

106+
// Activating the container resource detector by default always populates a `container.id` attribute,
107+
// even when running in a non-container Linux setting.
108+
Instrumentations.Remove(Instrumentation.ContainerResource);
109+
106110
var disableInstrumentations = configuration[DisableInstrumentationsEnvVarName];
107111

108112
if (!string.IsNullOrEmpty(disableInstrumentations))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright Grafana Labs
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
using OpenTelemetry.ResourceDetectors.AWS;
7+
using OpenTelemetry.Resources;
8+
9+
namespace Grafana.OpenTelemetry
10+
{
11+
internal class AWSResourceInitializer : InstrumentationInitializer
12+
{
13+
public override Instrumentation Id { get; } = Instrumentation.AWSResource;
14+
15+
protected override ResourceBuilder InitializeResourceDetector(ResourceBuilder builder)
16+
{
17+
return builder
18+
#if !NETFRAMEWORK && !NETSTANDARD
19+
.AddDetector(new AWSECSResourceDetector())
20+
.AddDetector(new AWSEKSResourceDetector())
21+
#endif
22+
.AddDetector(new AWSEC2ResourceDetector())
23+
.AddDetector(new AWSEBSResourceDetector());
24+
}
25+
}
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright Grafana Labs
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
using OpenTelemetry.ResourceDetectors.Azure;
7+
using OpenTelemetry.Resources;
8+
9+
namespace Grafana.OpenTelemetry
10+
{
11+
internal class AzureResourceInitializer : InstrumentationInitializer
12+
{
13+
public override Instrumentation Id { get; } = Instrumentation.AzureResource;
14+
15+
protected override ResourceBuilder InitializeResourceDetector(ResourceBuilder builder)
16+
{
17+
return builder.AddDetector(new AppServiceResourceDetector());
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright Grafana Labs
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
using OpenTelemetry.ResourceDetectors.Container;
7+
using OpenTelemetry.Resources;
8+
9+
namespace Grafana.OpenTelemetry
10+
{
11+
internal class ContainerResourceInitializer : InstrumentationInitializer
12+
{
13+
public override Instrumentation Id { get; } = Instrumentation.ContainerResource;
14+
15+
protected override ResourceBuilder InitializeResourceDetector(ResourceBuilder builder)
16+
{
17+
return builder.AddDetector(new ContainerResourceDetector());
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)