LightCDP.Telemetry.OtelBridge (light_cdp v0.2.0)

Copy Markdown View Source

Bridges LightCDP telemetry events to OpenTelemetry spans.

Requires opentelemetry and opentelemetry_api in your dependencies. Does not depend on opentelemetry_telemetry — uses the Erlang OTel API directly to manage span context via a process dictionary token stack.

Setup

In an OTP application, call setup/0 from your Application.start/2 callback:

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    LightCDP.Telemetry.OtelBridge.setup()

    children = [...]
    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

In a script, call it after Mix.install:

Mix.install([{:light_cdp, "~> 0.1"}, {:opentelemetry, "~> 1.4"}, ...])
LightCDP.Telemetry.OtelBridge.setup()

All LightCDP page operations will then produce OTel spans. Wrap your workflow in a root span for a single trace:

require OpenTelemetry.Tracer
OpenTelemetry.Tracer.with_span "my_workflow" do
  {:ok, session} = LightCDP.start()
  {:ok, page} = LightCDP.new_page(session)
  LightCDP.Page.navigate(page, "https://example.com")
  LightCDP.stop(session)
end

Teardown

LightCDP.Telemetry.OtelBridge.teardown()

Summary

Functions

Attaches telemetry handlers that create OpenTelemetry spans.

Computes the OTel span name from a telemetry event and metadata.

Detaches the OpenTelemetry telemetry handlers.

Functions

setup()

Attaches telemetry handlers that create OpenTelemetry spans.

span_name(list, arg2)

Computes the OTel span name from a telemetry event and metadata.

Connection commands include the CDP method for at-a-glance readability:

"connection.command DOM.querySelector"
"connection.command Page.navigate"

Page operations use module.operation:

"page.navigate"
"page.click"

teardown()

Detaches the OpenTelemetry telemetry handlers.