Skip to content

Commit

Permalink
Ship auto instrumentation plugin as part of Elastic.OpenTelemetry dir…
Browse files Browse the repository at this point in the history
…ectly (#122)

* Ship auto instrumentation plugin as part of Elastic.OpenTelemetry directly

* rename Plugin to AutoInstrumentationPlugin
  • Loading branch information
Mpdreamz committed Jul 16, 2024
1 parent 2a4f748 commit 5c60036
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 60 deletions.
7 changes: 0 additions & 7 deletions Elastic.OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppHost", "examples\AppHost
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "examples\ServiceDefaults\ServiceDefaults.csproj", "{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.OpenTelemetry.AutoInstrumentationPlugin", "src\Elastic.OpenTelemetry.AutoInstrumentationPlugin\Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj", "{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.AutoInstrumentation", "examples\Example.AutoInstrumentation\Example.AutoInstrumentation.csproj", "{F3AA76EC-C7D8-42DA-947D-4376B6562772}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoInstrumentation.IntegrationTests", "tests\AutoInstrumentation.IntegrationTests\AutoInstrumentation.IntegrationTests.csproj", "{782E4DC1-8186-4BAC-B2F4-89E6DF22A4DD}"
Expand Down Expand Up @@ -101,10 +99,6 @@ Global
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5}.Release|Any CPU.Build.0 = Release|Any CPU
{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B61D749B-21E5-430D-B50D-CA02EBAA7F2F}.Release|Any CPU.Build.0 = Release|Any CPU
{F3AA76EC-C7D8-42DA-947D-4376B6562772}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3AA76EC-C7D8-42DA-947D-4376B6562772}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3AA76EC-C7D8-42DA-947D-4376B6562772}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -127,7 +121,6 @@ Global
{863CAB86-5EB0-4E9F-B01D-F51687EC6597} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{206203BD-3EBA-4E9A-8881-1189D95AB037} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{A3D1ED4D-863B-45D7-9829-305DD33B4CE5} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{B61D749B-21E5-430D-B50D-CA02EBAA7F2F} = {E622CFF2-C6C4-40FB-BE42-7C4F2B38B75A}
{F3AA76EC-C7D8-42DA-947D-4376B6562772} = {4E95C87B-655B-4BC3-8F2A-DF06B7AAB7E9}
{782E4DC1-8186-4BAC-B2F4-89E6DF22A4DD} = {AAD39891-0B70-47FA-A212-43E1AAE5DF56}
EndGlobalSection
Expand Down
53 changes: 22 additions & 31 deletions examples/Example.AutoInstrumentation/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,42 @@ RUN OTEL_DOTNET_AUTO_HOME="/app/otel" sh otel-dotnet-auto-install.sh


FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build_example
WORKDIR /src
COPY ["examples/Example.AutoInstrumentation/Example.AutoInstrumentation.csproj", "examples/Example.AutoInstrumentation/"]
RUN dotnet restore "examples/Example.AutoInstrumentation/Example.AutoInstrumentation.csproj"
COPY . .
WORKDIR "/src/examples/Example.AutoInstrumentation"
RUN dotnet build "Example.AutoInstrumentation.csproj" -c Release -o /app/build_example
ENV _PROJECT="Example.AutoInstrumentation"
ENV _PROJECTPATH="${_PROJECT}/${_PROJECT}.csproj"
WORKDIR /work
COPY ["examples/${_PROJECTPATH}", "examples/${_PROJECT}/"]
RUN dotnet restore "examples/${_PROJECT}"
COPY .git .git
COPY examples/${_PROJECT} examples/${_PROJECT}
WORKDIR "/work/examples/${_PROJECT}"
RUN dotnet build "${_PROJECT}.csproj" -c Release -o /app/build_example

FROM build_example AS publish_example
RUN dotnet publish "Example.AutoInstrumentation.csproj" -c Release -o /app/example /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build_plugin
WORKDIR /src
COPY ["README.md", "."]
COPY ["LICENSE.txt", "."]
COPY ["NOTICE.txt", "."]
COPY ["src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj", "src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/"]
RUN dotnet restore "src/Elastic.OpenTelemetry.AutoInstrumentationPlugin/Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj"
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build_distro
ENV _PROJECT="Elastic.OpenTelemetry"
ENV _PROJECTPATH="${_PROJECT}/${_PROJECT}.csproj"
WORKDIR /work
COPY ["src/${_PROJECTPATH}", "src/${_PROJECT}/"]
RUN dotnet restore "src/${_PROJECTPATH}"
COPY . .
WORKDIR "/src/src/Elastic.OpenTelemetry.AutoInstrumentationPlugin"
RUN dotnet build "Elastic.OpenTelemetry.AutoInstrumentationPlugin.csproj" -c release
RUN mkdir -p /app/temp
RUN cp -r /src/.artifacts/bin /app/temp
WORKDIR "/work/src/${_PROJECT}"
RUN dotnet build "${_PROJECT}.csproj" -c Release

FROM otel AS final
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETVARIANT
WORKDIR /app
COPY --from=publish_example /app/example /app/example
COPY --from=otel /app/otel /app/otel

