From 426f1a6816be90d12cc8c1d6bcb3e8e2b176c771 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 23 Aug 2022 16:30:21 -0700 Subject: [PATCH] [Instrumentation.Process] Create src/test project files. (#596) --- .../comp_instrumentation_process.md | 41 ++++++++++++++++ .github/component_owners.yml | 2 + .../package-Instrumentation.Process.yml | 49 +++++++++++++++++++ opentelemetry-dotnet-contrib.sln | 14 ++++++ .../netstandard2.0/PublicAPI.Shipped.txt | 0 .../netstandard2.0/PublicAPI.Unshipped.txt | 4 ++ .../AssemblyInfo.cs | 25 ++++++++++ .../MeterProviderBuilderExtensions.cs | 47 ++++++++++++++++++ ...enTelemetry.Instrumentation.Process.csproj | 19 +++++++ .../ProcessInstrumentationOptions.cs | 24 +++++++++ .../ProcessMetrics.cs | 38 ++++++++++++++ .../README.md | 48 ++++++++++++++++++ ...metry.Instrumentation.Process.Tests.csproj | 24 +++++++++ .../ProcessMetricsTests.cs | 21 ++++++++ 14 files changed, 356 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/comp_instrumentation_process.md create mode 100644 .github/workflows/package-Instrumentation.Process.yml create mode 100644 src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt create mode 100644 src/OpenTelemetry.Instrumentation.Process/AssemblyInfo.cs create mode 100644 src/OpenTelemetry.Instrumentation.Process/MeterProviderBuilderExtensions.cs create mode 100644 src/OpenTelemetry.Instrumentation.Process/OpenTelemetry.Instrumentation.Process.csproj create mode 100644 src/OpenTelemetry.Instrumentation.Process/ProcessInstrumentationOptions.cs create mode 100644 src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs create mode 100644 src/OpenTelemetry.Instrumentation.Process/README.md create mode 100644 test/OpenTelemetry.Instrumentation.Process.Tests/OpenTelemetry.Instrumentation.Process.Tests.csproj create mode 100644 test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs diff --git a/.github/ISSUE_TEMPLATE/comp_instrumentation_process.md b/.github/ISSUE_TEMPLATE/comp_instrumentation_process.md new file mode 100644 index 0000000000..c91853c544 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/comp_instrumentation_process.md @@ -0,0 +1,41 @@ +--- +name: OpenTelemetry.Instrumentation.Process +about: Issue with OpenTelemetry.Instrumentation.Process +labels: comp:instrumentation.process +--- + +# Issue with OpenTelemetry.Instrumentation.Process + +List of [all OpenTelemetry NuGet +packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are +using (e.g. `OpenTelemetry 1.0.2`): + +* TBD + +Process version (e.g. `net462`, `net48`, `netcoreapp3.1`, `net6.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. diff --git a/.github/component_owners.yml b/.github/component_owners.yml index 969e074b50..d8973e3081 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -44,6 +44,8 @@ components: - moonheart src/OpenTelemetry.Instrumentation.Owin/: - codeblanch + src/OpenTelemetry.Instrumentation.Process/: + - Yun-Ting src/OpenTelemetry.Instrumentation.Quartz/: - maldago src/OpenTelemetry.Instrumentation.Runtime/: diff --git a/.github/workflows/package-Instrumentation.Process.yml b/.github/workflows/package-Instrumentation.Process.yml new file mode 100644 index 0000000000..3b4d609a0b --- /dev/null +++ b/.github/workflows/package-Instrumentation.Process.yml @@ -0,0 +1,49 @@ +name: Pack OpenTelemetry.Instrumentation.Process + +on: + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'warning' + push: + tags: + - 'Instrumentation.Process-*' # trigger when we create a tag with prefix "Instrumentation.Process-" + +jobs: + build-test-pack: + runs-on: ${{ matrix.os }} + env: + PROJECT: OpenTelemetry.Instrumentation.Process + + strategy: + matrix: + os: [windows-latest] + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # fetching all + + - name: Install dependencies + run: dotnet restore + + - name: dotnet build ${{env.PROJECT}} + run: dotnet build src/${{env.PROJECT}} --configuration Release --no-restore -p:Deterministic=true + + - name: dotnet test ${{env.PROJECT}} + run: dotnet test test/${{env.PROJECT}}.Tests + + - name: dotnet pack ${{env.PROJECT}} + run: dotnet pack src/${{env.PROJECT}} --configuration Release --no-build + + - name: Publish Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{env.PROJECT}}-packages + path: '**/${{env.PROJECT}}/bin/**/*.*nupkg' + + - name: Publish Nuget + run: | + nuget push **/${{env.PROJECT}}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }} \ No newline at end of file diff --git a/opentelemetry-dotnet-contrib.sln b/opentelemetry-dotnet-contrib.sln index 15e63c98a1..ec6c76ee44 100644 --- a/opentelemetry-dotnet-contrib.sln +++ b/opentelemetry-dotnet-contrib.sln @@ -233,6 +233,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentati EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.EventCounters.Tests", "test\OpenTelemetry.Instrumentation.EventCounters.Tests\OpenTelemetry.Instrumentation.EventCounters.Tests.csproj", "{DDA355A3-4D75-4F45-9A5E-E93C3EFB9896}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Process", "src\OpenTelemetry.Instrumentation.Process\OpenTelemetry.Instrumentation.Process.csproj", "{F811262D-D78A-4C4A-8A31-FFC458164BF2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Process.Tests", "test\OpenTelemetry.Instrumentation.Process.Tests\OpenTelemetry.Instrumentation.Process.Tests.csproj", "{61421ACF-5F90-491B-AFB3-14EF12CCA255}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -487,6 +491,14 @@ Global {DDA355A3-4D75-4F45-9A5E-E93C3EFB9896}.Debug|Any CPU.Build.0 = Debug|Any CPU {DDA355A3-4D75-4F45-9A5E-E93C3EFB9896}.Release|Any CPU.ActiveCfg = Release|Any CPU {DDA355A3-4D75-4F45-9A5E-E93C3EFB9896}.Release|Any CPU.Build.0 = Release|Any CPU + {F811262D-D78A-4C4A-8A31-FFC458164BF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F811262D-D78A-4C4A-8A31-FFC458164BF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F811262D-D78A-4C4A-8A31-FFC458164BF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F811262D-D78A-4C4A-8A31-FFC458164BF2}.Release|Any CPU.Build.0 = Release|Any CPU + {61421ACF-5F90-491B-AFB3-14EF12CCA255}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61421ACF-5F90-491B-AFB3-14EF12CCA255}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61421ACF-5F90-491B-AFB3-14EF12CCA255}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61421ACF-5F90-491B-AFB3-14EF12CCA255}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -562,6 +574,8 @@ Global {9FF9B46A-AD93-4B3F-92DA-6FDCC98FEA91} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA} {AE12EFB7-4B1A-46B8-B89A-0375252B10B1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} {DDA355A3-4D75-4F45-9A5E-E93C3EFB9896} = {2097345F-4DD3-477D-BC54-A922F9B2B402} + {F811262D-D78A-4C4A-8A31-FFC458164BF2} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} + {61421ACF-5F90-491B-AFB3-14EF12CCA255} = {2097345F-4DD3-477D-BC54-A922F9B2B402} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66} diff --git a/src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..0247a31728 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions +OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions.ProcessInstrumentationOptions() -> void +OpenTelemetry.Metrics.MeterProviderBuilderExtensions +static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder, System.Action configure = null) -> OpenTelemetry.Metrics.MeterProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.Process/AssemblyInfo.cs b/src/OpenTelemetry.Instrumentation.Process/AssemblyInfo.cs new file mode 100644 index 0000000000..dfc38d71b6 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/AssemblyInfo.cs @@ -0,0 +1,25 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Runtime.CompilerServices; + +[assembly: CLSCompliant(false)] +#if SIGNED +[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Process.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] +#else +[assembly: InternalsVisibleTo("OpenTelemetry.Instrumentation.Process.Tests")] +#endif diff --git a/src/OpenTelemetry.Instrumentation.Process/MeterProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.Process/MeterProviderBuilderExtensions.cs new file mode 100644 index 0000000000..516945ebd1 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/MeterProviderBuilderExtensions.cs @@ -0,0 +1,47 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using OpenTelemetry.Instrumentation.Process; +using OpenTelemetry.Internal; + +namespace OpenTelemetry.Metrics; + +/// +/// Extension methods to simplify registering of dependency instrumentation. +/// +public static class MeterProviderBuilderExtensions +{ + /// + /// Enables runtime instrumentation. + /// + /// being configured. + /// Runtime metrics options. + /// The instance of to chain the calls. + public static MeterProviderBuilder AddProcessInstrumentation( + this MeterProviderBuilder builder, + Action configure = null) + { + Guard.ThrowIfNull(builder); + + var options = new ProcessInstrumentationOptions(); + configure?.Invoke(options); + + var instrumentation = new ProcessMetrics(options); + builder.AddMeter(ProcessMetrics.MeterInstance.Name); + return builder.AddInstrumentation(() => instrumentation); + } +} diff --git a/src/OpenTelemetry.Instrumentation.Process/OpenTelemetry.Instrumentation.Process.csproj b/src/OpenTelemetry.Instrumentation.Process/OpenTelemetry.Instrumentation.Process.csproj new file mode 100644 index 0000000000..f4d3822b0c --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/OpenTelemetry.Instrumentation.Process.csproj @@ -0,0 +1,19 @@ + + + netstandard2.0 + dotnet process instrumentation for OpenTelemetry .NET + $(PackageTags);process + Instrumentation.Process- + true + true + + + + + + + + + + + diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessInstrumentationOptions.cs new file mode 100644 index 0000000000..bc5b7ddef8 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessInstrumentationOptions.cs @@ -0,0 +1,24 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Instrumentation.Process; + +/// +/// Options to define the process metrics. +/// +public class ProcessInstrumentationOptions +{ +} diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs new file mode 100644 index 0000000000..930279d669 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs @@ -0,0 +1,38 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System.Diagnostics.Metrics; +using System.Reflection; + +namespace OpenTelemetry.Instrumentation.Process; + +internal class ProcessMetrics +{ + internal static readonly AssemblyName AssemblyName = typeof(ProcessMetrics).Assembly.GetName(); + internal static readonly Meter MeterInstance = new(AssemblyName.Name, AssemblyName.Version.ToString()); + + static ProcessMetrics() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The options to define the metrics. + public ProcessMetrics(ProcessInstrumentationOptions options) + { + } +} diff --git a/src/OpenTelemetry.Instrumentation.Process/README.md b/src/OpenTelemetry.Instrumentation.Process/README.md new file mode 100644 index 0000000000..a0fc4b1faa --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.Process/README.md @@ -0,0 +1,48 @@ +# Process Instrumentation for OpenTelemetry .NET + +[![NuGet](https://img.shields.io/nuget/v/OpenTelemetry.Instrumentation.Process.svg)](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) +[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.Instrumentation.Process.svg)](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) + +This is an [Instrumentation +Library](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library), +which instruments [.NET](https://docs.microsoft.com/dotnet) and +collect telemetry about process behavior. + +## Steps to enable OpenTelemetry.Instrumentation.Process + +### Step 1: Install package + +Add a reference to +[`OpenTelemetry.Instrumentation.Process`](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Process) +package. + +```shell +dotnet add package OpenTelemetry.Instrumentation.Process +``` + +Add a reference to +[`OpenTelemetry.Exporter.Prometheus.HttpListener`](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.HttpListener) +package. + +```shell +dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.HttpListener +``` + +### Step 2: Enable Process instrumentation + +Process instrumentation should be enabled at application startup using the +`AddProcessInstrumentation` extension on `MeterProviderBuilder`: + +```csharp +using var meterProvider = Sdk.CreateMeterProviderBuilder() + .AddProcessInstrumentation() + .AddPrometheusHttpListener( + options => options.UriPrefixes = new string[] { "http://localhost:9464/" }) + .Build(); +``` + +## Metrics + +## References + +* [OpenTelemetry Project](https://opentelemetry.io/) diff --git a/test/OpenTelemetry.Instrumentation.Process.Tests/OpenTelemetry.Instrumentation.Process.Tests.csproj b/test/OpenTelemetry.Instrumentation.Process.Tests/OpenTelemetry.Instrumentation.Process.Tests.csproj new file mode 100644 index 0000000000..031dce0c55 --- /dev/null +++ b/test/OpenTelemetry.Instrumentation.Process.Tests/OpenTelemetry.Instrumentation.Process.Tests.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp3.1;net6.0 + $(TargetFrameworks);net462 + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + diff --git a/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs new file mode 100644 index 0000000000..701679c659 --- /dev/null +++ b/test/OpenTelemetry.Instrumentation.Process.Tests/ProcessMetricsTests.cs @@ -0,0 +1,21 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Instrumentation.Process.Tests; + +public class ProcessMetricsTests +{ +}