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

Env var instrumentation improvements #2088

Merged
merged 37 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b4e09b2
rename local variables
Kielek Jan 25, 2023
56afa56
remove IDE warnings in test
Kielek Jan 25, 2023
3d0c957
new way to parse enabled signals
Kielek Jan 25, 2023
cbcccf6
new way to configure traces instrumentation - managed code
Kielek Jan 25, 2023
b79a3d5
metrics configuration - managed code
Kielek Jan 25, 2023
49aca04
logs configuration - managed code
Kielek Jan 25, 2023
ff7dcb6
fix module tests
Kielek Jan 25, 2023
5d0dd3f
avoid reallocation for enabled values
Kielek Jan 25, 2023
7bb1734
remove unused cpde
Kielek Jan 25, 2023
f1bbaae
documentation scaffolding
Kielek Jan 26, 2023
393e425
Update tests to use new variables
Kielek Jan 26, 2023
e0fbf95
include missing file into vcxproj
Kielek Jan 26, 2023
fccf337
integration generator - cleanup code
Kielek Jan 27, 2023
2cd6ea6
generate available bytecode integration names
Kielek Jan 27, 2023
1f5d4ff
new way to load enabled integrations - native code
Kielek Jan 27, 2023
edde152
fix smoke test
Kielek Jan 27, 2023
860e833
update documentation
Kielek Jan 27, 2023
d8f28af
typo fix
Kielek Jan 27, 2023
228d52f
remove temp code
Kielek Jan 27, 2023
fdb3d2d
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Jan 27, 2023
e081254
fix line ending + guard in header
Kielek Jan 27, 2023
2300c6a
update changelog
Kielek Jan 27, 2023
767f016
md lint
Kielek Jan 27, 2023
df37e28
add missing endif
Kielek Jan 27, 2023
51eb3b6
ENABLED -> DISABLED
Kielek Jan 27, 2023
abbf76b
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Jan 27, 2023
9c54b1e
typo fix
Kielek Jan 27, 2023
301092e
generator generates lineending specific for system
Kielek Jan 27, 2023
d439810
Adjust documentation
Kielek Jan 27, 2023
82b3078
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Jan 27, 2023
1fe1d84
Merge branch 'main' into env-var-instrumentation-imrpovements
pellared Jan 27, 2023
3a40e84
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Jan 30, 2023
d435ef3
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Feb 1, 2023
9139c0d
Merge branch 'main' into env-var-instrumentation-imrpovements
Kielek Feb 1, 2023
0dc6986
ENABLED -> DISABLED
Kielek Feb 1, 2023
aea539c
PR feedback- make comment consistent
Kielek Feb 1, 2023
f3e12be
fix default value
Kielek Feb 1, 2023
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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope
to `linux-musl-x64` for Linux musl and
`OpenTelemetry.AutoInstrumentation.Native.dylib`
to `osx-x64` for MacOS.
- Change the way to manage enabled instrumentations. The following environmental
variables:
- `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`,
- `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`z,
Kielek marked this conversation as resolved.
Show resolved Hide resolved
- `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`,
- `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS`,
- `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS`,
- `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS`

are replaced by:

- `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`.

### Deprecated

Expand Down
19 changes: 10 additions & 9 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ for more details.

## Instrumentations

