Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ runs:
uses: actions/setup-dotnet@v4
with:
global-json-file: ./global.json
# 6.x is required for the release-notes tool.
# 7.x is required for the dotnet-project-licenses tool.
dotnet-version: |
6.x
7.x
8.x

- id: dotnet
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let private generateApiChanges _ =
"assembly-differ"
$"previous-nuget|%s{p}|%s{currentVersion}|%s{tfm}";
//$"directory|.artifacts/bin/%s{p}/release/%s{tfm}";
$"directory|.artifacts/bin/%s{p}/release_net8.0";
$"directory|.artifacts/bin/%s{p}/release_net9.0";
"-a"; "true"; "--target"; p; "-f"; "github.amrom.workers.devment"; "--output"; outputFile
]
exec { run "dotnet" args }
Expand Down
4 changes: 2 additions & 2 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"assembly-differ": {
"version": "0.15.0",
"version": "0.16.0",
"commands": [
"assembly-differ"
]
Expand All @@ -21,7 +21,7 @@
]
},
"nupkg-validator": {
"version": "0.6.0",
"version": "0.7.0",
"commands": [
"nupkg-validator"
]
Expand Down
9 changes: 3 additions & 6 deletions examples/Example.AspNetCore.Mvc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
// 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

using OpenTelemetry;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

builder.AddElasticOpenTelemetry();

builder.Services
.AddHttpClient()
.AddElasticOpenTelemetry()
.WithTracing(t => t.AddAspNetCoreInstrumentation()); // This is redundant but used in manual testing for now
.AddHttpClient();

builder.Services
.AddControllersWithViews();
Expand Down
3 changes: 2 additions & 1 deletion examples/Example.AspNetCore.Mvc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"Elastic": {
"OpenTelemetry": {
"LogLevel": "Trace",
"LogDirectory": "C:\\Logs\\BrandNewLogs"
"LogDirectory": "C:\\Logs\\BrandNewLogs",
"LogTargets": "file;stdout"
}
}
}
2 changes: 0 additions & 2 deletions examples/ServiceDefaults/ServiceDefaults.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.11.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="1.11.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.11.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>True</IsPackable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net462;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>True</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.10.0" GeneratePathProperty="true" PrivateAssets="contentfiles" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.AutoInstrumentation" Version="1.10.0" GeneratePathProperty="true" PrivateAssets="contentfiles" />
</ItemGroup>

<ItemGroup>
<Content Remove="README.md" />
Expand All @@ -23,23 +23,22 @@

<!-- ensure we remove the linked instrument.sh from base OpenTelemetry.AutoInstrumentation
and link it as _instrument.sh since we manually copy it over in the prebuild event -->

<Content Update="instrument.sh" CopyToPublishDirectory="Never" CopyToOutputDirectory="Never" />
<Content Remove="instrument.sh" />
<Content Include="_instrument.sh" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Pack="True" PackagePath="contentFiles/any/any/_instrument.sh" />
<Content Include="instrument.sh" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Pack="True" PackagePath="contentFiles/any/any/instrument.sh" />

<Content Include="instrument.props" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Pack="True" PackagePath="build/elastic.opentelemetry.autoinstrumentation.props" />

</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<!-- Copies the content files manually as physical files in the source repository -->
<!-- we manually repackage these as contentfiles (albeit renamed) -->
<!-- we manually repackage these as contentfiles (albeit renamed) -->
<Copy SourceFiles="$(PkgOpenTelemetry_AutoInstrumentation)/contentFiles/any/any/instrument.cmd" DestinationFiles="$(MSBuildThisFileDirectory)/_instrument.cmd" />
<Copy SourceFiles="$(PkgOpenTelemetry_AutoInstrumentation)/contentFiles/any/any/instrument.sh" DestinationFiles="$(MSBuildThisFileDirectory)/_instrument.sh" />
</Target>

<ItemGroup>
<ProjectReference Include="..\Elastic.OpenTelemetry\Elastic.OpenTelemetry.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ public void ConfigureLogsOptions(OpenTelemetryLoggerOptions options)
public ResourceBuilder ConfigureResource(ResourceBuilder builder) =>
!_bootstrapInfo.Succeeded || _components is null
? builder
: builder.AddElasticDistroAttributes();
: builder.WithElasticDefaults();
}
15 changes: 13 additions & 2 deletions src/Elastic.OpenTelemetry/Core/SignalBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ public static bool IsSignalEnabled(ElasticOpenTelemetryComponents? components, C
return true;
}

