Skip to content

Commit 0542dbb

Browse files
authored
[FileBasedConfiguration] Support for IL rewrite for SqlClient (#4721)
1 parent 343e8b5 commit 0542dbb

29 files changed

+208
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
1414
- Support for [`NLog`](https://www.nuget.org/packages/NLog/)
1515
logs instrumentation for versions `5.*` and `6.*` on .NET using duck typing
1616
for zero-config auto-injection.
17+
- Support for file-based configuration of the IL rewrite for
18+
SqlClient instrumentation setting
1719

1820
### Changed
1921

docs/file-based-configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ file-based configuration to include these parameters.
5151
| `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` | Names of the executable files that the profiler cannot instrument. |
5252
| `OTEL_DOTNET_AUTO_OPENTRACING_ENABLED` | Enables OpenTracing tracer. |
5353
| `OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED` | Enables automatic redirection of the assemblies used by the automatic instrumentation on the .NET Framework. |
54-
| `OTEL_DOTNET_AUTO_SQLCLIENT_NETFX_ILREWRITE_ENABLED` | Enables IL rewriting of `SqlCommand` on .NET Framework to ensure `CommandText` is present for `SqlClient` instrumentation |
5554

5655
---
5756

@@ -543,6 +542,10 @@ instrumentation/development:
543542
# Whether the Oracle Client instrumentation can pass SQL statements through the db.statement attribute. Queries might contain sensitive information. If set to false, db.statement is recorded only for executing stored procedures.
544543
# Default is false
545544
set_db_statement_for_text: false
545+
sqlclient:
546+
# Enables IL rewriting of SqlCommand on .NET Framework to ensure CommandText is available for instrumentation.
547+
# Default is false
548+
netfx_ilrewrite_enabled: false
546549
aspnet:
547550
# A comma-separated list of HTTP header names. ASP.NET instrumentations will capture HTTP request header values for all configured header names.
548551
capture_request_headers: "X-Key,X-Custom-Header,X-Header-Example"

examples/file-based-configuration-files/kitchen-sink.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ instrumentation/development:
595595
rabbitmq: # RabbitMQ.Client
596596
quartz: # Quartz
597597
sqlclient: # Microsoft.Data.SqlClient & System.Data.SqlClient
598+
# Enables IL rewriting of SqlCommand on .NET Framework to ensure CommandText is available for instrumentation.
599+
# If omitted false is used.
600+
netfx_ilrewrite_enabled: false
598601
stackexchangeredis: # StackExchange.Redis
599602
wcfclient: # WCF Client
600603
wcfservice: # WCF Service

examples/file-based-configuration-files/sdk-migration-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ instrumentation/development:
236236
rabbitmq: # RabbitMQ.Client
237237
quartz: # Quartz
238238
sqlclient: # Microsoft.Data.SqlClient & System.Data.SqlClient
239+
# Enables IL rewriting of SqlCommand on .NET Framework to ensure CommandText is available for instrumentation.
240+
# If omitted false is used.
241+
netfx_ilrewrite_enabled: ${OTEL_DOTNET_AUTO_SQLCLIENT_NETFX_ILREWRITE_ENABLED:-false}
239242
stackexchangeredis: # StackExchange.Redis
240243
wcfclient: # WCF Client
241244
wcfservice: # WCF Service

src/OpenTelemetry.AutoInstrumentation.Native/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ endif()
150150
add_library("OpenTelemetry.AutoInstrumentation.Native.static" STATIC
151151
class_factory.cpp
152152
clr_helpers.cpp
153+
configuration.cpp
153154
continuous_profiler_clr_helpers.cpp
154155
continuous_profiler.cpp
155156
cor_profiler_base.cpp

src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ EXPORTS
77
IsProfilerAttached
88
AddInstrumentations
99
AddDerivedInstrumentations
10+
SetSqlClientNetFxILRewriteEnabled
1011
InitializeTraceMethods
1112
ConfigureContinuousProfiler
1213
ContinuousProfilerReadThreadSamples

src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
<ClInclude Include="calltarget_tokens.h" />
175175
<ClInclude Include="class_factory.h" />
176176
<ClInclude Include="com_ptr.h" />
177+
<ClInclude Include="configuration.h" />
177178
<ClInclude Include="continuous_profiler_clr_helpers.h" />
178179
<ClInclude Include="continuous_profiler.h" />
179180
<ClInclude Include="cor_profiler.h" />
@@ -220,6 +221,7 @@
220221
<ClCompile Include="calltarget_tokens.cpp" />
221222
<ClCompile Include="class_factory.cpp" />
222223
<ClCompile Include="clr_helpers.cpp" />
224+
<ClCompile Include="configuration.cpp" />
223225
<ClCompile Include="continuous_profiler_clr_helpers.cpp" />
224226
<ClCompile Include="continuous_profiler.cpp" />
225227
<ClCompile Include="cor_profiler_base.cpp" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "configuration.h"
7+
8+
namespace trace
9+
{
10+
11+
bool sqlclient_netfx_ilrewrite_enabled = false;
12+
13+
bool IsSqlClientNetFxILRewriteEnabled()
14+
{
15+
return sqlclient_netfx_ilrewrite_enabled;
16+
}
17+
18+
void SetSqlClientNetFxILRewriteEnabled(bool enabled)
19+
{
20+
sqlclient_netfx_ilrewrite_enabled = enabled;
21+
}
22+
23+
} // namespace trace
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OTEL_CLR_CONFIGURATION_H_
7+
#define OTEL_CLR_CONFIGURATION_H_
8+
9+
namespace trace
10+
{
11+
12+
bool IsSqlClientNetFxILRewriteEnabled();
13+
void SetSqlClientNetFxILRewriteEnabled(bool enabled);
14+
15+
} // namespace trace
16+
17+
#endif // OTEL_CLR_CONFIGURATION_H_

src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "dllmain.h"
1313
#include "environment_variables.h"
1414
#include "environment_variables_util.h"
15+
#include "configuration.h"
1516
#include "il_rewriter.h"
1617
#include "il_rewriter_wrapper.h"
1718
#include "stub_generator.h"

0 commit comments

Comments
 (0)