Kielek marked this conversation as resolved.
Show resolved Hide resolved
| Environment variable | Description | Default value |
|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | |
| `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS` | Comma-separated list of traces source instrumentations you want to enable. Set to `none` to disable all trace instrumentations. | all available instrumentations |
| `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS` | Comma-separated list of traces source and bytecode instrumentations you want to disable. | |
| `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations |
| `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to disable. | |
| `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations |
| `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to disable. | |
| Environment variable | Description | Default value |
|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | |
| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` |
| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` |
| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` |
pellared marked this conversation as resolved.
Show resolved Hide resolved
| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Enables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` |
| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` |
| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Enables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` |
| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` |

### Traces instrumentations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="bytecode_instrumentations.h" />
<ClInclude Include="calltarget_tokens.h" />
<ClInclude Include="class_factory.h" />
<ClInclude Include="com_ptr.h" />
Expand All @@ -199,6 +200,7 @@
<ClInclude Include="miniutf.hpp" />
<ClInclude Include="miniutfdata.h" />
<ClInclude Include="module_metadata.h" />
<ClInclude Include="netfx_assembly_redirection.h" />
<ClInclude Include="otel_profiler_constants.h" />
<ClInclude Include="pal.h" />
<ClInclude Include="rejit_handler.h" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Auto-generated file, do not change it - generated by the IntegrationsJsonGenerator
#ifndef BYTECODE_INSTRUMENTATIONS_H
#define BYTECODE_INSTRUMENTATIONS_H

#include "string.h"

namespace trace
{
inline std::unordered_map<WSTRING, WSTRING> trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}};
inline std::unordered_map<WSTRING, WSTRING> metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}};
inline std::unordered_map<WSTRING, WSTRING> log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}};
Kielek marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
12 changes: 5 additions & 7 deletions src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <corprof.h>
#include <string>

#include "bytecode_instrumentations.h"
#include "clr_helpers.h"
#include "dllmain.h"
#include "environment_variables.h"
Expand Down Expand Up @@ -163,19 +164,16 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un

rejit_handler = new RejitHandler(this->info_, callback);


const bool instrumentation_enabled_by_default = AreInstrumentationsEnabledByDefault();

// load all integrations from JSON files
const LoadIntegrationConfiguration configuration(
AreTracesEnabled(),
GetEnvironmentValues(environment::enabled_traces_integrations),
GetEnvironmentValues(environment::disabled_traces_integrations),
GetEnabledEnvironmentValues(AreTracesInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), trace_integration_names),
AreMetricsEnabled(),
GetEnvironmentValues(environment::enabled_metrics_integrations),
GetEnvironmentValues(environment::disabled_metrics_integrations),
GetEnabledEnvironmentValues(AreMetricsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), metric_integration_names),
AreLogsEnabled(),
GetEnvironmentValues(environment::enabled_logs_integrations),
GetEnvironmentValues(environment::disabled_logs_integrations));
GetEnabledEnvironmentValues(AreLogsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), log_integration_names));
LoadIntegrationsFromEnvironment(integration_methods_, configuration);

Logger::Debug("Number of Integrations loaded: ", integration_methods_.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,33 @@ const WSTRING profiler_home_path = WStr("OTEL_DOTNET_AUTO_HOME");
// "MyApp.exe,dotnet.exe"
const WSTRING exclude_process_names = WStr("OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES");

// Whether instrumentations are enabled. If not set (default), all instrumentations are enabled.
const WSTRING instrumentation_enabled =
WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED");

// Whether traces are enabled or not. If not set (default), traces are enabled.
const WSTRING traces_enabled =
WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED");

// Sets a list of integrations to enable. If not set (default), all integrations are enabled.
// Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING enabled_traces_integrations =
WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS");

// Sets a list of integrations to disable. Status of other integrations will remain
// unchanged. Calculation order: OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS
// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS is checked.
// Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING disabled_traces_integrations =
WStr("OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS");
// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used.
const WSTRING traces_instrumentation_enabled =
WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED");

// Whether metrics are enabled or not. If not set (default), traces are enabled.
const WSTRING metrics_enabled =
WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED");

// Sets a list of integrations to enable. If not set (default), all integrations are enabled.
// Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING enabled_metrics_integrations =
WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS");

// Sets a list of integrations to disable. Status of other integrations will remain
// unchanged. Calculation order: OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS
// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS is checked.
// Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING disabled_metrics_integrations =
WStr("OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS");
// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used.
const WSTRING metrics_instrumentation_enabled =
WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED");

// Whether logs are enabled or not. If not set (default), logs are enabled.
const WSTRING logs_enabled =
WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED");

// Sets a list of integrations to enable. If not set (default), all integrations
// are enabled. Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING enabled_logs_integrations =
WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS");

// Sets a list of integrations to disable. Status of other integrations will
// remain unchanged. Calculation order:
// OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS then if instrumentation is
// not explicitly disabled OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS is
// checked. Supports multiple values separated with comma, for example:
// "ElasticsearchNet,AspNetWebApi2"
const WSTRING disabled_logs_integrations =
WStr("OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS");
// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used.
const WSTRING logs_instrumentation_enabled =
WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED");

// Sets the directory for the profiler's log file.
// If not set, default is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ bool IsNetFxAssemblyRedirectionEnabled() {
ToBooleanWithDefault(GetEnvironmentValue(environment::netfx_assembly_redirection_enabled), true);
}

bool AreInstrumentationsEnabledByDefault() {
ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), true);
}

bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) {
ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_enabled), enabled_if_not_configured);
}

bool AreMetricsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) {
ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_enabled), enabled_if_not_configured);
}

bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) {
ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_enabled), enabled_if_not_configured);
}

} // namespace trace

#endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,8 @@ namespace
{
bool InstrumentationEnabled(
const WSTRING name,
const std::vector<WSTRING>& enabledIntegrationNames,
const std::vector<WSTRING>& disabledIntegrationNames)
const std::vector<WSTRING>& enabledIntegrationNames)
{
// check if the integration is disabled
for (const WSTRING& disabledName : disabledIntegrationNames)
{
if (name == disabledName)
{
return false;
}
}

if (enabledIntegrationNames.empty())
{
return true;
}

// check if the integration is enabled
for (const WSTRING& enabledName : enabledIntegrationNames)
{
Expand Down Expand Up @@ -178,7 +163,7 @@ namespace
return;
}

if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames, configuration.disabledTraceIntegrationNames))
if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames))
{
return;
}
Expand All @@ -189,7 +174,7 @@ namespace
{
return;
}
if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames, configuration.disabledMetricIntegrationNames))
if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames))
{
return;
}
Expand All @@ -200,7 +185,7 @@ namespace
{
return;
}
if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames, configuration.disabledLogIntegrationNames))
if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames))
{
return;
}
Expand Down
Loading