public static string GetBuilderIdentifier<T>(this T builder) where T : class =>
!ElasticOpenTelemetry.BuilderStateTable.TryGetValue(builder, out var state)
? builder.GetHashCode().ToString()
: $"{state.InstanceIdentifier}:{builder.GetHashCode()}";

/// <summary>
/// Hold common logic for configuring a builder, either a TracerProviderBuilder,
/// Holds common logic for configuring a builder, either a TracerProviderBuilder,
/// MeterProviderBuilder or LoggingProviderBuilder.
/// </summary>
public static bool ConfigureBuilder<T>(
Expand Down Expand Up @@ -184,7 +189,13 @@ public static void AddInstrumentationViaReflection<T>(T builder, ElasticOpenTele
if (components.Options.SkipInstrumentationAssemblyScanning)
return;

var logger = components.Logger;
AddInstrumentationViaReflection(builder, components.Logger, assemblyInfos);
}

[RequiresUnreferencedCode("Accesses assemblies and methods dynamically using refelction. This is by design and cannot be made trim compatible.")]
public static void AddInstrumentationViaReflection<T>(T builder, ILogger logger, ReadOnlySpan<InstrumentationAssemblyInfo> assemblyInfos)
where T : class
{
var builderTypeName = builder.GetType().Name;
var assemblyLocation = AppContext.BaseDirectory;

Expand Down
72 changes: 42 additions & 30 deletions src/Elastic.OpenTelemetry/Diagnostics/LoggerMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,55 +38,67 @@ internal static partial class LoggerMessages
[LoggerMessage(EventId = 8, EventName = "LocatedInstrumentationAssembly", Level = LogLevel.Trace, Message = "Located {AssemblyFilename} in {Path}.")]
public static partial void LogLocatedInstrumentationAssembly(this ILogger logger, string assemblyFilename, string path);

[LoggerMessage(EventId = 9, EventName = "AddedInstrumentation", Level = LogLevel.Debug, Message = "Added {InstrumentationName} to {ProviderBuilderType}.")]
// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 9, Level = LogLevel.Trace, Message = "{ProcessorName} found `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void FoundTag(this ILogger logger, string processorName, string attributeName, string attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 9, Level = LogLevel.Trace, Message = "{ProcessorName} found `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void FoundTag(this ILogger logger, string processorName, string attributeName, int attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 10, Level = LogLevel.Trace, Message = "{ProcessorName} set `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void SetTag(this ILogger logger, string processorName, string attributeName, string attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 10, Level = LogLevel.Trace, Message = "{ProcessorName} set `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void SetTag(this ILogger logger, string processorName, string attributeName, int attributeValue);

[LoggerMessage(EventId = 11, Level = LogLevel.Debug, Message = "Added '{ProcessorTypeName}' processor to {BuilderTypeName} with ID '{BuilderIdentifier}'.")]
public static partial void LogProcessorAdded(this ILogger logger, string processorTypeName, string builderTypeName, string builderIdentifier);

[LoggerMessage(EventId = 12, Level = LogLevel.Debug, Message = "Added '{MeterName}' meter to {BuilderTypeName}.")]
public static partial void LogMeterAdded(this ILogger logger, string meterName, string builderTypeName);

[LoggerMessage(EventId = 13, Level = LogLevel.Error, Message = "Unable to configure {BuilderTypeName} with EDOT .NET logging defaults.")]
public static partial void UnableToConfigureLoggingDefaultsError(this ILogger logger, string builderTypeName);

[LoggerMessage(EventId = 14, EventName = "AddedInstrumentation", Level = LogLevel.Debug, Message = "Added {InstrumentationName} to {ProviderBuilderType}.")]
public static partial void LogAddedInstrumentation(this ILogger logger, string instrumentationName, string providerBuilderType);

[LoggerMessage(EventId = 10, EventName = "AddedInstrumentationViaReflection", Level = LogLevel.Debug, Message = "Added {InstrumentationName} to {ProviderBuilderType} via reflection assembly scanning.")]
[LoggerMessage(EventId = 15, EventName = "AddedInstrumentationViaReflection", Level = LogLevel.Debug, Message = "Added {InstrumentationName} to {ProviderBuilderType} via reflection assembly scanning.")]
public static partial void LogAddedInstrumentationViaReflection(this ILogger logger, string instrumentationName, string providerBuilderType);

[LoggerMessage(EventId = 11, EventName = "HttpInstrumentationFound", Level = LogLevel.Debug, Message = "The contrib HTTP instrumentation library was located alongside the executing assembly. " +
"Skipping adding native {InstrumentationType} instrumentation from the 'System.Net.Http' ActivitySource.")]
public static partial void LogHttpInstrumentationFound(this ILogger logger, string instrumentationType);
[LoggerMessage(EventId = 16, EventName = "HttpInstrumentationFound", Level = LogLevel.Debug, Message = "The contrib HTTP instrumentation library was located alongside the executing assembly. " +
"Skipping adding native {InstrumentationType} instrumentation from the 'System.Net.Http' ActivitySource to '{ProviderBuilderType}' with ID '{BuilderIdentifier}'.")]
public static partial void LogHttpInstrumentationFound(this ILogger logger, string instrumentationType, string providerBuilderType, string builderIdentifier);

[LoggerMessage(EventId = 12, EventName = "RuntimeInstrumentationFound", Level = LogLevel.Debug, Message = "The contrib runtime instrumentation library was located alongside the executing assembly. " +
[LoggerMessage(EventId = 17, EventName = "RuntimeInstrumentationFound", Level = LogLevel.Debug, Message = "The contrib runtime instrumentation library was located alongside the executing assembly. " +
"Skipping adding native metric instrumentation from the 'System.Runtime' ActivitySource.")]
public static partial void LogRuntimeInstrumentationFound(this ILogger logger);

[LoggerMessage(EventId = 13, EventName = "SignalDisabled", Level = LogLevel.Information, Message = "Skipping configuring and setting EDOT defaults for {Signal}, as these have been disabled via configuration.")]
[LoggerMessage(EventId = 18, EventName = "SignalDisabled", Level = LogLevel.Information, Message = "Skipping configuring and setting EDOT defaults for {Signal}, as these have been disabled via configuration.")]
public static partial void LogSignalDisabled(this ILogger logger, string signal);

[LoggerMessage(EventId = 14, EventName = "ProviderBuilderSignalDisabled", Level = LogLevel.Information, Message = "Skipping configuring and setting EDOT defaults for {Signal} on {ProviderBuilderType}, " +
[LoggerMessage(EventId = 19, EventName = "ProviderBuilderSignalDisabled", Level = LogLevel.Information, Message = "Skipping configuring and setting EDOT defaults for {Signal} on {ProviderBuilderType}, " +
"as these have been disabled via configuration.")]
public static partial void LogSignalDisabled(this ILogger logger, string signal, string providerBuilderType);

[LoggerMessage(EventId = 15, EventName = "SkippingBootstrap", Level = LogLevel.Warning, Message = "Skipping EDOT bootstrap and provider configuration because the `Signals` configuration is set to `None`. " +
[LoggerMessage(EventId = 20, EventName = "SkippingBootstrap", Level = LogLevel.Warning, Message = "Skipping EDOT bootstrap and provider configuration because the `Signals` configuration is set to `None`. " +
"This likely represents a misconfiguration. If you do not want to use the EDOT for any signals, avoid calling `WithElasticDefaults` on the builder.")]
public static partial void LogSkippingBootstrapWarning(this ILogger logger);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 9, Level = LogLevel.Debug, Message = "{ProcessorName} found `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void FoundTag(this ILogger logger, string processorName, string attributeName, string attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 9, Level = LogLevel.Debug, Message = "{ProcessorName} found `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void FoundTag(this ILogger logger, string processorName, string attributeName, int attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 10, Level = LogLevel.Debug, Message = "{ProcessorName} set `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void SetTag(this ILogger logger, string processorName, string attributeName, string attributeValue);

// We explictly reuse the same event ID and this is the same log message, but with different types for the structured data
[LoggerMessage(EventId = 10, Level = LogLevel.Debug, Message = "{ProcessorName} set `{AttributeName}` attribute with value '{AttributeValue}' on the span.")]
internal static partial void SetTag(this ILogger logger, string processorName, string attributeName, int attributeValue);
[LoggerMessage(EventId = 21, EventName = "LogAddedMeter", Level = LogLevel.Warning, Message = "Added {MeterName} to resource builder '{BuilderIdentifier}'.")]
public static partial void LogAddedMeter(this ILogger logger, string meterName, string builderIdentifier);

[LoggerMessage(EventId = 11, Level = LogLevel.Debug, Message = "Added '{ProcessorTypeName}' processor to '{BuilderTypeName}'.")]
public static partial void LogProcessorAdded(this ILogger logger, string processorTypeName, string builderTypeName);
[LoggerMessage(EventId = 22, EventName = "ResourceBuilderAlreadyConfigured", Level = LogLevel.Debug, Message = "The resource builder '{BuilderIdentifier}' has already been configured with EDOT defaults.")]
public static partial void LogResourceBuilderAlreadyConfigured(this ILogger logger, string builderIdentifier);

[LoggerMessage(EventId = 12, Level = LogLevel.Debug, Message = "Added '{MeterName}' meter to '{BuilderTypeName}'.")]
public static partial void LogMeterAdded(this ILogger logger, string meterName, string builderTypeName);
[LoggerMessage(EventId = 23, EventName = "ResourceBuilderConfigured", Level = LogLevel.Debug, Message = "Configuring the resource builder '{BuilderIdentifier}' with EDOT defaults.")]
public static partial void LogResourceBuilderConfigured(this ILogger logger, string builderIdentifier);

[LoggerMessage(EventId = 13, Level = LogLevel.Error, Message = "Unable to configure {BuilderTypeName} with EDOT .NET logging defaults.")]
public static partial void UnableToConfigureLoggingDefaultsError(this ILogger logger, string builderTypeName);
[LoggerMessage(EventId = 24, EventName = "ConfiguringBuilder", Level = LogLevel.Information, Message = "Configuring the {ProviderBuilderType} with ID '{BuilderIdentifier}' with EDOT defaults.")]
public static partial void LogConfiguringBuilder(this ILogger logger, string providerBuilderType, string builderIdentifier);

public static void LogDistroPreamble(this ILogger logger, SdkActivationMethod activationMethod, ElasticOpenTelemetryComponents components)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
Expand Down Expand Up @@ -33,7 +33,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.6" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.9.0-beta.1" />
<PackageReference Include="OpenTelemetry.Resources.Host" Version="1.11.0-beta.1" />
<PackageReference Include="Polyfill" Version="7.16.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Polyfill" Version="7.20.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta09" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>

Expand All @@ -42,8 +42,9 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net9.0'">
<PackageReference Include="System.Text.Json" Version="9.0.2" />
<!-- We skip this on .NET since we prefer to use the native instrumentation from the builtin Meter -->
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.11.0" />
<!-- We skip this on .NET since we prefer to use the native instrumentation from the builtin ActivitySource -->
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.11.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using OpenTelemetry.Resources;

// Matching namespace with LoggerProviderBuilder
#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace OpenTelemetry.Logs;
#pragma warning restore IDE0130 // Namespace does not match folder structure

/// <summary>
/// Extension methods for <see cref="LoggerProviderBuilder"/> used to register
/// Provides extension methods on the <see cref="LoggerProviderBuilder"/> used to register
/// the Elastic Distribution of OpenTelemetry (EDOT) defaults.
/// </summary>
public static class LoggingProviderBuilderExtensions
Expand Down Expand Up @@ -127,7 +128,7 @@ internal static LoggerProviderBuilder WithElasticDefaultsCore(

static void ConfigureBuilder(LoggerProviderBuilder builder, ElasticOpenTelemetryComponents components)
{
builder.ConfigureResource(r => r.AddElasticDistroAttributes());
builder.ConfigureResource(r => r.WithElasticDefaults(components.Logger));

if (components.Options.SkipOtlpExporter)
{
Expand Down
Loading
Loading