DEV Community

Cover image for Trace kubectl using OpenTelemetry
Adam Gardner
Adam Gardner

Posted on

Trace kubectl using OpenTelemetry

kubectl opentelemetry tracing

kubectl otel is a Kubernetes CLI plugin which will generate OpenTelemetry traces for any kubectl ... command you run and output them to a tracing storage backend of your choice.

For example, this command will time how long it takes to apply the deploy.yaml file and send the trace to a backend.

kubectl otel apply -f deploy.yaml
Enter fullscreen mode Exit fullscreen mode

You could also alias it so the tracing is seamless:

alias ko='kubectl otel'
ko apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Prerequisites

  • Currently only supports Linux and MacOS
  • You must have a standalone binary of tracepusher in your path (ie. you are able to run tracepusher from the command line and see output)
  • You must have an OpenTelemetry collector somewhere so the spans can be sent there

Installation

krew listing - coming soon (hopefully)

For now:

  • Download kubectl-otel
  • Make it executable: chmod +x kubectl-otel
  • Move it to anywhere in your path (eg. /usr/local/bin): sudo mv kubectl-otel /usr/local/bin

Try it out: kubectl otel version should execute kubectl version and trace the time (expected to be quick eg. 0 seconds).

Code on GitHub

This plugin is fully open sourced on GitHub. Drop by, submit an enhancement PR and give the repo a ⭐

Top comments (0)