-
Notifications
You must be signed in to change notification settings - Fork 95
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
Log error if missing bytecode instrumentation method #1520
Merged
pellared
merged 8 commits into
open-telemetry:main
from
pjanotti:log-error-if-missing-instrumentation-method
Nov 2, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e9aa0c5
Log error msg if instrumentation method is missing
pjanotti ec1801a
Merge branch 'main' of github.com:open-telemetry/opentelemetry-dotnet…
pjanotti 5e73b77
Update CHANGELOG
pjanotti 73f67ae
Change loop to modern c++ style
pjanotti d648aad
Prevent changing json file used in tests
pjanotti 2ecd85e
Merge branch 'main' into log-error-if-missing-instrumentation-method
pjanotti bd46c7b
Merge branch 'main' into log-error-if-missing-instrumentation-method
pjanotti 730a781
Merge branch 'main' into log-error-if-missing-instrumentation-method
pjanotti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2494,14 +2494,47 @@ HRESULT CorProfiler::CallTarget_RewriterCallback(RejitHandlerModule* moduleHandl | |
&wrapper_type_def); | ||
if (FAILED(hr) || wrapper_type_def == mdTypeDefNil) | ||
{ | ||
Logger::Warn("*** CallTarget_RewriterCallback() Failed for: ", caller->type.name, ".", caller->name, | ||
Logger::Error("*** CallTarget_RewriterCallback() Failed for: ", caller->type.name, ".", caller->name, | ||
"() integration type not found on the managed profiler module HRESULT=", HResultStr(hr), | ||
" IntegrationType=", wrapper.type_name); | ||
return S_FALSE; | ||
} | ||
|
||
// TODO: Use the method signature to validate also the method, tracking via | ||
// https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issue/1499 | ||
// CallTarget instrumentation doesn't inject calls to the instrumentation methods via IL rewrite. | ||
// It injects the OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker, written in managed code, | ||
// that uses reflection to find the expected instrumentation methods on the instrumentation wrapper type. | ||
// If the wrapper type doesn't have any of the expected instrumentation methods "nothing happens", but, | ||
// the JIT code of the targeted method is modified anyway. To avoid injecting instrumentation that does | ||
// nothing and give a clear error message the code below ensures that at least one of the expected methods is | ||
// implemented on the wrapper type. | ||
static const LPCWSTR expected_wrapper_methods[] = { WStr("OnMethodBegin"), WStr("OnMethodEnd"), WStr("OnAsyncMethodEnd") }; | ||
bool found_wrapper_method = false; | ||
for (LPCWSTR expected_wrapper_method : expected_wrapper_methods) | ||
{ | ||
mdMethodDef wrapper_method_def[1]; | ||
HCORENUM phEnum = NULL; | ||
ULONG cTokens, | ||
hr = instrumentation_module_metadata->metadata_import->EnumMethodsWithName( | ||
&phEnum, | ||
wrapper_type_def, | ||
expected_wrapper_method, | ||
wrapper_method_def, | ||
1, | ||
&cTokens); | ||
if (hr == S_OK && cTokens > 0) | ||
{ | ||
found_wrapper_method = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found_wrapper_method) | ||
{ | ||
Logger::Error("*** CallTarget_RewriterCallback() Failed for: ", caller->type.name, ".", caller->name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some comment as above. |
||
"() integration type found but none of the wrapper methods expected by CallTargetInvoker was found ", | ||
"IntegrationType=", wrapper.type_name); | ||
return S_FALSE; | ||
} | ||
} | ||
|
||
ModuleID module_id = moduleHandler->GetModuleId(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it not be a warning? It is an oddity, but the application and instrumentation would continue to work without any bad side-effects. Should the user react when he notices such an error?
Maybe we should even "accept" such behavior so that we could use e.g.
#if NETFRAMEWORK
on a whole instrumentation class? Then we could even change this level to debug.Leaving it for a discussion + potentially separate PR.