Skip to content

Commit

Permalink
fix bug, add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Dec 13, 2024
1 parent c1747ab commit af8d3a0
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 13 deletions.
13 changes: 9 additions & 4 deletions ext/telemetry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ enum DenoPeriodicReaderMessage {
#[derive(Debug)]
struct DenoPeriodicReader {
tx: tokio::sync::mpsc::Sender<DenoPeriodicReaderMessage>,
temporality: Temporality,
}

impl MetricReader for DenoPeriodicReader {
Expand All @@ -323,20 +324,22 @@ impl MetricReader for DenoPeriodicReader {
fn force_flush(&self) -> opentelemetry_sdk::metrics::MetricResult<()> {
let (tx, rx) = oneshot::channel();
let _ = self.tx.try_send(DenoPeriodicReaderMessage::ForceFlush(tx));
rx.blocking_recv().unwrap()
deno_core::futures::executor::block_on(rx).unwrap()?;
Ok(())
}

fn shutdown(&self) -> opentelemetry_sdk::metrics::MetricResult<()> {
let (tx, rx) = oneshot::channel();
let _ = self.tx.try_send(DenoPeriodicReaderMessage::Shutdown(tx));
rx.blocking_recv().unwrap()
deno_core::futures::executor::block_on(rx).unwrap()?;
Ok(())
}

fn temporality(
&self,
_kind: opentelemetry_sdk::metrics::InstrumentKind,
) -> Temporality {
Temporality::Cumulative
self.temporality
}
}

Expand All @@ -352,6 +355,8 @@ impl DenoPeriodicReader {

let (tx, mut rx) = tokio::sync::mpsc::channel(256);

let temporality = PushMetricExporter::temporality(&exporter);

let worker = async move {
let inner = ManualReader::builder()
.with_temporality(PushMetricExporter::temporality(&exporter))
Expand Down Expand Up @@ -454,7 +459,7 @@ impl DenoPeriodicReader {
.unbounded_send(worker.boxed())
.expect("failed to send task to shared OpenTelemetry runtime");

DenoPeriodicReader { tx }
DenoPeriodicReader { tx, temporality }
}
}

Expand Down
8 changes: 6 additions & 2 deletions ext/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,13 +1162,17 @@ async function observe(): Promise<void> {
// Primordials are not needed, because this is a SafeSet.
// deno-lint-ignore prefer-primordials
for (const callback of callbacks) {
ArrayPrototypePush(promises, PromiseTry(callback, result));
// PromiseTry is not in primordials?
// deno-lint-ignore prefer-primordials
ArrayPrototypePush(promises, Promise.try(callback, result));
}
}
// Primordials are not needed, because this is a SafeMap.
// deno-lint-ignore prefer-primordials
for (const { 0: callback, 1: result } of BATCH_CALLBACKS) {
ArrayPrototypePush(promises, PromiseTry(callback, result));
// PromiseTry is not in primordials?
// deno-lint-ignore prefer-primordials
ArrayPrototypePush(promises, Promise.try(callback, result));
}
await SafePromiseAll(promises);
}
Expand Down
17 changes: 10 additions & 7 deletions tests/specs/cli/otel_basic/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
{
"steps": [
{
"tests": {
"basic": {
"args": "run -A main.ts basic.ts",
"output": "basic.out"
},
{
"natural_exit": {
"args": "run -A main.ts natural_exit.ts",
"output": "natural_exit.out"
},
{
"deno_dot_exit": {
"args": "run -A main.ts deno_dot_exit.ts",
"output": "deno_dot_exit.out"
},
{
"uncaught": {
"args": "run -A main.ts uncaught.ts",
"output": "uncaught.out"
},
{
"metric": {
"envs": {
"OTEL_METRIC_EXPORT_INTERVAL": "1000"
},
"args": "run -A main.ts metric.ts",
"output": "metric.out"
},
{
"args": "run -A --unstable-otel context.ts",
"output": ""
}
]
}
}
Loading

0 comments on commit af8d3a0

Please sign in to comment.