-
Notifications
You must be signed in to change notification settings - Fork 13
Implements OpenTelemetry Instrumentation for Observability #395
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
Open
shikokuchuo
wants to merge
28
commits into
main
Choose a base branch
from
feat-otel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+424
−15
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0047854
otel concept
shikokuchuo f2f444b
Include daemon on which mirai is evaluated as an attribute
shikokuchuo b7456f7
Enable across all daemons types
shikokuchuo 0579830
Add mirai_map() spans
shikokuchuo f58b171
Add daemon() span
shikokuchuo e35a1df
Explicitly end daemon spans
shikokuchuo d5f03a1
Apply suggestion from @schloerke
shikokuchuo de8389b
Correct otel span nesting code
shikokuchuo de53879
Rebase
shikokuchuo b3b5036
Simplify inheritance for mirai::mirai_map
shikokuchuo e9c5199
Simplify inheritance for mirai::daemon and mirai::daemon->eval
shikokuchuo c4ce8f6
Also nest mirai::mirai_map under active spans
shikokuchuo 70e017c
Better attribute labels
shikokuchuo 503a161
Set status for mirai::daemons span
shikokuchuo 7518546
Add mirai id and enable spans only when daemons are used
shikokuchuo 9b24a59
Add news item
shikokuchuo 68277ca
Set status for mirai::daemon->eval result
shikokuchuo 58ee98a
Upgrade to use links
shikokuchuo efa5c1e
Add events to mirai::daemon span
shikokuchuo fa7ac08
Eval start
shikokuchuo 02b4523
Add span kinds
shikokuchuo e08688e
Simplify and avoid long parent spans
shikokuchuo e5f3219
Update for new otel interfaces
shikokuchuo 5a10821
Add otel tests
shikokuchuo 98cac72
Migrate from dynGet for all otel spans
shikokuchuo d13a068
Complete otel tests
shikokuchuo e5ecc92
✨Add OpenTelemetry vignette✨ (#423)
shikokuchuo 7239898
Update package docs and reorg vignettes
shikokuchuo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ Imports: | |
nanonext (>= 1.7.0) | ||
Suggests: | ||
cli, | ||
litedown | ||
litedown, | ||
otel | ||
Enhances: | ||
parallel, | ||
promises | ||
|
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
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
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,139 @@ | ||
--- | ||
title: "OpenTelemetry" | ||
vignette: > | ||
%\VignetteIndexEntry{OpenTelemetry} | ||
%\VignetteEngine{litedown::vignette} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r} | ||
#| include: false | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
out.width = "100%" | ||
) | ||
``` | ||
|
||
### 1. Introduction | ||
|
||
mirai provides comprehensive OpenTelemetry (otel) tracing support for observing asynchronous operations and distributed computation. | ||
|
||
When the `otel` and `otelsdk` packages are installed and tracing is enabled, mirai automatically creates spans to track the lifecycle of daemon management, async operations, and task execution. | ||
|
||
This enables detailed monitoring of: | ||
|
||
- Task submission and completion times | ||
- Daemon lifecycle and performance | ||
- Error tracking and debugging | ||
- Distributed tracing across network boundaries | ||
|
||
### 2. Automatic Tracing Setup | ||
|
||
Tracing is automatically enabled when: | ||
|
||
1. The `otel` and `otelsdk` packages are installed and available | ||
2. OpenTelemetry tracing is configured and enabled (see <https://otelsdk.r-lib.org/reference/collecting.html>) | ||
|
||
No additional configuration is required - mirai will automatically detect the presence of OpenTelemetry and begin creating spans. | ||
|
||
### 3. Span Types and Hierarchy | ||
|
||
mirai creates several types of spans to represent different operations: | ||
|
||
#### 3.1 Core Span Types | ||
|
||
**`mirai::daemons`** - Root span for daemon management | ||
|
||
- **Kind**: `internal` | ||
- **Attributes**: `url`, `n` (number of daemons), `dispatcher` (true/false), `compute_profile` | ||
- **Lifecycle**: Created when `daemons()` is called, ended when daemons are reset | ||
|
||
**`mirai::daemon`** - Individual daemon process span | ||
|
||
- **Kind**: `internal` | ||
- **Lifecycle**: Tracks the lifetime of a single daemon process | ||
|
||
**`mirai::mirai_map`** - Parallel map operation span | ||
|
||
- **Kind**: `internal` | ||
- **Lifecycle**: Encompasses the entire map operation across multiple mirai tasks | ||
|
||
**`mirai::mirai`** - Client-side async task span | ||
|
||
- **Kind**: `client` | ||
- **Attributes**: `mirai.id` (unique task identifier) | ||
- **Lifecycle**: Created when `mirai()` is called, ended as soon as it returns | ||
|
||
**`mirai::daemon->eval`** - Server-side task evaluation span | ||
|
||
- **Kind**: `server` | ||
- **Lifecycle**: Tracks for the duration of actual mirai evaluation on the daemon | ||
|
||
#### 3.2 Span Relationships and Context Propagation | ||
|
||
The spans form a distributed structure that traces the complete lifecycle of async operations: | ||
|
||
``` | ||
mirai::daemons (compute profile - top level) | ||
|
||
mirai::daemon (daemon process 1 - top level) | ||
mirai::daemon (daemon process 2 - top level) | ||
mirai::daemon (daemon process N - top level) | ||
|
||
mirai::mirai_map (top level) | ||
├── mirai::mirai (task 1) ──link→ mirai::daemons | ||
├── mirai::mirai (task 2) ──link→ mirai::daemons | ||
└── mirai::mirai (task N) ──link→ mirai::daemons | ||
└── mirai::daemon->eval ──link→ mirai::daemon | ||
|
||
mirai::mirai (top level) ──link→ mirai::daemons | ||
└── mirai::daemon->eval ──link→ mirai::daemon | ||
``` | ||
|
||
**Context Propagation**: The context is automatically packaged with each `mirai()` call and extracted on the daemon side, enabling proper parent-child relationships across process boundaries. | ||
|
||
**Span Links**: Tasks are linked to their compute profile's `mirai::daemons` span on the client side, and to each `mirai::daemon` span on the server side, showing exactly where each evaluation happened. | ||
|
||
### 4. Status and Error Tracking | ||
|
||
`mirai::daemon->eval` spans automatically track the success or failure of operations: | ||
|
||
**Status Values**: | ||
|
||
- `'ok'` - Operation completed successfully | ||
- `'error'` - Operation failed with an error | ||
- `'unset'` - Operation was interrupted | ||
|
||
### 5. Monitoring and Observability | ||
|
||
The OpenTelemetry spans provide rich observability into mirai operations: | ||
|
||
**Performance Monitoring**: | ||
|
||
- Track task execution times from submission to completion | ||
- Monitor daemon utilization and load balancing | ||
- Identify bottlenecks in distributed computation | ||
|
||
**Error Analysis**: | ||
|
||
- Correlate errors with specific tasks and daemons | ||
- Track error rates across different types of operations | ||
- Debug issues in distributed environments | ||
|
||
**Distributed Tracing**: | ||
|
||
- Follow task execution across network boundaries | ||
- Understand the complete lifecycle of async operations | ||
- Correlate client-side requests with server-side execution | ||
|
||
### 6. Integration with Observability Platforms | ||
|
||
mirai's OpenTelemetry implementation works seamlessly with any OpenTelemetry-compatible observability platform, including: | ||
|
||
- Grafana | ||
- Pydantic Logfire | ||
- Jaeger | ||
- Any of those listed at <https://otelsdk.r-lib.org/reference/collecting.html>. | ||
|
||
The tracer name used by mirai is `"org.r-lib.mirai"`, making it easy to filter and identify mirai-related traces in your observability platform. |
File renamed without changes.
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.