diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f188f3a5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,120 @@ +name: ci + +on: + push: + branches: [ main ] + paths-ignore: + - '**.md' + pull_request: + branches: [ main ] + workflow_dispatch: + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: true + DOTNET_NOLOGO: true + DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 + NUGET_XMLDOC_MODE: skip + TERM: xterm + +permissions: {} + +jobs: + build-test: + name: ${{ matrix.os-name }} + runs-on: ${{ matrix.runner }} + + outputs: + dotnet-sdk-version: ${{ steps.setup-dotnet.outputs.dotnet-version }} + + permissions: + attestations: write + contents: write + id-token: write + + strategy: + fail-fast: false + matrix: + include: + - os-name: macos + runner: macos-latest + - os-name: linux + runner: ubuntu-latest + - os-name: windows + runner: windows-latest + + steps: + + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + filter: 'tree:0' + show-progress: false + + - name: Setup .NET SDK + uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1 + id: setup-dotnet + + - name: Build + run: dotnet build --configuration Release + + - name: Test + run: dotnet test --configuration Release --logger:"GitHubActions;report-warnings=false" + + - name: Generate SBOM + uses: anchore/sbom-action@9f7302141466aa6482940f15371237e9d9f4c34a # v0.19.0 + with: + artifact-name: build-${{ matrix.os-name }}.spdx.json + output-file: ./artifacts/build.spdx.json + path: ./artifacts/bin + upload-release-assets: ${{ runner.os == 'Windows' }} + + - name: Attest artifacts + uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0 + if: | + runner.os == 'Windows' && + github.event.repository.fork == false && + (github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/')) + with: + subject-path: | + ./artifacts/bin/Grafana.OpenTelemetry*/release*/Grafana.OpenTelemetry*.dll + ./artifacts/package/release/* + + - name: Publish NuGet packages + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: packages-${{ matrix.os-name }} + path: ./artifacts/package/release + if-no-files-found: error + + validate-packages: + needs: build-test + runs-on: ubuntu-latest + steps: + + - name: Download packages + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: packages-windows + + - name: Setup .NET SDK + uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1 + with: + dotnet-version: ${{ needs.build-test.outputs.dotnet-sdk-version }} + + - name: Validate NuGet packages + shell: pwsh + run: | + dotnet tool install --global dotnet-validate --version 0.0.1-preview.304 --allow-roll-forward + $packages = Get-ChildItem -Filter "*.nupkg" | ForEach-Object { $_.FullName } + $invalidPackages = 0 + foreach ($package in $packages) { + dotnet validate package local $package + if ($LASTEXITCODE -ne 0) { + $invalidPackages++ + } + } + if ($invalidPackages -gt 0) { + Write-Output "::error::$invalidPackages NuGet package(s) failed validation." + exit 1 + } diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index df9538f3..00000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build - -on: - push: - branches: [ 'main*' ] - paths-ignore: - - '**.md' - pull_request: - branches: [ 'main*' ] - paths-ignore: - - '**.md' - -jobs: - build-test: - strategy: - fail-fast: false # ensures the entire test matrix is run, even if one permutation fails - matrix: - os: [ windows-latest, ubuntu-latest ] - version: [ net462, net8.0 ] - exclude: - - os: ubuntu-latest - version: net462 - permissions: {} - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # fetching all - persist-credentials: false - - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - - - name: Install dependencies - run: dotnet restore - - - name: Build - run: dotnet build --configuration Release --no-restore - - - name: Test ${{ matrix.version }} - run: dotnet test **/bin/**/${{ matrix.version }}/*.Tests.dll --logger:"console;verbosity=detailed" diff --git a/.gitignore b/.gitignore index 01d5ae1d..32374e2f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ mono_crash.* # Build results +[Aa]rtifacts/ [Bb]uild/ [Dd]ebug/ [Dd]ebugPublic/ diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..cd3b7614 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,34 @@ + + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + Grafana Labs + SHA256 + Grafana Labs + true + Copyright (c) Grafana Labs + true + true + false + en-US + + $(NoWarn);NU5104 + disable + Grafana_icon.png + Apache-2.0 + https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/ + package-readme.md + https://github.com/grafana/grafana-opentelemetry-dotnet/blob/main/CHANGELOG.md + false + OpenTelemetry;Grafana;Metrics;Logs;Traces;Observability;Monitoring + true + git + https://github.com/grafana/grafana-opentelemetry-dotnet + snupkg + true + true + + + + + + diff --git a/README.md b/README.md index 78a72c56..0f8e4a9e 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,8 @@ To engage with the Grafana Application Observability community: * [File an issue][issues] for bugs, issues, and feature suggestions. [app-o11y]: https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/ -[ci-badge]: https://github.com/grafana/grafana-opentelemetry-dotnet/actions/workflows/unit-tests.yml/badge.svg?branch=main -[ci-status]: https://github.com/grafana/grafana-opentelemetry-dotnet/actions/workflows/unit-tests.yml +[ci-badge]: https://github.com/grafana/grafana-opentelemetry-dotnet/actions/workflows/ci.yml/badge.svg?branch=main +[ci-status]: https://github.com/grafana/grafana-opentelemetry-dotnet/actions/workflows/ci.yml [discussions]: https://github.com/grafana/grafana-opentelemetry-dotnet/discussions [issues]: https://github.com/grafana/grafana-opentelemetry-dotnet/issues/new [oats-badge]: https://github.com/grafana/grafana-opentelemetry-dotnet/actions/workflows/oats.yml/badge.svg?branch=main diff --git a/global.json b/global.json index c51594ae..9f3b4cbd 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "rollForward": "latestFeature", - "version": "8.0.101", + "version": "8.0.410", "allowPrerelease": false } } diff --git a/package-readme.md b/package-readme.md new file mode 100644 index 00000000..83d58645 --- /dev/null +++ b/package-readme.md @@ -0,0 +1,63 @@ +# Grafana OpenTelemetry distribution for .NET + + +[![NuGet][package-badge-version]][package-download] +[![SDK][otel-badge]][otel] +[![Slack][slack-badge]][slack-channel] + + +## About + +This is a pre-configured and pre-packaged bundle of [OpenTelemetry .NET components][otel-contrib], +optimized for [Grafana Cloud Application Observability][app-o11y]. + +It requires only minimal setup and configuration and makes it very easy to emit +OpenTelemetry metrics, logs, and traces from your .NET application. + +## Getting Started + +### Step 1: Install package + +For installing the distribution with the full set of dependencies, add a +reference to the [`Grafana.OpenTelemetry`][package] package to your project. + +```sh +dotnet add package Grafana.OpenTelemetry +``` + +### Step 2: Enable the Grafana distribution at application startup + +The `UseGrafana` extension method on the `TracerProviderBuilder` or the +`MetricProviderBuilder` can be used to set up the Grafana distribution. By +default, telemetry data will be sent to Grafana Alloy or an OpenTelemetry collector +that runs locally and listens to default OTLP ports. + +```csharp +using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .UseGrafana() + .Build(); +``` + +Alternatively, you can send telemetry data directly to Grafana Cloud without +involving an agent or collector. This can be configured via the environment +variables `OTEL_EXPORTER_OTLP_PROTOCOL`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and +`OTEL_EXPORTER_OTLP_HEADERS`. + +For details on how to obtain those values, refer to +[Send data to the Grafana Cloud OTLP endpoint: Quickstart architecture][push-oltp]. + +## Documentation + +For detailed documentation and setup instructions, refer to [our documentation][docs]. + +[app-o11y]: https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/ +[docs]: https://github.com/grafana/grafana-opentelemetry-dotnet/tree/main/docs +[otel]: https://github.com/open-telemetry/opentelemetry-dotnet +[otel-badge]: https://img.shields.io/badge/OTel--SDK-1.9.0-blue?style=flat&logo=opentelemetry +[otel-contrib]: http://github.com/open-telemetry/opentelemetry-dotnet-contrib +[package]: https://www.nuget.org/packages/Grafana.OpenTelemetry +[package-badge-version]: https://img.shields.io/nuget/v/Grafana.OpenTelemetry?logo=nuget&label=NuGet&color=blue +[package-download]: https://www.nuget.org/profiles/Grafana +[push-oltp]: https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/#quickstart-architecture +[slack-badge]: https://img.shields.io/badge/%20Slack-%23app--o11y-brightgreen.svg?logo=slack +[slack-channel]: https://grafana.slack.com/archives/C05E87XRK3J diff --git a/src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj b/src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj index 5f2c9708..371106fc 100644 --- a/src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj +++ b/src/Grafana.OpenTelemetry.Base/Grafana.OpenTelemetry.Base.csproj @@ -1,21 +1,9 @@ - net8.0;netstandard2.0;net462 - disable - true - - Minimal Grafana distribution of OpenTelemetry .NET - Grafana Labs - Copyright (c) Grafana Labs - Apache-2.0 - OpenTelemetry;Grafana;Metrics;Logs;Traces;Observability;Monitoring - Grafana_icon.png - https://github.com/grafana/grafana-opentelemetry-dotnet/blob/main/CHANGELOG.md - https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/ - https://github.com/grafana/grafana-opentelemetry-dotnet - git + true + net8.0;netstandard2.0;net462 @@ -23,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -52,18 +40,14 @@ + + + + <_Parameter1>Grafana.OpenTelemetry.Tests - - - - - - - - diff --git a/src/Grafana.OpenTelemetry/Grafana.OpenTelemetry.csproj b/src/Grafana.OpenTelemetry/Grafana.OpenTelemetry.csproj index b846e65d..a82c11a6 100644 --- a/src/Grafana.OpenTelemetry/Grafana.OpenTelemetry.csproj +++ b/src/Grafana.OpenTelemetry/Grafana.OpenTelemetry.csproj @@ -1,21 +1,9 @@ - net8.0;netstandard2.0;net462 - disable - true - - Full Grafana distribution of OpenTelemetry .NET - Grafana Labs - Copyright (c) Grafana Labs - Apache-2.0 - OpenTelemetry;Grafana;Metrics;Logs;Traces;Observability;Monitoring - Grafana_icon.png - https://github.com/grafana/grafana-opentelemetry-dotnet/blob/main/CHANGELOG.md - https://grafana.com/docs/grafana-cloud/monitor-applications/application-observability/ - https://github.com/grafana/grafana-opentelemetry-dotnet - git + true + net8.0;netstandard2.0;net462