Skip to content

Commit

Permalink
Merge branch 'main' into prep-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
colleenmcginnis committed Jul 23, 2024
2 parents 431a8f1 + 3d093c9 commit cfad3c9
Show file tree
Hide file tree
Showing 32 changed files with 1,511 additions and 589 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
10 changes: 5 additions & 5 deletions docs/configure.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ an OTLP endpoint. This can be useful when you want to test applications without
|===

[discrete]
[[config-enabledelasticdefaults]]
===== `EnabledElasticDefaults`
[[config-elasticdefaults]]
===== `ElasticDefaults`

A comma-separated list of Elastic defaults to enable. This can be useful when you want to enable
only some of the Elastic Distribution for OpenTelemetry .NET opinionated defaults.

Valid options: `None`, `Tracing`, `Metrics`, `Logging`.
Valid options: `None`, `Traces`, `Metrics`, `Logs`, `All`.

Except for the `None` option, all other options can be combined.

Expand All @@ -242,12 +242,12 @@ OpenTelemetry SDK configuration. You may then choose to configure the various pr
as required.

In all other cases, the Elastic Distribution for OpenTelemetry .NET will enable the specified defaults. For example, to enable only
Elastic defaults only for tracing and metrics, set this value to `Tracing,Metrics`.
Elastic defaults only for tracing and metrics, set this value to `Traces,Metrics`.

[%header]
|===
| Environment variable name | `IConfiguration` key
| `ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS` | `Elastic:OpenTelemetry:EnabledElasticDefaults`
| `ELASTIC_OTEL_DEFAULTS_ENABLED` | `Elastic:OpenTelemetry:ElasticDefaults` |
|===

[%header]
Expand Down
58 changes: 24 additions & 34 deletions examples/Example.AutoInstrumentation/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,57 @@ 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
ENV OTEL_LOGS_EXPORTER=none
ENV OTEL_SERVICE_NAME=ExampleInstrumentation

ENV OTEL_LOG_LEVEL=info
ENV ELASTIC_OTEL_LOG_LEVEL=trace
ENV ELASTIC_OTEL_LOG_TARGETS=stdout
ENV OTEL_LOG_LEVEL=debug
ENV OTEL_DOTNET_AUTO_LOG_DIRECTORY=/app/logs
ENV ELASTIC_OTEL_LOG_TARGETS=stdout

ENV OTEL_DOTNET_AUTO_HOME="/app/otel"
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
28 changes: 28 additions & 0 deletions src/Elastic.OpenTelemetry/Configuration/ConfigCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.OpenTelemetry.Configuration;

internal class ConfigCell<T>(string key, T value)
{
public string Key { get; } = key;
public T? Value { get; private set; } = value;
public ConfigSource Source { get; set; } = ConfigSource.Default;

public void Assign(T value, ConfigSource source)
{
Value = value;
Source = source;
}

public override string ToString() => $"{Key}: '{Value}' from [{Source}]";
}
internal enum ConfigSource
{
Default, // Default value assigned within this class
Environment, // Loaded from an environment variable
// ReSharper disable once InconsistentNaming
IConfiguration, // Bound from an IConfiguration instance
Property // Set via property initializer
}
29 changes: 29 additions & 0 deletions src/Elastic.OpenTelemetry/Configuration/ElasticDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.OpenTelemetry.Configuration;

/// <summary>
/// Control which elastic defaults you want to include.
/// <para>NOTE: this is an expert level option only use this if you want to take full control of the OTEL configuration</para>
/// <para>defaults to <see cref="ElasticDefaults.All"/></para>
/// </summary>
[Flags]
public enum ElasticDefaults
{
/// <summary> No Elastic defaults will be included, acting effectively as a vanilla OpenTelemetry </summary>
None,

/// <summary> Include Elastic Distribution for OpenTelemetry .NET tracing defaults</summary>
Traces = 1 << 0, //1

/// <summary> Include Elastic Distribution for OpenTelemetry .NET metrics defaults</summary>
Metrics = 1 << 1, //2

/// <summary> Include Elastic Distribution for OpenTelemetry .NET logging defaults</summary>
Logs = 1 << 2, //4

/// <summary> (default) Include all Elastic Distribution for OpenTelemetry .NET logging defaults</summary>
All = ~0
}
Loading

0 comments on commit cfad3c9

Please sign in to comment.