Coder Social home page Coder Social logo

lmotelfy's Introduction

LMOtelFY

Let Me OTel(Open Telemetry) For You

What this program does?

It will look for two situations:

  • Exported functions that have context.Context as a parameter.
  • HTTP handlers

And create:

  • Start() new span made by "package.function name".
  • defer the span End()
  • call span.RecordError(err) when error is handled in the function.
  • Add the imports needed
Examples

This code:

pakage samples

import (
	"context"
	"errors"
	"log"
	"net/http"
)

func H(w http.ResponseWriter, r *http.Request) {
	 ...
	if err != nil {
		log.Println(err.Error())
		w.WriteHeader(http.StatusUnauthorized)
		return
	}
 ...
}

func C(ctx context.Context) error {
	...
	if err != nil {
		return err
	}
	...
}

will turn into this:

pakage samples

import (
	"context"
	"errors"
	"github.com/example/extensions/telemetry" // New import needed
	"log"
	"net/http"
)

func H(w http.ResponseWriter, r *http.Request) {
	ctx, span := telemetry.FromContext(ctx).Start(ctx, "samples.H")
	defer span.End()
	...
	if err != nil {
		span.RecordError(err)
		log.Println(err.Error())
		w.WriteHeader(http.StatusUnauthorized)
		return
	}
  ...
}

func C(ctx context.Context) error {
	ctx, span := telemetry.FromContext(ctx).Start(ctx, "samples.C")
	defer span.End()
	...
	if err != nil {
		span.RecordError(err)
		return err
	}
  ...
}

Params

  • --dry-run
    • when dry run is true the program will modify the files found
    • default: true
  • --path
    • What path to read?
    • default: "."
  • --import
    • Where is your telemetry functions?
    • default: "github.com/example/extensions/telemetry"
  • --allowed-dirs
    • The list of dir fragments allowed
    • default: "samples"
  • --disallowed-dirs
    • The list of dir fragments disallowed
    • default: "."

lmotelfy's People

Contributors

alexrios avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.