# This `RUN true` is a bit of magic that I don't care to understand
# https://github.com/moby/moby/issues/37965
# Seems to relate to the fs driver on GitHub Actions failing to copy files from the `build_plugin` layer.
# Hence we copy the whole .artifacts/bin folder manually and copy the files to /app/otel/net
RUN true
COPY --from=build_plugin /app/temp /app/temp
RUN true
RUN ls -al /app/temp/bin
RUN mkdir -p /app/otel/net
RUN cp "/app/temp/bin/Elastic.OpenTelemetry.AutoInstrumentationPlugin/release_net8.0/Elastic.OpenTelemetry.AutoInstrumentationPlugin.dll" /app/otel/net/
RUN cp "/app/temp/bin/Elastic.OpenTelemetry/release_net8.0/Elastic.OpenTelemetry.dll" /app/otel/net/
COPY --from=build_distro /work/.artifacts/bin/Elastic.OpenTelemetry/release_netstandard2.1/Elastic.OpenTelemetry.dll /app/otel/net/
COPY --from=build_distro /work/.artifacts/bin/Elastic.OpenTelemetry/release_netstandard2.1/Elastic.OpenTelemetry.pdb /app/otel/net/

ENV CORECLR_ENABLE_PROFILING="1"
ENV CORECLR_PROFILER="{918728DD-259F-4A6A-AC2B-B85E1B658318}"
ENV CORECLR_PROFILER_PATH="/app/otel/linux-${TARGETARCH}/OpenTelemetry.AutoInstrumentation.Native.so"
ENV OTEL_DOTNET_AUTO_PLUGINS="Elastic.OpenTelemetry.AutoInstrumentationPlugin.ElasticAutoInstrumentationPlugin, Elastic.OpenTelemetry.AutoInstrumentationPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=069ca2728db333c1"
ENV OTEL_DOTNET_AUTO_PLUGINS="Elastic.OpenTelemetry.AutoInstrumentationPlugin, Elastic.OpenTelemetry, Version=1.0.0.0, Culture=neutral, PublicKeyToken=069ca2728db333c1"

ENV OTEL_TRACES_EXPORTER=none
ENV OTEL_METRICS_EXPORTER=none
Expand All @@ -83,4 +72,6 @@ ENV DOTNET_ADDITIONAL_DEPS="/app/otel/AdditionalDeps"
ENV DOTNET_SHARED_STORE="/app/otel/store"
ENV DOTNET_STARTUP_HOOKS="/app/otel/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll"

ENV OTEL_DOTNET_AUTO_FAIL_FAST_ENABLED=true

ENTRYPOINT ["dotnet", "/app/example/Example.AutoInstrumentation.dll"]
20 changes: 20 additions & 0 deletions examples/Example.AutoInstrumentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Example auto instrumentation plugin for OpenTelemetry .NET

This is a very minimal .NET application that we use to validate our OpenTelemetry plugin loads correctly

This happens automated through our testing setup:

```bash
$ ./build.sh test --test-suite=integration
```

Which ends up running the tests in `/tests/AutoInstrumentation.IntegrationTests`


To quickly see the `DockerFile` in action run the following from the root of this repository.


```bash
$ docker build -t example.autoinstrumentation:latest -f examples/Example.AutoInstrumentation/Dockerfile --no-cache . && \
docker run -it --rm -p 5000:8080 --name autoin example.autoinstrumentation:latest
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Elastic.OpenTelemetry.AutoInstrumentationPlugin;
namespace Elastic.OpenTelemetry;

/// <summary>
/// Elastic Distribution for OpenTelemetry .NET plugin for Auto Instrumentation.
/// <para>Ensures all signals are rich enough to report to Elastic</para>
/// </summary>
// ReSharper disable once UnusedType.Global
public class ElasticAutoInstrumentationPlugin
public class AutoInstrumentationPlugin
{
private readonly ILogger _logger;
private readonly EventListener _eventListener;

/// <inheritdoc cref="ElasticAutoInstrumentationPlugin"/>
public ElasticAutoInstrumentationPlugin()
/// <inheritdoc cref="AutoInstrumentationPlugin"/>
public AutoInstrumentationPlugin()
{
var options = new ElasticOpenTelemetryBuilderOptions();
var (eventListener, logger) = ElasticOpenTelemetryBuilder.Bootstrap(options);
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<IsPackable>True</IsPackable>
<PolyPublic>false</PolyPublic>
<NoWarn>$(NoWarn);OTEL1000</NoWarn>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard2.0')) OR $(TargetFramework.StartsWith('net4'))">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task ObserveDistributionPluginLoad()
var output = exampleApplicationContainer.FailureTestOutput();
output.Should()
.NotBeNullOrWhiteSpace()
.And.Contain("Elastic OpenTelemetry Distribution:")
.And.Contain("Elastic Distribution for OpenTelemetry .NET:")
.And.Contain("ElasticOpenTelemetryBuilder initialized")
.And.Contain("Added 'Elastic.OpenTelemetry.Processors.ElasticCompatibilityProcessor'");

Expand Down

0 comments on commit 5c60036

Please sign in to comment.