-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-example.sh
76 lines (62 loc) · 3.43 KB
/
run-example.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
set -euxo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $DIR
# Defaults for script behavior
enableProfiling=${enableProfiling:-1} # Set to zero to use only the DOTNET_STARTUP_HOOK
skipAppBuild=${skipAppBuild:-false}
keepContainers=${keepContainers:-false}
# Defaults for selected dotnet CLI commands.
configuration=${configuration:-Release}
aspNetAppTargetFramework=${aspNetAppTargetFramework:-netcoreapp3.1}
exampleAppTargetFramework=${exampleAppTargetFramework:-netcoreapp3.1}
exampleApp=${exampleApp:-ConsoleApp}
if [[ $aspNetAppTargetFramework == net462 ]];
then
vendorPluginTargetFramework=${exampleAppTargetFramework:-net462}
else
vendorPluginTargetFramework=${exampleAppTargetFramework:-netcoreapp3.1}
fi
# Handle the differences between launching a dll and exe
exampleAppExt="dll"
exampleAppDotnetCli="dotnet"
if [[ $exampleAppTargetFramework == net4* ]]; then
exampleAppExt="exe"
exampleAppDotnetCli=""
fi
# Defaults for selected OTEL env vars.
tracesExporter=${tracesExporter:-otlp}
metricsExporter=${metricsExporter:-otlp}
exampleAppInjectSDK=${exampleAppInjectSDK:-true}
# Build the applications
if [[ $skipAppBuild != "true" && $skipAppBuild != "1" ]]; then
# Build the server app
dotnet publish -f $aspNetAppTargetFramework -c $configuration ./examples/AspNetCoreMvc/Examples.AspNetCoreMvc.csproj
# build plugin for HTTP server app
dotnet publish -f $vendorPluginTargetFramework -c $configuration ./examples/Vendor.Distro/Examples.Vendor.Distro.csproj -o bin/tracer-home/$vendorPluginTargetFramework
# build the client app
dotnet publish -f $exampleAppTargetFramework -c $configuration ./examples/${exampleApp}/Examples.${exampleApp}.csproj
fi
function finish {
if [[ $keepContainers != "true" && $keepContainers != "1" ]]; then
docker-compose -f ./dev/docker-compose.yaml -f ./examples/docker-compose.yaml down
fi
kill 0 # kill background processes
}
trap finish EXIT
# Start the Docker containers
docker-compose -f ./dev/docker-compose.yaml -f ./examples/docker-compose.yaml up -d
# instrument and run HTTP server app in background
export {OTEL_DOTNET_AUTO_TRACES_PLUGINS,OTEL_DOTNET_AUTO_METRICS_PLUGINS}="Examples.AspNetCoreMvc.OtelSdkPlugin, Examples.AspNetCoreMvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:Examples.Vendor.Distro.Plugin, Examples.Vendor.Distro, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null"
ENABLE_PROFILING=${enableProfiling} OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES="MyCompany.MyProduct.MyLibrary" OTEL_SERVICE_NAME="aspnet-server" OTEL_TRACES_EXPORTER=${tracesExporter} OTEL_METRICS_EXPORTER=${metricsExporter} ./dev/instrument.sh ASPNETCORE_URLS="http://127.0.0.1:8080/" dotnet ./examples/AspNetCoreMvc/bin/${configuration}/${aspNetAppTargetFramework}/Examples.AspNetCoreMvc.dll &
unset OTEL_DOTNET_AUTO_TRACES_PLUGINS OTEL_DOTNET_AUTO_METRICS_PLUGINS
./dev/wait-local-port.sh 8080
# instrument and run HTTP client app
ENABLE_PROFILING=${enableProfiling} OTEL_SERVICE_NAME=${exampleApp} OTEL_TRACES_EXPORTER=${tracesExporter} OTEL_DOTNET_AUTO_LOAD_TRACER_AT_STARTUP=${exampleAppInjectSDK} ./dev/instrument.sh $exampleAppDotnetCli ./examples/${exampleApp}/bin/$configuration/${exampleAppTargetFramework}/Examples.${exampleApp}.${exampleAppExt}
# verify if it works
{
echo "Check traces at http://localhost:16686/search"
echo "Check metrics at http://localhost:9090"
echo "Press enter to close containers and stop example apps"
read
} 2> /dev/null