Skip to content

Commit

Permalink
Add AspNetCoreMvc as playground example (#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Jan 2, 2023
1 parent 683ea5b commit 345beca
Show file tree
Hide file tree
Showing 41 changed files with 686 additions and 65 deletions.
10 changes: 8 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ updates:
open-pull-requests-limit: 20

- package-ecosystem: nuget
directory: /examples/Client
directory: /examples/demo/Client
schedule:
interval: "daily"
open-pull-requests-limit: 20

- package-ecosystem: nuget
directory: /examples/Service
directory: /examples/demo/Service
schedule:
interval: "daily"
open-pull-requests-limit: 20

- package-ecosystem: nuget
directory: /examples/playground/AspNetCoreMvc
schedule:
interval: "daily"
open-pull-requests-limit: 20
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/examples.yml → .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: examples
name: demo

on:
push:
branches: [ main ]
paths:
- 'examples/**'
- examples/demo/**
pull_request:
branches: [ main ]
paths:
- 'examples/**'
- examples/demo/**
workflow_dispatch:

jobs:
Expand All @@ -17,6 +17,6 @@ jobs:

steps:
- uses: actions/checkout@v3.2.0
- name: Test examples
- name: Test demo
run: make all
working-directory: examples
working-directory: examples/demo
5 changes: 1 addition & 4 deletions .lycheeignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
http://localhost:8889/metrics
http://localhost:9090/graph
http://localhost:16686/search
http://localhost:13133/
localhost
75 changes: 43 additions & 32 deletions OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.AutoInstrumentation.Loader", "src\OpenTelemetry.AutoInstrumentation.Loader\OpenTelemetry.AutoInstrumentation.Loader.csproj", "{AB8596C1-CFDA-4A5E-9E9C-74A3DF9AED77}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}"
ProjectSection(SolutionItems) = preProject
test\test-applications\integrations\Directory.Build.props = test\test-applications\integrations\Directory.Build.props
examples\docker-compose.yaml = examples\docker-compose.yaml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.AutoInstrumentation", "src\OpenTelemetry.AutoInstrumentation\OpenTelemetry.AutoInstrumentation.csproj", "{6690361C-CCD8-42C4-A5CF-82D554B03A3D}"
EndProject
Expand Down Expand Up @@ -141,9 +137,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.Http.NetFra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.SqlClient.NetFramework", "test\test-applications\integrations\TestApplication.SqlClient.NetFramework\TestApplication.SqlClient.NetFramework.csproj", "{C5EB9F63-DE06-4444-A0DB-08F1CAC07B42}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "examples\Client\Client.csproj", "{F9A550C1-2284-4BE5-95B7-B46BE40E0638}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Client", "examples\demo\Client\Examples.Client.csproj", "{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Service", "examples\demo\Service\Examples.Service.csproj", "{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "examples\Service\Service.csproj", "{221AA0E8-2EA8-446C-9972-69F1FAA03E12}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.AspNetCoreMvc", "examples\playground\AspNetCoreMvc\Examples.AspNetCoreMvc.csproj", "{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -629,30 +627,42 @@ Global
{C5EB9F63-DE06-4444-A0DB-08F1CAC07B42}.Release|x64.Build.0 = Release|x64
{C5EB9F63-DE06-4444-A0DB-08F1CAC07B42}.Release|x86.ActiveCfg = Release|x86
{C5EB9F63-DE06-4444-A0DB-08F1CAC07B42}.Release|x86.Build.0 = Release|x86
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|x64.ActiveCfg = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|x64.Build.0 = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|x86.ActiveCfg = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Debug|x86.Build.0 = Debug|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|Any CPU.Build.0 = Release|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|x64.ActiveCfg = Release|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|x64.Build.0 = Release|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|x86.ActiveCfg = Release|Any CPU
{F9A550C1-2284-4BE5-95B7-B46BE40E0638}.Release|x86.Build.0 = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|x64.ActiveCfg = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|x64.Build.0 = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|x86.ActiveCfg = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Debug|x86.Build.0 = Debug|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|Any CPU.Build.0 = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|x64.ActiveCfg = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|x64.Build.0 = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|x86.ActiveCfg = Release|Any CPU
{221AA0E8-2EA8-446C-9972-69F1FAA03E12}.Release|x86.Build.0 = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|x64.ActiveCfg = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|x64.Build.0 = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|x86.ActiveCfg = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Debug|x86.Build.0 = Debug|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|Any CPU.Build.0 = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|x64.ActiveCfg = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|x64.Build.0 = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|x86.ActiveCfg = Release|Any CPU
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8}.Release|x86.Build.0 = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|x64.ActiveCfg = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|x64.Build.0 = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|x86.ActiveCfg = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Debug|x86.Build.0 = Debug|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|Any CPU.Build.0 = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|x64.ActiveCfg = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|x64.Build.0 = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|x86.ActiveCfg = Release|Any CPU
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2}.Release|x86.Build.0 = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|x64.ActiveCfg = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|x64.Build.0 = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|x86.ActiveCfg = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Debug|x86.Build.0 = Debug|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|Any CPU.Build.0 = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|x64.ActiveCfg = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|x64.Build.0 = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|x86.ActiveCfg = Release|Any CPU
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -702,8 +712,9 @@ Global
{F8C3A1FF-2333-45C8-9174-75F12526DFDD} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{5D0FECF8-1954-449D-8C42-5373D91154FA} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{C5EB9F63-DE06-4444-A0DB-08F1CAC07B42} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{F9A550C1-2284-4BE5-95B7-B46BE40E0638} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{221AA0E8-2EA8-446C-9972-69F1FAA03E12} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{6FCD22A7-E6DD-4452-8B0B-95A4D726AFA8} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{8BBF3519-CE93-4213-9AA0-8F5DEF3C50B2} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
{ACEB118B-767E-459F-AFD3-A52ED4ED08C6} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
Expand Down
12 changes: 12 additions & 0 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ partial class Build
.DependsOn(CompileNativeTestsWindows)
.DependsOn(CompileNativeTestsLinux);

Target CompileExamples => _ => _
.Description("Compiles all the example projects")
.Executes(() =>
{
foreach (var exampleProject in Solution.GetProjects("Examples.*"))
{
DotNetBuild(s => s
.SetProjectFile(exampleProject)
.SetConfiguration(BuildConfiguration));
}
});

Target PublishManagedProfiler => _ => _
.Unlisted()
.After(CompileManagedSrc)
Expand Down
1 change: 1 addition & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void DeleteReparsePoints(string path)
.Description("GitHub workflow entry point")
.DependsOn(Clean)
.DependsOn(BuildTracer)
.DependsOn(CompileExamples)
.DependsOn(NativeTests)
.DependsOn(ManagedTests);

Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ Get-Help Install-OpenTelemetryCore -Detailed

## Instrument a container

You can find an example using Docker Compose [here](../examples).
You can find our demonstrative example
that uses Docker Compose [here](../examples/demo).

You can also consider using
the [Kubernetes Operator for OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-operator).
Expand Down
7 changes: 3 additions & 4 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ For example:
./test/test-applications/integrations/TestApplication.Smoke/bin/x64/Release/net7.0/TestApplication.Smoke
```

### Running the examples
### Using playground application

You can use the example applications to see the local changes in action. See
[`examples/README.md`](../examples/README.md) for instructions on
how to run the examples.
You can use [the example playground application](../examples/playground)
to test the local changes.

## Release process

Expand Down
2 changes: 1 addition & 1 deletion docs/manual-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ by setting the `OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES` environmental variab
You can set the value to either `Examples.ManualInstrumentations.Registered`
or to `Examples.ManualInstrumentations.*`, which registers the entire prefix.

You can see a sample console application with manual instrumentation [here](../examples/Service/Program.cs).
You can see a sample console application with manual instrumentation [here](../examples/demo/Service/Program.cs).

> Note that an `Activity` created for `NonRegistered.ManualInstrumentations`
`ActivitySource` is not handled by the OpenTelemetry Automatic Instrumentation.
Expand Down
2 changes: 1 addition & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@

1. For a non-RC and non-beta release, update the version in:

- [`examples/Dockerfile`](../examples/Dockerfile)
- [`examples/demo/Dockerfile`](../examples/demo/Dockerfile)
- [OpenTelemetry Operator](https://github.com/open-telemetry/opentelemetry-operator/blob/main/autoinstrumentation/dotnet/version.txt)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 10 additions & 9 deletions examples/README.md → examples/demo/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Demonstrative example
# Demo

## Description

This example uses Docker Compose.
This is a demonstarative example that uses Docker Compose.

It consists of following services:

1. [`client`](Client) - console application that makes a HTTP GET request
instrumented with OpenTelemetry .NET Automatic Instrumentation.
1. [`service`](Service) - simple HTTP server using SQL Server.
2. [`service`](Service) - simple HTTP server using SQL Server.
The application additionally has manual instrumentation (traces, metrics, logs)
on top of the automatic instrumentation.
1. `sqlserver` - [Microsoft SQL Server](https://hub.docker.com/_/microsoft-mssql-server)
3. `sqlserver` - [Microsoft SQL Server](https://hub.docker.com/_/microsoft-mssql-server)
used by `service`
1. `otel-collector` - [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/)
4. `otel-collector` - [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/)
which collects the telemetry send by `client` and `service`
1. `jaeger` - [Jaeger](https://www.jaegertracing.io/) as traces backend
1. `prometheus` - [Prometheus](https://prometheus.io/) as metrics backend
5. `jaeger` - [Jaeger](https://www.jaegertracing.io/) as traces backend
6. `prometheus` - [Prometheus](https://prometheus.io/) as metrics backend

## Usage

Expand All @@ -35,8 +36,8 @@ make

The following Web UI endpoints are exposed:

- <http://localhost:16686/search> - traces
- <http://localhost:9090/graph> - metrics
- <http://localhost:16686/search> - traces (Jaeger)
- <http://localhost:9090/graph> - metrics (Prometheus)

You can also find the exported telemetry in the `log` directory.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
using Microsoft.Data.SqlClient;

// .NET Diagnostics: create the span factory
using var activitySource = new ActivitySource("MyCompany.Service");
using var activitySource = new ActivitySource("Examples.Service");

// .NET Diagnostics: create a metric
using var meter = new Meter("MyCompany.Service", "1.0");
using var meter = new Meter("Examples.Service", "1.0");
var successCounter = meter.CreateCounter<long>("srv.successes.count", description: "Number of successful responses");

var builder = WebApplication.CreateBuilder(args);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
build:
context: ./Client
dockerfile: ../Dockerfile # installs OpenTelemetry .NET Automatic Instrumentation
entrypoint: "./out/Client http://service:5000"
entrypoint: "./out/Examples.Client http://service:5000"
env_file:
- otel-dotnet.env # enables OpenTelemetry .NET Automatic Instrumentation
environment:
Expand All @@ -20,16 +20,16 @@ services:
build:
context: ./Service
dockerfile: ../Dockerfile # installs OpenTelemetry .NET Automatic Instrumentation
entrypoint: "./out/Service --urls http://*:5000"
entrypoint: "./out/Examples.Service --urls http://*:5000"
env_file:
- otel-dotnet.env # enable OpenTelemetry .NET Automatic Instrumentation
environment:
DB_CONNECTION: "Server=sqlserver,1433;User=sa;Password=yourStrong(!)Password;TrustServerCertificate=True;"
# OpenTelemetry environmental variables:
OTEL_SERVICE_NAME: "service"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4318"
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES: "MyCompany.Service"
OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES: "MyCompany.Service"
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES: "Examples.Service"
OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES: "Examples.Service"
depends_on:
- sqlserver
- otel-collector
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions examples/playground/AspNetCoreMvc/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <copyright file="ApiController.cs" company="OpenTelemetry Authors">
// 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.
// </copyright>

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Examples.AspNetCoreMvc.Controllers;

[Route("api")]
public class ApiController : ControllerBase
{
[HttpGet]
[Route("delay/{seconds}")]
public ActionResult Delay(int seconds)
{
Thread.Sleep(TimeSpan.FromSeconds(seconds));
return Ok(seconds);
}

[HttpGet]
[Route("delay-async/{seconds}")]
public async Task<ActionResult> DelayAsync(int seconds)
{
await Task.Delay(TimeSpan.FromSeconds(seconds));
return Ok(seconds);
}
}
Loading

0 comments on commit 345beca

Please sign in to comment.