Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Feb 27, 2024
0 parents commit 66302da
Showing 18 changed files with 569 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: build
on:
- push
jobs:
build:
runs-on: ubuntu-22.04
name: Build
steps:
- uses: actions/checkout@v4
- name: Build
run: ./build.sh build
release:
if: startsWith(github.ref, 'refs/tags/v')
name: Release
needs: build
runs-on: ubuntu-22.04
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Release
run: ./build.sh release
- name: Release binary artifact
uses: ncipollo/release-action@v1
with:
bodyFile: dist/release-notes.md
token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
tmp/
*.sln
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cSpell.words": [
"ASPNETCORE",
"Edsger",
"Heemstra",
"opentelemetry",
"opsi",
"OTEL",
"otlp",
"Petroski",
"Pravin",
"Sipley",
"Skroob",
"Spaceballs",
"traceparent",
"tracestate",
"wireshark"
]
}
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# About

[![Build](https://github.com/rgl/opentelemetry-dotnet-playground/actions/workflows/build.yml/badge.svg)](https://github.com/rgl/opentelemetry-dotnet-playground/actions/workflows/build.yml)

This is a [OpenTelemetry .NET](https://github.com/open-telemetry/opentelemetry-dotnet) playground.

The following components are used:

![components](components.png)

# Usage (Ubuntu 22.04)

```bash
# create the environment defined in docker-compose.yml
# and leave it running in the background.
docker compose up -d --build

# show running containers.
docker compose ps

# show logs.
docker compose logs

# open a container network interface in wireshark.
./wireshark.sh quotes

# open the quotes service swagger.
xdg-open http://localhost:8000/swagger

# make a request.
http \
--verbose \
http://localhost:8000/quote

# make a failing request.
http \
--verbose \
http://localhost:8000/quote?opsi=opsi

# make a request that includes a parent trace.
# NB the dotnet trace id will be set to the traceparent trace id.
# NB the tracestate does not seem to be stored or propagated anywhere.
http \
--verbose \
http://localhost:8000/quote \
traceparent:00-f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1-2f2f2f2f2f2f2f2f-01 \
tracestate:x.client.state=example

# open aspire dashboard (metrics/traces/logs).
xdg-open http://localhost:18888

# destroy the environment.
docker compose down --remove-orphans --volumes --timeout=0
```

# Notes

* .NET uses the [Activity class](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.activity?view=net-8.0) to encapsulate the [W3C Trace Context](https://www.w3.org/TR/trace-context/).
* The Activity `Id` property contains to the [W3C `traceparent` header value](https://www.w3.org/TR/trace-context/#traceparent-header).
* It looks alike `00-98d483b6d0e3a6d012b11e23737faa50-6ac18089ab13c12e-01`.
* It has four fields: `version`, `trace-id`, `parent-id` (aka `span-id`), and `trace-flags`.

# Reference

* [W3C Trace Context](https://www.w3.org/TR/trace-context/).
* [opentelemetry-dotnet repository](https://github.com/open-telemetry/opentelemetry-dotnet).
* [OpenTelemetry in .NET documentation](https://opentelemetry.io/docs/languages/net/).
* [OpenTelemetry.Exporter.OpenTelemetryProtocol Environment Variables](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol#environment-variables).
76 changes: 76 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -euxo pipefail

GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-rgl/opentelemetry-dotnet-playground}"

QUOTES_SOURCE_URL="https://github.com/$GITHUB_REPOSITORY"
if [[ "${GITHUB_REF:-v0.0.0-dev}" =~ \/v([0-9]+(\.[0-9]+)+(-.+)?) ]]; then
QUOTES_VERSION="${BASH_REMATCH[1]}"
else
QUOTES_VERSION='0.0.0-dev'
fi
QUOTES_REVISION="${GITHUB_SHA:-0000000000000000000000000000000000000000}"
QUOTES_TITLE="$(basename "$GITHUB_REPOSITORY")"
QUOTES_DESCRIPTION="$(perl -ne 'print $1 if /\<Description\>(.+)\<\/Description\>/' <quotes/Quotes.csproj)"
QUOTES_LICENSE='ISC'
QUOTES_AUTHOR_NAME="$(perl -ne 'print $1 if /\<Company\>(.+)\<\/Company\>/' <quotes/Quotes.csproj)"
QUOTES_VENDOR="$QUOTES_AUTHOR_NAME"

function set-metadata {
sed -i -E "s,(\<Version\>).+(\</Version\>),\1$QUOTES_VERSION\2,g" quotes/Quotes.csproj
}

function build {
set-metadata
docker compose build
}

function release {
set-metadata
pushd quotes
local image="ghcr.io/$GITHUB_REPOSITORY:$QUOTES_VERSION"
local image_created="$(date --utc '+%Y-%m-%dT%H:%M:%S.%NZ')"
docker build \
--label "org.opencontainers.image.created=$image_created" \
--label "org.opencontainers.image.source=$QUOTES_SOURCE_URL" \
--label "org.opencontainers.image.version=$QUOTES_VERSION" \
--label "org.opencontainers.image.revision=$QUOTES_REVISION" \
--label "org.opencontainers.image.title=$QUOTES_TITLE" \
--label "org.opencontainers.image.description=$QUOTES_DESCRIPTION" \
--label "org.opencontainers.image.licenses=$QUOTES_LICENSE" \
--label "org.opencontainers.image.vendor=$QUOTES_VENDOR" \
--label "org.opencontainers.image.authors=$QUOTES_AUTHOR_NAME" \
-t "$image" \
.
docker push "$image"
popd
install -d dist
cat >dist/release-notes.md <<EOF
# Container image
[$QUOTES_SOURCE_URL/pkgs/container/$QUOTES_TITLE]($QUOTES_SOURCE_URL/pkgs/container/$QUOTES_TITLE)
\`\`\`bash
docker pull $image
\`\`\`
EOF
echo "$image"
}

function main {
local command="$1"; shift
case "$command" in
build)
build "$@"
;;
release)
release "$@"
;;
*)
echo "ERROR: Unknown command $command"
exit 1
;;
esac
}

main "$@"
Binary file added components.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions components.uxf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="15.1">
<zoom_level>10</zoom_level>
<element>
<id>UMLClass</id>
<coordinates>
<x>350</x>
<y>280</y>
<w>190</w>
<h>110</h>
</coordinates>
<panel_attributes>&lt;&lt;dashboard&gt;&gt;
&lt;&lt;metrics&gt;&gt;
&lt;&lt;traces&gt;&gt;
&lt;&lt;logs&gt;&gt;
aspire-dashboard</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>350</x>
<y>410</y>
<w>190</w>
<h>70</h>
</coordinates>
<panel_attributes>&lt;&lt;service&gt;&gt;
quotes</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>150</x>
<y>410</y>
<w>220</w>
<h>40</h>
</coordinates>
<panel_attributes>r1=http://localhost:8000
lt=()-</panel_attributes>
<additional_attributes>10.0;20.0;200.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>150</x>
<y>280</y>
<w>220</w>
<h>40</h>
</coordinates>
<panel_attributes>r1=http://localhost:18888
lt=()-</panel_attributes>
<additional_attributes>10.0;20.0;200.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>530</x>
<y>350</y>
<w>330</w>
<h>110</h>
</coordinates>
<panel_attributes>lt=-(</panel_attributes>
<additional_attributes>10.0;90.0;310.0;90.0;310.0;20.0;290.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>530</x>
<y>350</y>
<w>290</w>
<h>40</h>
</coordinates>
<panel_attributes>r2=http://aspire-dashboard:18889
lt=-()</panel_attributes>
<additional_attributes>10.0;20.0;270.0;20.0</additional_attributes>
</element>
</diagram>
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# see https://github.com/compose-spec/compose-spec/blob/master/spec.md
# see https://github.com/opencontainers/image-spec/blob/master/annotations.md
services:
aspire-dashboard:
# see https://mcr.microsoft.com/product/dotnet/nightly/aspire-dashboard/about
# see https://github.com/dotnet/dotnet-docker/issues/5128
# see https://github.com/dotnet/aspire/issues/2248#issuecomment-1947902486
image: mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.0.0-preview.4
ports:
# web ui.
- 18888:18888
# otlp grpc.
#- 18889:18889
restart: on-failure
quotes:
build: quotes
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://aspire-dashboard:18889
- OTEL_EXPORTER_OTLP_PROTOCOL=grpc
- ASPNETCORE_URLS=http://+:8000
ports:
# http api.
# http://localhost:8000
- 8000:8000
restart: on-failure
4 changes: 4 additions & 0 deletions quotes/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
out/
.*/
Loading

0 comments on commit 66302da

Please sign in to comment.