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

Workaround dotnet CLI issue #2131

Closed
Closed
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
55 changes: 28 additions & 27 deletions .cspell/dot-net.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
CORECLR
netcoreapp
NGEN
aspnet
ASPNETCORE
ASSERTE
Bootstrapper
callq
CLSID
MSVC
CONTRACTL
CORECLR
corelib
corerun
lldb
SIGUSR
callq
movq
movl
corprof
cref
dlerror
popq
libcoreclr
dlopen
eetoprofinterfaceimpl
HOSTINGSTARTUPASSEMBLIES
idls
iisreset
ILREWRITE
libcoreclr
lldb
LPCSTR
ASSERTE
CONTRACTL
midl
movl
movq
MSVC
netcoreapp
NETFX
NGEN
nullptr
dlopen
ILREWRITE
aspnet
popq
pwsh
SIGUSR
stdlibc
struct
typeof
cref
corprof
idls
midl
stdlibc
corelib
ASPNETCORE
HOSTINGSTARTUPASSEMBLIES
Bootstrapper
NETFX
iisreset
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope
- `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`.
- Set the default of `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` to
`dotnet,dotnet.exe,powershell.exe,pwsh,pwsh.exe`.
- Unset, in the StartupHook, the `DOTNET_ADDITIONAL_DEPS`, `DOTNET_SHARED_STORE`,
and `DOTNET_STARTUP_HOOKS` environment variables, for processes in `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES`.

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ However, if given setting supports it, then:

## Global settings

