Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexrios/lmotelfy
Automagically insert Open Telemetry spans in your codebase.
https://github.com/alexrios/lmotelfy
ast cli go golang open-telemetry open-telemetry-go otel span
Last synced: about 16 hours ago
JSON representation
Automagically insert Open Telemetry spans in your codebase.
- Host: GitHub
- URL: https://github.com/alexrios/lmotelfy
- Owner: alexrios
- Created: 2022-09-01T04:00:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-03T02:34:08.000Z (about 2 years ago)
- Last Synced: 2024-09-26T07:01:38.921Z (about 16 hours ago)
- Topics: ast, cli, go, golang, open-telemetry, open-telemetry-go, otel, span
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 20
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```go
pakage samplesimport (
"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:
```go
pakage samplesimport (
"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: "."