From 6d3373803b8e6b8ac994cc6ad3bba554e751fd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 19 Nov 2024 13:35:46 +0100 Subject: [PATCH 1/5] Tracing and OpenTelemetry --- runtime/_data.ts | 1 + runtime/fundamentals/tracing_and_opentelemetry.md | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 runtime/fundamentals/tracing_and_opentelemetry.md diff --git a/runtime/_data.ts b/runtime/_data.ts index f95138ba0..7ce7e8249 100644 --- a/runtime/_data.ts +++ b/runtime/_data.ts @@ -35,6 +35,7 @@ export const sidebar = [ label: "HTTP Server", id: "/runtime/fundamentals/http_server/", }, + "/runtime/fundamentals/tracing_and_opentelemetry/", "/runtime/fundamentals/stability_and_releases/", ], }, diff --git a/runtime/fundamentals/tracing_and_opentelemetry.md b/runtime/fundamentals/tracing_and_opentelemetry.md new file mode 100644 index 000000000..85292f8f5 --- /dev/null +++ b/runtime/fundamentals/tracing_and_opentelemetry.md @@ -0,0 +1,5 @@ +--- +title: "Tracing and OpenTelemetry" +--- + +Lorem ipsum dolor sit amet From 3a056fd4434eb05d4ee6cc9f0ffc4078bdce4e8f Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 20 Nov 2024 11:49:00 +0100 Subject: [PATCH 2/5] content --- .../fundamentals/tracing_and_opentelemetry.md | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/runtime/fundamentals/tracing_and_opentelemetry.md b/runtime/fundamentals/tracing_and_opentelemetry.md index 85292f8f5..117568f85 100644 --- a/runtime/fundamentals/tracing_and_opentelemetry.md +++ b/runtime/fundamentals/tracing_and_opentelemetry.md @@ -2,4 +2,67 @@ title: "Tracing and OpenTelemetry" --- -Lorem ipsum dolor sit amet +Deno provides an experimental high-performance implementation of OpenTelemetry +([What is OpenTelemetry?][1]). You can use the official `@opentelemetry` +packages in combination with Deno's `@deno/otel` package to automatically +export telemetry from your application. + +To activate OpenTelemetry, at least two environment variables are needed: + +- [`OTEL_EXPORTER_OTLP_ENDPOINT`][2]: The URL to which spans, metrics, and logs +will be sent. The default is `http://localhost:4318` and any scheme, host, +port, and path provided will override that section of the default URL. +- [`OTEL_EXPORTER_OTLP_PROTOCOL`][2]: Currently this may be one of +`http/protobuf` or `http/json`. + +The OpenTelemetry specification provides a full list of environment variables: +https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/. + +As this API is currently unstable, Deno must also be run with the +`--unstable-otel` flag. + +## A Quick Example + +Grafana provides a useful docker container to test out OpenTelemetry: +https://github.com/grafana/docker-otel-lgtm. Let's connect a simple Deno +application to this. + +```js +import { trace } from "npm:@opentelemetry/api"; +import "jsr:@deno/otel/register"; + +const tracer = trace.getTracer("my-app"); + +Deno.serve(async (request) => { + return await tracer.startActiveSpan("request", async (span) => { + console.log('Incoming request', request); + const body = await fetch('https://hello.deno.dev/').then((r) => r.text()); + const response = new Response(body, { statusCode: 200 }); + span.end(); + return response; + }); +}); +``` + +```bash + # Start Grafana. It will provide a web interface at localhost:3000 +$ ./run-lgtm.sh + # OTEL collector is now running on localhost:4318 +$ export OTEL_EXPORTER_OTLP_ENDPOINT=localhost + # It accepts http/json and http/protobuf. +$ export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf + # Let's give our app a nice name in telemetry data. +$ export OTEL_SERVICE_NAME=my-app + # Deno needs the `--unstable-otel` flag. +$ deno run -A --unstable-otel my-app.js + # Try making some requests to localhost:8000 and + # exploring the Grafana dashboard. +``` +We can see logs and traces have been collected, and explore the data they contain: + +| | | +|-|-| +| [](https://gc.gy/a2e7b6a1-ee6f-40ff-a7b5-895d15568374.png) | [](https://gc.gy/38d70281-fa06-48c4-9068-8a96d4ea9fe8.png) | + +[1]: https://opentelemetry.io/docs/what-is-opentelemetry/ +[2]: https://opentelemetry.io/docs/specs/otel/protocol/exporter/ From 8f5bae27f21b5831299de145d4caefbe5f3d76f7 Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 20 Nov 2024 11:53:15 +0100 Subject: [PATCH 3/5] Update tracing_and_opentelemetry.md --- runtime/fundamentals/tracing_and_opentelemetry.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/fundamentals/tracing_and_opentelemetry.md b/runtime/fundamentals/tracing_and_opentelemetry.md index 117568f85..100c79186 100644 --- a/runtime/fundamentals/tracing_and_opentelemetry.md +++ b/runtime/fundamentals/tracing_and_opentelemetry.md @@ -60,9 +60,10 @@ $ deno run -A --unstable-otel my-app.js ``` We can see logs and traces have been collected, and explore the data they contain: -| | | -|-|-| -| [](https://gc.gy/a2e7b6a1-ee6f-40ff-a7b5-895d15568374.png) | [](https://gc.gy/38d70281-fa06-48c4-9068-8a96d4ea9fe8.png) | +
+ + +
[1]: https://opentelemetry.io/docs/what-is-opentelemetry/ [2]: https://opentelemetry.io/docs/specs/otel/protocol/exporter/ From b8f45dfde8507ad9b84930162b091f57162a3158 Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 20 Nov 2024 11:54:18 +0100 Subject: [PATCH 4/5] format --- .../fundamentals/tracing_and_opentelemetry.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/runtime/fundamentals/tracing_and_opentelemetry.md b/runtime/fundamentals/tracing_and_opentelemetry.md index 100c79186..4c8d891f6 100644 --- a/runtime/fundamentals/tracing_and_opentelemetry.md +++ b/runtime/fundamentals/tracing_and_opentelemetry.md @@ -4,16 +4,16 @@ title: "Tracing and OpenTelemetry" Deno provides an experimental high-performance implementation of OpenTelemetry ([What is OpenTelemetry?][1]). You can use the official `@opentelemetry` -packages in combination with Deno's `@deno/otel` package to automatically -export telemetry from your application. +packages in combination with Deno's `@deno/otel` package to automatically export +telemetry from your application. To activate OpenTelemetry, at least two environment variables are needed: - [`OTEL_EXPORTER_OTLP_ENDPOINT`][2]: The URL to which spans, metrics, and logs -will be sent. The default is `http://localhost:4318` and any scheme, host, -port, and path provided will override that section of the default URL. + will be sent. The default is `http://localhost:4318` and any scheme, host, + port, and path provided will override that section of the default URL. - [`OTEL_EXPORTER_OTLP_PROTOCOL`][2]: Currently this may be one of -`http/protobuf` or `http/json`. + `http/protobuf` or `http/json`. The OpenTelemetry specification provides a full list of environment variables: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/. @@ -35,8 +35,8 @@ const tracer = trace.getTracer("my-app"); Deno.serve(async (request) => { return await tracer.startActiveSpan("request", async (span) => { - console.log('Incoming request', request); - const body = await fetch('https://hello.deno.dev/').then((r) => r.text()); + console.log("Incoming request", request); + const body = await fetch("https://hello.deno.dev/").then((r) => r.text()); const response = new Response(body, { statusCode: 200 }); span.end(); return response; @@ -58,7 +58,9 @@ $ deno run -A --unstable-otel my-app.js # Try making some requests to localhost:8000 and # exploring the Grafana dashboard. ``` -We can see logs and traces have been collected, and explore the data they contain: + +We can see logs and traces have been collected, and explore the data they +contain:
From e6e5b9b17d8f6ec7eefdd603d663021ae2408073 Mon Sep 17 00:00:00 2001 From: snek Date: Wed, 20 Nov 2024 12:08:01 +0100 Subject: [PATCH 5/5] x --- runtime/fundamentals/tracing_and_opentelemetry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/fundamentals/tracing_and_opentelemetry.md b/runtime/fundamentals/tracing_and_opentelemetry.md index 4c8d891f6..7dfef65d2 100644 --- a/runtime/fundamentals/tracing_and_opentelemetry.md +++ b/runtime/fundamentals/tracing_and_opentelemetry.md @@ -35,7 +35,7 @@ const tracer = trace.getTracer("my-app"); Deno.serve(async (request) => { return await tracer.startActiveSpan("request", async (span) => { - console.log("Incoming request", request); + console.log("Incoming request for", request.url); const body = await fetch("https://hello.deno.dev/").then((r) => r.text()); const response = new Response(body, { statusCode: 200 }); span.end();