otel-tui

repository·main·Indexed 20 days ago

https://github.com/ymtdzzz/otel-tui

A terminal-based OpenTelemetry viewer for real-time visualization of traces, metrics, and logs. It supports OTLP (gRPC/HTTP), Zipkin, Prometheus, and Datadog formats. The tool can be installed via Homebrew, Go, Nix, Docker, or as a binary, and can be integrated as a TUI exporter within an OpenTelemetry Collector.

Tokens
4K
Snippets
14
Records
18
Agent score
77%

What's inside otel-tui

  1. Configure receiver ports and protocols

    main

    By default, otel-tui listens on the following ports:

    • 4317: OpenTelemetry signals (gRPC)
    • 4318: OpenTelemetry signals (HTTP)

    Additional protocols can be enabled via flags:

    • Zipkin (Traces): Port 9411 (requires --enable-zipkin)
    • Datadog (Traces, Metrics): Port 8126 (requires --enable-datadog)
    • DogStatsD (Metrics): Port 8125 (requires --enable-datadog)

    Note: The server includes localhost in the Access-Control-Allow-Origin header, allowing telemetry to be sent directly from browser applications running on localhost.

  2. Install otel-tui

    main

    You can install otel-tui using several methods depending on your environment:

    Homebrew (macOS/Linux)

    brew install ymtdzzz/tap/otel-tui

    Go install

    go install github.com/ymtdzzz/otel-tui@latest

    Nix

    nix develop github:ymtdzzz/otel-tui

    Docker

    Run the latest image directly:

    docker run --rm -it --name otel-tui ymtdzzz/otel-tui:latest

    GitHub Releases

    Download the executable binary directly from the GitHub releases page.

    brew install ymtdzzz/tap/otel-tui
  3. Run otel-tui in Docker Compose

    main

    To use otel-tui within a Docker Compose environment, add it as a service and configure your OpenTelemetry Collector (otelcol) to export to it.

    1. Add the service to docker-compose.yaml

    Note that stdin_open: true and tty: true are required to interact with the TUI. You can use entrypoint to pass specific flags like --enable-zipkin.

    2. Configure your exporter

    Point your OTLP exporter to the oteltui service name on port 4317 (gRPC).

    3. Attach to the TUI

    Run your services in the background, then use docker compose attach to view the interface.

    oteltui:
      image: ymtdzzz/otel-tui:latest
      container_name: otel-tui
      stdin_open: true
      tty: true
      # Override entrypoint if you want use options
      entrypoint: ["/otel-tui", "--enable-zipkin"]
    # Example otelcol configuration
    exporters:
      otlp:
        endpoint: oteltui:4317
        tls:
          insecure: true
    service:
      pipelines:
        traces:
          exporters: [otlp]
        logs:
          exporters: [otlp]
    # Run services as usual
    $ docker compose up -d
    
    # Show TUI in your current terminal session
    $ docker compose attach oteltui
    
    # Detach by pressing Ctrl+p -> Ctrl+q
  4. How Prometheus scraping targets are parsed

    main

    The PromTarget field accepts a slice of strings representing URLs. otel-tui automatically parses these strings into PromScrapeConfig objects.

    Parsing Rules:

    • If a scheme (e.g., http:// or https://) is missing, http:// is prepended by default.
    • The JobName is automatically generated as oteltui_prom_{index}.
    • The Target field is extracted from the URL host.
    • The Scheme is extracted from the URL protocol.
    • The MetricsPath is extracted from the URL path.
    • URL query parameters are converted into a sorted list of Param objects (where Param contains a Key and a slice of Values).
    // Example of how a target string is transformed:
    // Input: "https://example.com/metrics?foo=bar&foo=baz"
    // Resulting PromScrapeConfig:
    // {
    //     JobName: "oteltui_prom_1",
    //     Target: "example.com",
    //     Scheme: "https",
    //     MetricsPath: "/metrics",
    //     Params: [
    //         {Key: "foo", Values: ["bar", "baz"]}
    //     ]
    // }
  5. Enable clipboard functionality on Linux

    main

    The clipboard feature (triggered by the y key to copy log bodies) requires platform-specific tools to function.

    • Linux/Unix: You must install xclip or xsel.
    • macOS/Windows: No additional tools are required.

    If these tools are not installed on Linux, the application will continue to run normally, but the clipboard functionality will be disabled.

  6. Authenticate OTLP receivers with AUTH_TOKEN

    main

    The otel-tui collector supports Bearer token authentication for OTLP receivers (both HTTP and gRPC). You can provide this token via the AUTH_TOKEN environment variable.

    export AUTH_TOKEN="your-bearer-token"
    ./otel-tui
  7. Configure otel-tui CLI options

    main

    Use the following flags to configure the receiver ports, enabled protocols, and data sources:

    FlagDescription
    --debug-logEnable debug log output to file (/tmp/otel-tui.log)
    --enable-datadogEnable the Datadog and DogStatsD receivers
    --enable-zipkinEnable the Zipkin receiver
    --from-json-file <string>The JSON file path exported by JSON exporter
    --grpc <int>The port number on which we listen for OTLP gRPC payloads (default 4317)
    --host <string>The host where we expose our OTLP endpoints (default 0.0.0.0)
    --http <int>The port number on which we listen for OTLP HTTP payloads (default 4318)
    --prom-target <stringArray>Enable the Prometheus receiver and specify target endpoints (e.g., --prom-target "localhost:9000")
    --versionShow version
    Usage:
      otel-tui [flags]
    
    Flags:
          --debug-log                 Enable debug log output to file (/tmp/otel-tui.log)
          --enable-datadog            Enable the Datadog and DogStatsD receivers
          --enable-zipkin             Enable the zipkin receiver
          --from-json-file string     The JSON file path exported by JSON exporter
          --grpc int                  The port number on which we listen for OTLP grpc payloads (default 4317)
      -h, --help                      help for otel-tui
          --host string               The host where we expose our OTLP endpoints (default "0.0.0.0")
          --http int                  The port number on which we listen for OTLP http payloads (default 4318)
          --prom-target stringArray   Enable the prometheus receiver and specify the target endpoints for the receiver (--prom-target "localhost:9000" --prom-target "http://other-host:9000/custom/prometheus")
      -v, --version                   version for otel-tui
  8. Push traces, metrics, and logs to the TUI

    main

    The exporter implements the following methods to ingest telemetry data into the TUI store:

    • pushTraces(ctx, traces): Adds ptrace.Traces to the TUI.
    • pushMetrics(ctx, metrics): Adds pmetric.Metrics to the TUI.
    • pushLogs(ctx, logs): Adds plog.Logs to the TUI.
    func (e *tuiExporter) pushTraces(_ context.Context, traces ptrace.Traces) error
    func (e *tuiExporter) pushMetrics(_ context.Context, metrics pmetric.Metrics) error
    func (e *tuiExporter) pushLogs(_ context.Context, logs plog.Logs) error
  9. Implement the tuiexporter for OpenTelemetry Collector

    main

    The tuiexporter package provides a mechanism to export OpenTelemetry traces, metrics, and logs directly to a Terminal User Interface (TUI). It is designed to be used as a component within an OpenTelemetry Collector.

    To use it, you must implement the standard exporter methods: pushTraces, pushMetrics, and pushLogs. These methods take OpenTelemetry data types (ptrace.Traces, pmetric.Metrics, and plog.Logs) and store them in the TUI's internal store for visualization.

  10. Render configuration to YAML

    main

    The RenderYml() method allows you to generate a YAML configuration string by applying the current Config values to an internal template (config.yml.tpl). This is useful for exporting the current state of the configuration into a file format.

    yamlString, err := cfg.RenderYml()
    if err != nil {
        // handle error
    }
    fmt.Println(yamlString)
  11. Configure the TUI exporter via Config struct

    main

    The Config struct defines the configuration parameters for the TUI exporter. It is compatible with the component.Config interface from the OpenTelemetry Collector.

    Key configuration fields:

    • FromJSONFile: A boolean flag (mapped from from_json_file) indicating if configuration should be loaded from a JSON file.
    • DebugLogFilePath: A string (mapped from debug_log_file_path) specifying the file path where debug logs should be written.
    type Config struct {
    	FromJSONFile     bool   `mapstructure:"from_json_file"` 
    	DebugLogFilePath string `mapstructure:"debug_log_file_path"` 
    }
  12. Run otel-tui in interactive mode

    main

    The runInteractive function initializes the otel-tui command with the provided otelcol.CollectorSettings and executes it. This starts the OpenTelemetry Collector with the integrated TUI (Terminal User Interface) viewer. The command is configured to handle OTLP HTTP and gRPC payloads, and can be customized via CLI flags.

    err := runInteractive(params)
    if err != nil {
    	// handle error
    }