Skip to content

OpenTelemetry auto-instrumentation tool for Golang. It automatically injects OpenTelemetry blocks.

License

Notifications You must be signed in to change notification settings

hedhyw/otelinji

Repository files navigation

otelinji

Version Build Status Go Report Card go-recipes Coverage Status

OpenTelemetry auto-instrumentation tool. It injects a common tracing block to all exported functions.

OpenTelemetry diff

Features:

  • Custom templates are supported. Example: template.
  • If the function contains a named err result parameter, then err will be recorded in the span.
  • It supports different names of ctx parameter.
  • This can also be used with OpenTracing, but will require a custom template.
  • Using creativity, this can be used for any inserts at the beginning of the function.

Installation

MacOS/Linux HomeBrew

brew install hedhyw/main/otelinji

Deb/Rpm

Latest DEB and RPM packages are available on the releases page.

Go

go install github.com/hedhyw/otelinji/cmd/otelinji@latest

Source

git clone [email protected]:hedhyw/otelinji.git
cd gherkingen
task build # Requires https://taskfile.dev/
cp ./bin/gherkingen /usr/local/bin
chmod +x /usr/local/bin

Usage

Basic usage

Inject the layer and rewrite the file (be careful, always commit all changes first).

  • otelinji -filename input_file.go > input_file.go

    or

  • otelinji -w -filename input_file.go

    or in docker

  • docker run \
          --rm \
          --read-only \
          --network none \
          --rm \
          --volume $PWD:/host \
          hedhyw/otelinji:latest \
          -filename /host/internal/pkg/assets/assets_test.go

Recursive run

Running for all Go files in the current directory.

# It will inject the layer to all exported functions.
# It will ignore vendor and .git folders, test and generated files.

find . -name "*.go" \
    | grep -v "vendor/\|.git/\|_test.go" \
    | xargs -n 1 -t otelinji -w -filename

The same in docker:

docker run \
      --rm \
      --read-only \
      --network none \
      --volume $PWD:/host \
      --entrypoint sh \
      hedhyw/otelinji:latest \
      -c " \
            find /host -name \"*.go\" \
            | grep -v \"vendor/\|.git/\|_test.go\" \
            | xargs -n 1 -t /app/otelinji -w -filename \
      "

Help

otelinji --help

Usage of otelinji:
  -filename string
        golang file [required]
  -skip-generated DO NOT EDIT
        skip files with DO NOT EDIT comment (default true)
  -template string
        path to template file [optional] (default "@/otel")
  -version
        print application version and quit
  -w    write result to file [optional]

IDE

License

MIT.

About

OpenTelemetry auto-instrumentation tool for Golang. It automatically injects OpenTelemetry blocks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published