Skip to content

Commit 7253f95

Browse files
pdelewskiMrAlias
andauthored
Add instrgen how-it-works.md (#3659)
* Add instrgen how-it-works.md * update image * fixing point 3 * fixing entry point name * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> * Update instrgen/docs/how-it-works.md Co-authored-by: Tyler Yahn <[email protected]> --------- Co-authored-by: Przemek Delewski <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 78d106e commit 7253f95

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

instrgen/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# OpenTelemetry Go Source Automatic Instrumentation
22

33
This package provides a code generation utility that instruments existing source code with [OpenTelemetry].
4+
If you are looking for more details about internal working, see [How it works](./docs/how-it-works.md).
45

56
## Project Status
67

instrgen/docs/flow.png

79.9 KB
Loading

instrgen/docs/how-it-works.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## OpenTelemetry Go Source Automatic Instrumentation - How it works
2+
3+
`instrgen` adds OpenTelemetry instrumentation to source code by directly modifying it.
4+
It uses the AST (Abstract Syntax Tree) representation of the code to determine its operational flow and injects necessary OpenTelemetry functionality into the AST.
5+
6+
The AST modification algorithm is the following:
7+
1. Search for the entry point: a function definition with `AutotelEntryPoint()`.
8+
2. Build the call graph. Traverse all calls from the entry point through all function definitions.
9+
3. Inject OpenTelemetry instrumentation into functions bodies.
10+
4. Context propagation. Adding an additional context parameter to all function declarations and function call expressions that are visible
11+
(it will not add a context argument to call expressions if they are not reachable from the entry point).
12+
![image info](./flow.png)

0 commit comments

Comments
 (0)