-
Notifications
You must be signed in to change notification settings - Fork 14
AzureKVP Telemetry Library for Hyper-V Integration #133
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2b1ded8
Squash merge for adding KVP functionality via tracing and repo instru…
peytonr18 60af377
Refactoring KVP PR to move kvp.rs into main libazureinit crate, combi…
peytonr18 f119cc5
Update tracing setup for compatibility with OpenTelemetry 0.27.0
peytonr18 798ab8a
Merging in latest changes from main.
peytonr18 a90f155
Merging in changes from main
peytonr18 44e8737
Merge branch 'main' into probertson-kvp-test
peytonr18 c3dd388
Resolving lifetime declaration of StringVisitor clippy error, along w…
peytonr18 b96c33f
Add unit test to validate slice value length and replace hardcoded va…
peytonr18 352d4cd
Refactor module structure and rename tracing.rs to logging.rs in azur…
peytonr18 c87ac52
Merge main into probertson-kvp-test
peytonr18 f62d7b9
Merge branch 'main' into probertson-kvp-test
peytonr18 71cd9ff
Resolving cargofmt issue
peytonr18 35bd757
Merge branch 'main' into probertson-kvp-test
peytonr18 8b2c829
Auditing tracing::info! calls in an attempt to clean up KVP file for …
peytonr18 e14d8ac
Add filter
peytonr18 0536a3b
Refactor emit_kvp_kayer and otel_layer with improved per-layer filter…
peytonr18 6257a81
Updating note to reflect that both the key and the value are null-byt…
peytonr18 9e6820a
Refactor KVP logging to use module-based targets and update filtering…
peytonr18 88ae27d
Merge remote-tracking branch 'origin/main' into probertson-kvp-test
peytonr18 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Tracing Logic Overview | ||
|
||
## How Tracing is Set Up | ||
|
||
The tracing setup in this project is built around three key layers, each with its own responsibility: | ||
|
||
1. **EmitKVPLayer**: Custom Layer for Span Processing | ||
2. **OpenTelemetryLayer**: Context Propagation and Span Export | ||
3. **stderr_layer**: Formatting and Logging to stderr | ||
|
||
These layers work together, yet independently, to process span data as it flows through the program. | ||
|
||
## Layer Overview | ||
|
||
### 1. EmitKVPLayer | ||
|
||
- **Purpose**: This custom layer is responsible for processing spans and events by capturing their metadata, generating key-value pairs (KVPs), encoding them into a specific format, and writing the encoded data to the VM's Hyper-V file for consumption by the `hv_kvp_daemon` service. | ||
|
||
- **How It Works**: | ||
- **Span Processing**: When a span is created, `EmitKVPLayer` processes the span's metadata, generating a unique key for the span and encoding the span data into a binary format that can be consumed by Hyper-V. | ||
- **Event Processing**: When an event is emitted using the `event!` macro, the `on_event` method in `EmitKVPLayer` processes the event, capturing its message and linking it to the current span. Events are useful for tracking specific points in time within a span, such as errors, warnings, retries, or important state changes. Events are recorded independently of spans but they are be tied to the span they occur within by using the same span metadata. | ||
- Both span and event data are written to the `/var/lib/hyperv/.kvp_pool_1` file, which is typically monitored by the Hyper-V `hv_kvp_daemon` service. | ||
- The `hv_kvp_daemon` uses this file to exchange key-value pair (KVP) data between the virtual machine and the Hyper-V host. This mechanism is crucial for telemetry and data synchronization. | ||
|
||
- **Reference**: For more details on how the Hyper-V Data Exchange Service works, refer to the official documentation here: [Hyper-V Data Exchange Service (KVP)](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/integration-services#hyper-v-data-exchange-service-kvp). | ||
|
||
### 2. OpenTelemetryLayer | ||
|
||
- **Purpose**: This layer integrates with the OpenTelemetry framework to handle context propagation and export span data to an external tracing backend (e.g., Jaeger, Prometheus) or to stdout. | ||
- **How It Works**: | ||
- As spans are created and processed, the `OpenTelemetryLayer` ensures that context is propagated correctly across different parts of the program, which is crucial in distributed systems for tracing requests across service boundaries. | ||
- The span data is then exported to a configured backend or stdout, where it can be visualized and analyzed using OpenTelemetry-compatible tools. | ||
|
||
### 3. stderr_layer | ||
|
||
- **Purpose**: This layer formats and logs span and event data to stderr or a specified log file, providing a human-readable output for immediate inspection. | ||
- **How It Works**: | ||
- Each span's lifecycle events, as well as individual emitted events, are logged in a structured format, making it easy to see the flow of execution in the console or log files. | ||
- This layer is particularly useful for debugging and monitoring during development. | ||
|
||
## How the Layers Work Together | ||
|
||
- **Independent Processing**: Each of these layers processes spans and events independently. When a span is created, it triggers the `on_new_span` method in each layer, and when an event is emitted, it triggers the `on_event` method. As the span progresses through its lifecycle (`on_enter`, `on_close`), each layer performs its respective tasks. | ||
- **Order of Execution**: The layers are executed in the order they are added in the `initialize_tracing` function. For instance, `EmitKVPLayer` might process a span before `OpenTelemetryLayer`, but this order only affects the sequence of operations, not the functionality or output of each layer. | ||
- **No Cross-Layer Dependencies**: Each layer operates independently of the others. For example, the `EmitKVPLayer` encodes and logs span and event data without affecting how `OpenTelemetryLayer` exports span data to a backend. This modular design allows each layer to be modified, replaced, or removed without impacting the others. | ||
|
||
In the `main.rs` file, the tracing logic is initialized. Spans are instrumented using the `#[instrument]` attribute and events can be created with the `event!` macro to monitor the execution of the function. Here's an example: | ||
|
||
```rust | ||
#[instrument(name = "root")] | ||
async fn provision() -> Result<(), anyhow::Error> { | ||
event!(Level::INFO, msg = "Starting the provision process..."); | ||
// Other logic... | ||
} | ||
``` | ||
|
||
1. **Initialization**: | ||
The `initialize_tracing` function is called at the start of the program to set up the tracing subscriber with the configured layers (`EmitKVPLayer`, `OpenTelemetryLayer`, and `stderr_layer`). | ||
|
||
2. **Instrumenting the `provision()` Function**: | ||
The `#[instrument]` attribute is used to automatically create a span for the `provision()` function. | ||
- The `name = "root"` part of the `#[instrument]` attribute specifies the name of the span. | ||
- This span will trace the entire execution of the `provision()` function, capturing any relevant metadata (e.g., function parameters, return values). | ||
|
||
3. **Span Processing**: | ||
As the `provision()` function is called and spans are created, entered, exited, and closed, they are processed by the layers configured in `initialize_tracing`: | ||
- **EmitKVPLayer** processes the span, generates key-value pairs, encodes them, and writes them directly to `/var/lib/hyperv/.kvp_pool_1`. | ||
- **OpenTelemetryLayer** handles context propagation and exports span data to a tracing backend or stdout. | ||
- **stderr_layer** logs span information to stderr or another specified output for immediate visibility. |
Oops, something went wrong.
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.
It is not clear on reading the log how to disable writing to kvp? This is a strong requirement per Azure Privacy Review (that we need to document what is collected, and provide the customer with a mean to disable it)
This document probably focuses on the technical aspect of tracing/kvp. I would add another section on the main page about telemetry and describe what we're collecting
See this section
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init#telemetry
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.
#152
Will address this great PR comment in this issue!