Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable log level - native code and loader #2288

Merged
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

### Added

- Support `OTEL_LOG_LEVEL` to configure SDK logging level.
pellared marked this conversation as resolved.
Show resolved Hide resolved

### Changed

### Deprecated
Expand Down
15 changes: 0 additions & 15 deletions OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.CustomSdk",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.Quartz", "test\test-applications\integrations\TestApplication.Quartz\TestApplication.Quartz.csproj", "{B48780CE-8AAB-44D3-9CD1-8491584352B5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{B1E71654-E784-4A39-BE45-8671E027B6D7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.EntityFrameworkCore", "test\test-applications\integrations\TestApplication.EntityFrameworkCore\TestApplication.EntityFrameworkCore.csproj", "{036A56A4-4EEF-42E3-9857-B9B00D302BF9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyListGenerator", "tools\DependencyListGenerator\DependencyListGenerator.csproj", "{D6181786-C7F1-400D-A678-8DC300485429}"
Expand Down Expand Up @@ -752,18 +750,6 @@ Global
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x64.Build.0 = Release|x64
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x86.ActiveCfg = Release|x86
{B48780CE-8AAB-44D3-9CD1-8491584352B5}.Release|x86.Build.0 = Release|x86
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|x64.ActiveCfg = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|x64.Build.0 = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|x86.ActiveCfg = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Debug|x86.Build.0 = Debug|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|Any CPU.Build.0 = Release|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|x64.ActiveCfg = Release|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|x64.Build.0 = Release|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|x86.ActiveCfg = Release|Any CPU
{B1E71654-E784-4A39-BE45-8671E027B6D7}.Release|x86.Build.0 = Release|Any CPU
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|Any CPU.ActiveCfg = Debug|x64
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|Any CPU.Build.0 = Debug|x64
{036A56A4-4EEF-42E3-9857-B9B00D302BF9}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -869,7 +855,6 @@ Global
{A0338846-2AF8-4D96-ADA7-EBD4F010D08F} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{7B363F47-1DB8-44CF-8388-A41F9366C9DE} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{B48780CE-8AAB-44D3-9CD1-8491584352B5} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{B1E71654-E784-4A39-BE45-8671E027B6D7} = {5C915382-C886-457D-8641-9E766D8E5A17}
{036A56A4-4EEF-42E3-9857-B9B00D302BF9} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{D6181786-C7F1-400D-A678-8DC300485429} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{6A63DAA1-463A-4F7E-B3FF-3B444F161DBD} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
Expand Down
11 changes: 0 additions & 11 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>
}
});

Target CompileBenchmarks => _ => _
.Description("Compiles the Benchmarks project in the test directory")
.After(CompileManagedSrc)
.Executes(() =>
{
DotNetBuild(x => x
.SetProjectFile(Solution.GetBenchmarks())
.SetConfiguration(BuildConfiguration)
.EnableNoRestore());
});

Target CompileNativeSrc => _ => _
.Description("Compiles the native loader")
.DependsOn(CompileNativeSrcWindows)
Expand Down
3 changes: 1 addition & 2 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ void DeleteReparsePoints(string path)
.DependsOn(BuildTracer)
.DependsOn(CompileExamples)
.DependsOn(NativeTests)
.DependsOn(ManagedTests)
.DependsOn(CompileBenchmarks);
.DependsOn(ManagedTests);

Target BuildTracer => _ => _
.Description("Builds the native and managed src, and publishes the tracer home directory")
Expand Down
8 changes: 1 addition & 7 deletions build/ProjectsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public static Project GetTestMock(this Solution solution)
return solution.GetProject(Projects.Mocks.AutoInstrumentationMock);
}

public static Project GetBenchmarks(this Solution solution)
{
return solution.GetProject(Projects.Benchmarks.AutoInstrumentationBenchmarks);
}

