otelinji

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2022 License: MIT

README

otelinji

Version Build Status Go Report Card Coverage Status

OpenTelemetry auto-instrumentation tool. It generates code with added OpenTelemetry blocks.

It injects a common open-telemetry block to all exported functions:

func Example(ctx context.Context) {
    ctx, span := otel.Tracer("package").Start(ctx, "Readme")
    defer span.End()
}

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

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

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

Recursive run
# 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
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")
  -w    write result to file [optional]

Directories

Path Synopsis
cmd
otelinji command
internal
app
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL