Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
^[\.]?air\.toml$
^\.vscode$
^cran-comments\.md$
^\.claude$
^CLAUDE.md$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ inst/doc
.vscode
air.toml
revdep/
.claude
CLAUDE.md
.DS_Store
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# mirai (development version)

#### Updates

* OpenTelemetry 'daemons' and 'daemon' span attributes have been updated to better follow semantic conventions for RPC (#481).

# mirai 2.5.1

#### New Features
Expand Down
8 changes: 7 additions & 1 deletion R/daemon.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,15 @@ eval_mirai <- function(._mirai_., sock = NULL) {
}

otel_daemon_span <- function(url, end_span = NULL) {
purl <- parse_url(url)
otel::start_local_active_span(
if (length(end_span)) "daemon->end" else "daemon",
attributes = otel::as_attributes(list(url = url)),
attributes = otel::as_attributes(list(
rpc.system = "mirai",
server.address = if (nzchar(purl[["hostname"]])) purl[["hostname"]] else purl[["path"]],
server.port = purl[["port"]],
network.transport = purl[["scheme"]]
)),
links = if (length(end_span)) list(daemon = end_span),
tracer = otel_tracer
)
Expand Down
12 changes: 8 additions & 4 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,17 @@ register_serial <- function(class, sfunc, ufunc) {
compute_env <- function(x) ..[[if (is.null(x)) .[["cp"]] else x]]

otel_daemons_span <- function(envir, .compute, reset = FALSE) {
purl <- parse_url(envir[["url"]])
otel::start_local_active_span(
if (reset) "daemons->reset" else "daemons",
attributes = otel::as_attributes(list(
url = envir[["url"]],
n = envir[["n"]],
dispatcher = if (is.null(envir[["dispatcher"]])) "false" else "true",
compute_profile = .compute
rpc.system = "mirai",
server.address = if (nzchar(purl[["hostname"]])) purl[["hostname"]] else purl[["path"]],
server.port = purl[["port"]],
network.transport = purl[["scheme"]],
mirai.n = envir[["n"]],
mirai.dispatcher = if (is.null(envir[["dispatcher"]])) "false" else "true",
mirai.compute = .compute
)),
links = if (reset) list(daemons = envir[["otel_span"]]),
tracer = otel_tracer
Expand Down
15 changes: 13 additions & 2 deletions dev/vignettes/_v05-opentelemetry.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,24 @@ mirai creates several types of spans to represent different operations:
**`daemons` / `daemons->reset`** - Root span for a compute profile

- **Kind**: `internal`
- **Attributes**: `url`, `n` (number of daemons), `dispatcher` (true/false), `compute_profile`
- **Attributes**:
+ `rpc.system` ('mirai')
+ `server.address` (e.g. '127.0.0.1' or 'hostname')
+ `server.port` (where applicable)
+ `network.transport` (e.g. 'tcp' or 'ipc')
+ `mirai.n` (number of daemons)
+ `mirai.dispatcher` (true/false)
+ `mirai.compute` (profile name)
- **Lifecycle**: Created when daemons are set, and when daemons are reset

**`daemon` / `daemon->end`** - Individual daemon process span

- **Kind**: `internal`
- **Attributes**: `url`
- **Attributes**:
+ `rpc.system` ('mirai')
+ `server.address` (e.g. '127.0.0.1' or 'hostname')
+ `server.port` (where applicable)
+ `network.transport` (e.g. 'tcp' or 'ipc')
- **Lifecycle**: Created when a daemon process starts and when it ends

**`mirai_map`** - Parallel map operation span
Expand Down
33 changes: 23 additions & 10 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ connection && requireNamespace("otel", quietly = TRUE) && Sys.getenv("NOT_CRAN")
ns[["otel_tracer"]] <- otel::get_tracer(name = mirai:::otel_tracer_name)
lockBinding("otel_tracer", ns)
url <- local_url()
purl <- parse_url(url)
test_true(daemons(url = url, dispatcher = FALSE))
mp <- mirai_map(1:3, rnorm)
m1 <- mirai(stop("error"))
Expand All @@ -466,10 +467,13 @@ connection && requireNamespace("otel", quietly = TRUE) && Sys.getenv("NOT_CRAN")
test_equal(length(traces), 15L)
test_equal(traces[[1L]]$name, "daemons")
test_equal(traces[[1L]]$kind, "internal")
test_equal(traces[[1L]]$attributes$url, url)
test_equal(traces[[1L]]$attributes$n, 1L)
test_equal(traces[[1L]]$attributes$dispatcher, "false")
test_equal(traces[[1L]]$attributes$compute_profile, "default")
test_equal(traces[[1L]]$attributes$rpc.system, "mirai")
test_equal(traces[[1L]]$attributes$server.address, purl[["path"]])
test_equal(traces[[1L]]$attributes$server.port, purl[["port"]])
test_equal(traces[[1L]]$attributes$network.transport, purl[["scheme"]])
test_equal(traces[[1L]]$attributes$mirai.n, 1L)
test_equal(traces[[1L]]$attributes$mirai.dispatcher, "false")
test_equal(traces[[1L]]$attributes$mirai.compute, "default")
test_equal(traces[[2L]]$name, "mirai")
test_equal(traces[[2L]]$kind, "client")
test_equal(traces[[2L]]$links[[1L]]$span_id, traces[[1L]]$span_id)
Expand All @@ -487,7 +491,10 @@ connection && requireNamespace("otel", quietly = TRUE) && Sys.getenv("NOT_CRAN")
test_equal(traces[[6L]]$links[[1L]]$span_id, traces[[1L]]$span_id)
test_equal(traces[[8L]]$name, "daemon")
test_equal(traces[[8L]]$kind, "internal")
test_equal(traces[[8L]]$attributes$url, url)
test_equal(traces[[8L]]$attributes$rpc.system, "mirai")
test_equal(traces[[8L]]$attributes$server.address, purl[["path"]])
test_equal(traces[[8L]]$attributes$server.port, purl[["port"]])
test_equal(traces[[8L]]$attributes$network.transport, purl[["scheme"]])
test_equal(traces[[9L]]$name, "daemon->eval")
test_equal(traces[[9L]]$kind, "server")
test_equal(traces[[9L]]$parent, traces[[2L]]$span_id)
Expand All @@ -498,14 +505,20 @@ connection && requireNamespace("otel", quietly = TRUE) && Sys.getenv("NOT_CRAN")
test_equal(traces[[13L]]$description, "miraiInterrupt")
test_equal(traces[[14L]]$name, "daemon->end")
test_equal(traces[[14L]]$kind, "internal")
test_equal(traces[[14L]]$attributes$url, url)
test_equal(traces[[14L]]$attributes$rpc.system, "mirai")
test_equal(traces[[14L]]$attributes$server.address, purl[["path"]])
test_equal(traces[[14L]]$attributes$server.port, purl[["port"]])
test_equal(traces[[14L]]$attributes$network.transport, purl[["scheme"]])
test_equal(traces[[14L]]$links[[1L]]$span_id, traces[[8L]]$span_id)
test_equal(traces[[15L]]$name, "daemons->reset")
test_equal(traces[[15L]]$kind, "internal")
test_equal(traces[[15L]]$attributes$url, url)
test_equal(traces[[15L]]$attributes$n, 1L)
test_equal(traces[[15L]]$attributes$dispatcher, "false")
test_equal(traces[[15L]]$attributes$compute_profile, "default")
test_equal(traces[[15L]]$attributes$rpc.system, "mirai")
test_equal(traces[[15L]]$attributes$server.address, purl[["path"]])
test_equal(traces[[15L]]$attributes$server.port, purl[["port"]])
test_equal(traces[[15L]]$attributes$network.transport, purl[["scheme"]])
test_equal(traces[[15L]]$attributes$mirai.n, 1L)
test_equal(traces[[15L]]$attributes$mirai.dispatcher, "false")
test_equal(traces[[15L]]$attributes$mirai.compute, "default")
}
}
test_false(daemons(0))
Expand Down
15 changes: 13 additions & 2 deletions vignettes/v05-opentelemetry.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,24 @@ mirai creates several types of spans to represent different operations:
**`daemons` / `daemons->reset`** - Root span for a compute profile

- **Kind**: `internal`
- **Attributes**: `url`, `n` (number of daemons), `dispatcher` (true/false), `compute_profile`
- **Attributes**:
+ `rpc.system` ('mirai')
+ `server.address` (e.g. '127.0.0.1' or 'hostname')
+ `server.port` (where applicable)
+ `network.transport` (e.g. 'tcp' or 'ipc')
+ `mirai.n` (number of daemons)
+ `mirai.dispatcher` (true/false)
+ `mirai.compute` (profile name)
- **Lifecycle**: Created when daemons are set, and when daemons are reset

**`daemon` / `daemon->end`** - Individual daemon process span

- **Kind**: `internal`
- **Attributes**: `url`
- **Attributes**:
+ `rpc.system` ('mirai')
+ `server.address` (e.g. '127.0.0.1' or 'hostname')
+ `server.port` (where applicable)
+ `network.transport` (e.g. 'tcp' or 'ipc')
- **Lifecycle**: Created when a daemon process starts and when it ends

**`mirai_map`** - Parallel map operation span
Expand Down