Skip to content

Commit

Permalink
ResourceDetectors - Process
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Dec 20, 2023
1 parent c558c17 commit c966b54
Show file tree
Hide file tree
Showing 20 changed files with 295 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/comp_resourcedetectors_process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: OpenTelemetry.ResourceDetectors.Process
about: OpenTelemetry.ResourceDetectors.Process
labels: comp:resourcedetectors.process
---

# Issue with OpenTelemetry.ResourceDetectors.Process

List of [all OpenTelemetry NuGet
packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are
using (e.g. `OpenTelemetry 1.3.2`):

* TBD

Runtime version (e.g. `net462`, `net48`, `net6.0`, `net7.0` etc. You can
find this information from the `*.csproj` file):

* TBD

**Is this a feature request or a bug?**

* [ ] Feature Request
* [ ] Bug

**What is the expected behavior?**

What do you expect to see?

**What is the actual behavior?**

What did you see instead? If you are reporting a bug, create a self-contained
project using the template of your choice and apply the minimum required code to
result in the issue you're observing. We will close this issue if:

* The repro project you share with us is complex. We can't investigate custom
projects, so don't point us to such, please.
* If we can not reproduce the behavior you're reporting.

## Additional Context

Add any other context about the feature request here.
5 changes: 5 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ flags:
paths:
- src/OpenTelemetry.ResourceDetectors.Azure

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

unittests-ResourceDetectors.ProcessRuntime:
carryforward: true
paths:
Expand Down
6 changes: 6 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ components:
- vishweshbankwar
src/OpenTelemetry.ResourceDetectors.Container/:
- iskiselev
src/OpenTelemetry.ResourceDetectors.Process/:
- Kielek
- lachmatt
src/OpenTelemetry.ResourceDetectors.ProcessRuntime/:
- Kielek
- lachmatt
Expand Down Expand Up @@ -144,6 +147,9 @@ components:
- vishweshbankwar
test/OpenTelemetry.ResourceDetectors.Container.Tests/:
- iskiselev
test/OpenTelemetry.ResourceDetectors.Process.Tests/:
- Kielek
- lachmatt
test/OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests/:
- Kielek
- lachmatt
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
owin: ['*/OpenTelemetry.Instrumentation.Owin*/**', 'examples/owin/**', '!**/*.md']
persistentstorage: ['*/OpenTelemetry.PersistentStorage*/**', '!**/*.md']
process: ['*/OpenTelemetry.Instrumentation.Process*/**', 'examples/process-instrumentation/**', '!**/*.md']
processruntime: ['*/OpenTelemetry.ResourceDetectors.ProcessRuntime*/**', '!**/*.md']
processdetector: ['*/OpenTelemetry.ResourceDetectors.Process/**', '*/OpenTelemetry.ResourceDetectors.Process.Tests/**', '!**/*.md']
processruntime: ['*/OpenTelemetry.ResourceDetectors.ProcessRuntime/**', '*/OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests/**', '!**/*.md']
redis: ['*/OpenTelemetry.Instrumentation.StackExchangeRedis*/**', 'examples/redis/**', '!**/*.md']
runtime: ['*/OpenTelemetry.Instrumentation.Runtime*/**', 'examples/runtime-instrumentation/**', '!**/*.md']
wcf: ['*/OpenTelemetry.Instrumentation.Wcf*/**', 'examples/wcf/**', '!**/*.md']
Expand All @@ -43,7 +44,10 @@ jobs:
'!*/OpenTelemetry.Instrumentation.AspNet*/**',
'!examples/AspNet/**',
'!*/OpenTelemetry.ResourceDetectors.Azure*/**',
'!*/OpenTelemetry.ResourceDetectors.ProcessRuntime*/**',
'!*/OpenTelemetry.ResourceDetectors.Process/**',
'!*/OpenTelemetry.ResourceDetectors.Process.Tests/**',
'!*/OpenTelemetry.ResourceDetectors.ProcessRuntime/**',
'!*/OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests/**',
'!*/OpenTelemetry.Instrumentation.EventCounters*/**',
'!examples/event-counters/**',
'!*/OpenTelemetry.Extensions/**',
Expand Down Expand Up @@ -178,6 +182,17 @@ jobs:
project-name: OpenTelemetry.Instrumentation.Process
code-cov-name: Instrumentation.Process

build-test-processdetector:
needs: detect-changes
if: |
contains(needs.detect-changes.outputs.changes, 'processdetector')
|| 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.Process
code-cov-name: ResourceDetectors.Process

build-test-processruntime:
needs: detect-changes
if: |
Expand Down Expand Up @@ -272,6 +287,7 @@ jobs:
OpenTelemetry.Instrumentation.Wcf.Tests.csproj,
OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj,
OpenTelemetry.ResourceDetectors.Azure.Tests.csproj,
OpenTelemetry.ResourceDetectors.Process.Tests.csproj
OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests.csproj
$failedProjects = @()
Expand Down Expand Up @@ -314,6 +330,7 @@ jobs:
contains(needs.detect-changes.outputs.changes, 'eventcounters')
|| contains(needs.detect-changes.outputs.changes, 'runtime')
|| contains(needs.detect-changes.outputs.changes, 'azure')
|| contains(needs.detect-changes.outputs.changes, 'processdetector')
|| contains(needs.detect-changes.outputs.changes, 'processruntime')
|| contains(needs.detect-changes.outputs.changes, 'aottestapp')
|| contains(needs.detect-changes.outputs.changes, 'build')
Expand All @@ -336,6 +353,7 @@ jobs:
build-test-owin,
build-test-persistentstorage,
build-test-process,
build-test-processdetector,
build-test-processruntime,
build-test-redis,
build-test-redis-integration,
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/package-ResourceDetectors.Process.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Pack OpenTelemetry.ResourceDetectors.Process

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

jobs:
call-build-test-pack:
permissions:
contents: write
uses: ./.github/workflows/Component.Package.yml
with:
project-name: OpenTelemetry.ResourceDetectors.Process
secrets: inherit
32 changes: 32 additions & 0 deletions build/Projects/OpenTelemetry.ResourceDetectors.Process.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.Process\OpenTelemetry.ResourceDetectors.Process.csproj" />
<SolutionProjects Include="$(RepoRoot)\test\OpenTelemetry.ResourceDetectors.Process.Tests\OpenTelemetry.ResourceDetectors.Process.Tests.csproj" />

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

<TestProjects Include="$(RepoRoot)\test\OpenTelemetry.ResourceDetectors.Process.Tests\OpenTelemetry.ResourceDetectors.Process.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>
16 changes: 16 additions & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\package-ResourceDetectors.AWS.yml = .github\workflows\package-ResourceDetectors.AWS.yml
.github\workflows\package-ResourceDetectors.Azure.yml = .github\workflows\package-ResourceDetectors.Azure.yml
.github\workflows\package-ResourceDetectors.Container.yml = .github\workflows\package-ResourceDetectors.Container.yml
.github\workflows\package-ResourceDetectors.Process.yml = .github\workflows\package-ResourceDetectors.Process.yml
.github\workflows\package-ResourceDetectors.ProcessRuntime.yml = .github\workflows\package-ResourceDetectors.ProcessRuntime.yml
.github\workflows\package-Sampler.AWS.yml = .github\workflows\package-Sampler.AWS.yml
.github\workflows\sanitycheck.yml = .github\workflows\sanitycheck.yml
Expand Down Expand Up @@ -322,13 +323,18 @@ 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.Process.proj = build\Projects\OpenTelemetry.ResourceDetectors.Process.proj
build\Projects\OpenTelemetry.ResourceDetectors.ProcessRuntime.proj = build\Projects\OpenTelemetry.ResourceDetectors.ProcessRuntime.proj
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.ProcessRuntime", "src\OpenTelemetry.ResourceDetectors.ProcessRuntime\OpenTelemetry.ResourceDetectors.ProcessRuntime.csproj", "{95372E82-CA5B-4C61-BD6C-74E6AB1970D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests", "test\OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests\OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests.csproj", "{B6157646-8EBA-464C-99B9-C386D474CB12}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Process", "src\OpenTelemetry.ResourceDetectors.Process\OpenTelemetry.ResourceDetectors.Process.csproj", "{A5FCDD8F-20FF-4657-804E-707EAD4FE31D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Process.Tests", "test\OpenTelemetry.ResourceDetectors.Process.Tests\OpenTelemetry.ResourceDetectors.Process.Tests.csproj", "{A5EF701C-439E-407F-8BB4-394166000C6D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -655,6 +661,14 @@ Global
{B6157646-8EBA-464C-99B9-C386D474CB12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6157646-8EBA-464C-99B9-C386D474CB12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6157646-8EBA-464C-99B9-C386D474CB12}.Release|Any CPU.Build.0 = Release|Any CPU
{A5FCDD8F-20FF-4657-804E-707EAD4FE31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5FCDD8F-20FF-4657-804E-707EAD4FE31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5FCDD8F-20FF-4657-804E-707EAD4FE31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5FCDD8F-20FF-4657-804E-707EAD4FE31D}.Release|Any CPU.Build.0 = Release|Any CPU
{A5EF701C-439E-407F-8BB4-394166000C6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5EF701C-439E-407F-8BB4-394166000C6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -753,6 +767,8 @@ Global
{048509D6-FB49-4B84-832A-90E55520B97B} = {824BD1DE-3FA8-4FE0-823A-FD365EAC78AF}
{95372E82-CA5B-4C61-BD6C-74E6AB1970D4} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{B6157646-8EBA-464C-99B9-C386D474CB12} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{A5FCDD8F-20FF-4657-804E-707EAD4FE31D} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{A5EF701C-439E-407F-8BB4-394166000C6D} = {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.Process.ProcessDetector
OpenTelemetry.ResourceDetectors.Process.ProcessDetector.Detect() -> OpenTelemetry.Resources.Resource!
OpenTelemetry.ResourceDetectors.Process.ProcessDetector.ProcessDetector() -> void
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.Process.ProcessDetector
OpenTelemetry.ResourceDetectors.Process.ProcessDetector.Detect() -> OpenTelemetry.Resources.Resource!
OpenTelemetry.ResourceDetectors.Process.ProcessDetector.ProcessDetector() -> void
10 changes: 10 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Process/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.Process.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")]
#else
[assembly: InternalsVisibleTo("OpenTelemetry.ResourceDetectors.Process.Tests")]
#endif
6 changes: 6 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Process/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## Unreleased

* Initial release of `OpenTelemetry.ResourceDetectors.Process` project
[1506](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1506)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>OpenTelemetry Extensions - Process Resource Detector.</Description>
<MinVerTagPrefix>ResourceDetectors.Process-</MinVerTagPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
</ItemGroup>
</Project>
32 changes: 32 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Process/ProcessDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NET6_0_OR_GREATER
using System;
#endif
using System.Collections.Generic;
using OpenTelemetry.Resources;

namespace OpenTelemetry.ResourceDetectors.Process;

/// <summary>
/// Process detector.
/// </summary>
public class ProcessDetector : IResourceDetector
{
/// <summary>
/// Detects the resource attributes for process.
/// </summary>
/// <returns>Resource with key-value pairs of resource attributes.</returns>
public Resource Detect()
{
return new Resource(new List<KeyValuePair<string, object>>(1)
{
#if NET6_0_OR_GREATER
new(ProcessSemanticConventions.AttributeProcessPid, Environment.ProcessId),
#else
new(ProcessSemanticConventions.AttributeProcessPid, System.Diagnostics.Process.GetCurrentProcess().Id),
#endif
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

namespace OpenTelemetry.ResourceDetectors.Process;

internal static class ProcessSemanticConventions
{
public const string AttributeProcessPid = "process.pid";
}
39 changes: 39 additions & 0 deletions src/OpenTelemetry.ResourceDetectors.Process/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Process Runtime Resource Detectors

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

## Getting Started

You need to install the
`OpenTelemetry.ResourceDetectors.Process` package to be able to use the
Process Runtime Resource Detectors.

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

## Usage

You can configure Process Runtime resource detector to
the `TracerProvider` with the following example below.

```csharp
using OpenTelemetry;
using OpenTelemetry.ResourceDetectors.Process;

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

The resource detectors will record the following metadata based on where
your application is running:

- **ProcessDetector**: `process.pid`.

## References

- [OpenTelemetry Project](https://opentelemetry.io/)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.EventCounters" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.StackExchangeRedis" />
<TrimmerRootAssembly Include="OpenTelemetry.ResourceDetectors.Azure" />
<TrimmerRootAssembly Include="OpenTelemetry.ResourceDetectors.Process" />
<TrimmerRootAssembly Include="OpenTelemetry.ResourceDetectors.ProcessRuntime" />

<TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Path="$(RepoRoot)\src\%(Identity)\%(Identity).csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Unit test project for Process Detector for OpenTelemetry</Description>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>$(SupportedNetTargets)</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.ResourceDetectors.Process\OpenTelemetry.ResourceDetectors.Process.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit c966b54

Please sign in to comment.