-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Remy Chantenay <[email protected]>
- Loading branch information
1 parent
b03f7d6
commit 93f960b
Showing
12 changed files
with
459 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
# otel-tag | ||
Simple package that extracts OpenTelemetry span attributes from a struct based on tags. | ||
Simple package that extracts OpenTelemetry [span attributes](https://opentelemetry.io/docs/demo/telemetry-features/manual-span-attributes/) and [baggage members](https://opentelemetry.io/docs/concepts/signals/baggage/) from a struct based on tags. | ||
|
||
> [!WARNING] | ||
> Please bear in mind that this package does not intend to cater to all use cases and please everyone. The code could also do with some refactoring here and there, but it's doing the job. | ||
## Shortcomings | ||
- Do not support embedded structs. | ||
- Does not support basic type pointers (only struct pointers). | ||
|
||
## Usage | ||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/otel/baggage" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
oteltag "github.com/remychantenay/otel-tag" | ||
) | ||
|
||
type User struct { | ||
ID string `otel:"app.user.id"` | ||
Username string `otel:"app.user.username"` | ||
IsPremium bool `otel:"app.user.premium"` | ||
|
||
UserDetails UserDetails | ||
} | ||
|
||
type UserDetails struct { | ||
Website string `otel:"app.user.website,omitempty"` | ||
Bio string // Not tagged, will be ignored. | ||
} | ||
|
||
func main() { | ||
// Span attributes. | ||
_, span := tracer.Start(context.Background(), "someOperation", | ||
trace.WithAttributes(oteltag.SpanAttributes(m)...), | ||
) | ||
defer span.End() | ||
|
||
// Baggage Members. | ||
members := oteltag.BaggageMembers(m) | ||
bag, _ := baggage.New(members...) | ||
ctx := baggage.ContextWithBaggage(context.Background(), bag) | ||
} | ||
``` | ||
|
||
## License | ||
Apache License Version 2.0 | ||
|
||
TODO | ||
- Shit! What about attribute name prefix???! Init? | ||
- Remove t.Log() calls in tests | ||
- Complete README.md with example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.