| Environment variable | Description | Default value |
|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| `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. | |
| Environment variable | Description | Default value |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------|
| `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`. | dotnet,dotnet.exe,powershell.exe,pwsh,pwsh.exe |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotnet,dotnet.exe,powershell.exe,pwsh,pwsh.exe seems like an excellent base, we should make a next step issue, where we can work out more complete list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should ignore dotnet. See #2131 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that sentiment @pellared: ideally, we would instrument dotnet <dll>, but, not the other usages of dotnet.


## Resources

Expand Down
20 changes: 19 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageVersion Include="System.Windows.Extensions" Version="4.7.0" />
</ItemGroup>

<ItemGroup Label="Transient dependencies auto-generated by GenerateNetFxTransientDependencies">
<ItemGroup Label="Transient dependencies auto-generated by GenerateNetFxTransientDependencies" Condition=" '$(TargetFramework)' == 'net462' ">
<PackageVersion Include="Google.Protobuf" Version="3.19.4" />
<PackageVersion Include="Grpc" Version="2.44.0" />
<PackageVersion Include="Grpc.Core" Version="2.44.0" />
Expand Down Expand Up @@ -68,4 +68,22 @@
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Label="Transient dependencies auto-generated by GenerateNetFxTransientDependencies" Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageVersion Include="DnsClient" Version="1.4.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="6.0.0" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Primitives" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="6.0.0" />
<PackageVersion Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.3.0" />
</ItemGroup>
</Project>
12 changes: 11 additions & 1 deletion src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
#endif

const auto process_name = GetCurrentProcessName();
const auto exclude_process_names = GetEnvironmentValues(environment::exclude_process_names);
auto exclude_process_names = GetEnvironmentValues(environment::exclude_process_names);
if (exclude_process_names.empty())
{
exclude_process_names = std::vector<WSTRING>
{
WStr("powershell.exe"), WStr("pwsh"), WStr("pwsh.exe")
};
}

// attach profiler only if this process's name is NOT on the list
if (!exclude_process_names.empty() && Contains(exclude_process_names, process_name))
Expand All @@ -114,6 +121,9 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
return E_FAIL;
}

Logger::Info("Profiler NOT disabled: ", process_name, " NOT found in ",
environment::exclude_process_names, ".");

if (runtime_information_.is_core())
{
// .NET Core applications should use the dotnet startup hook to bootstrap OpenTelemetry so that the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public static void Initialize()
if (IsApplicationInExcludeList(applicationName))
{
Logger.LogInformation("Application is in the exclusion list. Skipping initialization.");

// TODO: Non-destructive clean-up: remove only OTel .NET AutoInstrumentaion related paths.
Environment.SetEnvironmentVariable("DOTNET_ADDITIONAL_DEPS", null);
Environment.SetEnvironmentVariable("DOTNET_SHARED_STORE", null);
Environment.SetEnvironmentVariable("DOTNET_STARTUP_HOOKS", null);

return;
}

Expand Down Expand Up @@ -138,7 +144,10 @@ private static List<string> GetExcludedApplicationNames()

if (environmentValue == null)
{
return excludedProcesses;
return new List<string>
{
"powershell.exe", "pwsh", "pwsh.exe"
};
}

foreach (var processName in environmentValue.Split(Constants.ConfigurationValues.Separator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
// limitations under the License.
// </copyright>

using System.Diagnostics;
using System.Diagnostics.Metrics;
using OpenTelemetry.AutoInstrumentation.Instrumentations.GraphQL;
using OpenTelemetry.Logs;

namespace OpenTelemetry.AutoInstrumentation.Configurations;

/// <summary>
Expand Down Expand Up @@ -97,7 +92,7 @@ public static class Traces
public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED";

/// <summary>
/// Configuration key for additional <see cref="ActivitySource"/> names to be added to the tracer at the startup.
/// Configuration key for additional ActivitySource names to be added to the tracer at the startup.
/// </summary>
public const string AdditionalSources = "OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES";

Expand All @@ -123,7 +118,6 @@ public static class InstrumentationOptions
{
/// <summary>
/// Configuration key for GraphQL instrumentation to enable passing query as a document attribute.
/// See <see cref="GraphQLTags.Document"/>.
/// </summary>
public const string GraphQLSetDocument = "OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT";
}
Expand Down Expand Up @@ -161,7 +155,7 @@ public static class Metrics
public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED";

/// <summary>
/// Configuration key for additional <see cref="Meter"/> names to be added to the meter at the startup.
/// Configuration key for additional "Meter" names to be added to the meter at the startup.
/// </summary>
public const string AdditionalSources = "OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES";
}
Expand Down Expand Up @@ -189,7 +183,7 @@ public static class Logs

/// <summary>
/// Configuration key for whether or not formatted log message
/// should be included on generated <see cref="LogRecord"/>s.
/// should be included on generated.
/// </summary>
public const string IncludeFormattedMessage = "OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void AddAspNet(LazyInstrumentationLoader lazyInstrumentationLoader
{
#if NET462
new AspNetMetricsInitializer(lazyInstrumentationLoader);
#elif NET6_0_OR_GREATER
#elif NET6_0_OR_GREATER && _INCLUDE_ASP_NET_CORE_
lazyInstrumentationLoader.Add(new AspNetCoreMetricsInitializer());
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public override void Initialize(ILifespanManager lifespanManager)
var instrumentationType = Type.GetType("OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentation, OpenTelemetry.Instrumentation.AspNetCore")!;
var httpInListenerType = Type.GetType("OpenTelemetry.Instrumentation.AspNetCore.Implementation.HttpInListener, OpenTelemetry.Instrumentation.AspNetCore")!;

var options = new OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions();
_pluginManager.ConfigureTracesOptions(options);
// var options = new OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions();
// _pluginManager.ConfigureTracesOptions(options);

var httpInListener = Activator.CreateInstance(httpInListenerType, args: options);
var httpInListener = Activator.CreateInstance(httpInListenerType);
var instrumentation = Activator.CreateInstance(instrumentationType, args: httpInListener)!;

lifespanManager.Track(instrumentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
// </copyright>

#if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER && _INCLUDE_ASP_NET_CORE_

using System.Reflection;
using OpenTelemetry.Instrumentation.AspNetCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.MySqlData" />
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" />
Expand Down Expand Up @@ -69,4 +68,21 @@
<PackageReference Include="System.ValueTuple" />
</ItemGroup>

<ItemGroup Label="Transient dependencies auto-generated by GenerateNetFxTransientDependencies" Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="DnsClient" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Primitives" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
</ItemGroup>

</Project>
Loading