public static IEnumerable<Project> GetWindowsOnlyTestApplications(this Solution solution)
{
return solution
Expand All @@ -103,8 +98,7 @@ public static IEnumerable<Project> GetCrossPlatformManagedProjects(this Solution
return solution.GetManagedSrcProjects()
.Concat(solution.GetManagedTestProjects())
.Concat(solution.GetCrossPlatformTestApplications())
.Concat(new[] { solution.GetTestMock() })
.Concat(new[] { solution.GetBenchmarks() });
.Concat(new[] { solution.GetTestMock() });
}

public static IEnumerable<Project> GetNativeProjects(this Solution solution)
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ However, if given setting supports it, then:
|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| `OTEL_DOTNET_AUTO_HOME` | Installation location. | |
| `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` | Names of the executable files that the profiler cannot instrument. Supports multiple comma-separated values, for example: `ReservedProcess.exe,powershell.exe`. If unset, the profiler attaches to all processes by default. | |
| `OTEL_LOG_LEVEL` | SDK log level. (supported values: `none`,`error`,`warn`,`info`,`debug`) | `info` |

## Resources

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// <copyright file="AutoInstrumentationEventSource.Name.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,11 +14,12 @@
// limitations under the License.
// </copyright>

using BenchmarkDotNet.Running;
using System.Diagnostics.Tracing;

namespace OpenTelemetry.AutoInstrumentation.Loader.Benchmarks;
// ReSharper disable once CheckNamespace
namespace OpenTelemetry.AutoInstrumentation;

internal class Program
[EventSource(Name = "OpenTelemetry-AutoInstrumentation-Loader")]
internal partial class AutoInstrumentationEventSource
{
private static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
70 changes: 0 additions & 70 deletions src/OpenTelemetry.AutoInstrumentation.Loader/FileSink.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ private static string ResolveManagedProfilerDirectory()
// load the originally referenced version
if (assemblyName.Name != null && assemblyName.Name.StartsWith("OpenTelemetry.AutoInstrumentation", StringComparison.OrdinalIgnoreCase) && File.Exists(path))
{
LoaderLogger.Debug("Loading {0} with Assembly.LoadFrom", path);
Logger.Debug("Loading {0} with Assembly.LoadFrom", path);
return Assembly.LoadFrom(path);
}
else if (File.Exists(path))
{
LoaderLogger.Debug("Loading {0} with DependencyLoadContext.LoadFromAssemblyPath", path);
Logger.Debug("Loading {0} with DependencyLoadContext.LoadFromAssemblyPath", path);
return DependencyLoadContext.LoadFromAssemblyPath(path); // Load unresolved framework and third-party dependencies into a custom Assembly Load Context
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ private static string ResolveManagedProfilerDirectory()
return null;
}

LoaderLogger.Debug("Requester [{0}] requested [{1}]", args?.RequestingAssembly?.FullName ?? "<null>", args?.Name ?? "<null>");
Logger.Debug("Requester [{0}] requested [{1}]", args?.RequestingAssembly?.FullName ?? "<null>", args?.Name ?? "<null>");
var path = Path.Combine(ManagedProfilerDirectory, $"{assemblyName}.dll");
if (File.Exists(path))
{
try
{
var loadedAssembly = Assembly.LoadFrom(path);
LoaderLogger.Debug("Assembly.LoadFrom(\"{0}\") succeeded={1}", path, loadedAssembly != null);
Logger.Debug("Assembly.LoadFrom(\"{0}\") succeeded={1}", path, loadedAssembly != null, false);
pjanotti marked this conversation as resolved.
Show resolved Hide resolved
return loadedAssembly;
}
catch (Exception ex)
{
LoaderLogger.Debug("Assembly.LoadFrom(\"{0}\") Exception: {1}", path, ex);
Logger.Debug("Assembly.LoadFrom(\"{0}\") Exception: {1}", path, ex);
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System.Reflection;
using OpenTelemetry.AutoInstrumentation.Logging;

namespace OpenTelemetry.AutoInstrumentation.Loader;

Expand All @@ -25,6 +26,8 @@ internal partial class Loader
{
private static readonly string ManagedProfilerDirectory;

private static readonly IOtelLogger Logger = OtelLogging.GetLogger("Loader");

/// <summary>
/// Initializes static members of the <see cref="Loader"/> class.
/// This method also attempts to load the OpenTelemetry.AutoInstrumentation .NET assembly.
Expand All @@ -39,15 +42,15 @@ static Loader()
}
catch (Exception ex)
{
LoaderLogger.Log(ex, "Unable to register a callback to the CurrentDomain.AssemblyResolve event.");
Logger.Error(ex, "Unable to register a callback to the CurrentDomain.AssemblyResolve event.");
}

TryLoadManagedAssembly();
}

private static void TryLoadManagedAssembly()
{
LoaderLogger.Log("Managed Loader TryLoadManagedAssembly()");
Logger.Information("Managed Loader TryLoadManagedAssembly()");

try
{
Expand All @@ -73,7 +76,7 @@ private static void TryLoadManagedAssembly()
}
catch (Exception ex)
{
LoaderLogger.Log(ex, $"Error when loading managed assemblies. {ex.Message}");
Logger.Error(ex, "Error when loading managed assemblies. {0}", ex.Message);
throw;
}
}
Expand All @@ -86,7 +89,7 @@ private static void TryLoadManagedAssembly()
}
catch (Exception ex)
{
LoaderLogger.Log(ex, "Error while loading environment variable " + key);
Logger.Error(ex, "Error while loading environment variable {0}", key);
}

return null;
Expand Down
Loading