https://github.com/mashiike/otelattr
https://github.com/mashiike/otelattr
Last synced: 30 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mashiike/otelattr
- Owner: mashiike
- License: mit
- Created: 2024-09-11T03:31:52.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T20:56:48.000Z (5 months ago)
- Last Synced: 2025-04-30T07:04:58.575Z (30 days ago)
- Language: Go
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# otelattr
## Usage
```golang
package mainimport (
"encoding/json"
"os""github.com/mashiike/otelattr"
)type HTTPContext struct {
Status int `otelattr:"http.status_code"`
Method string `otelattr:"http.method"`
Path string `otelattr:"http.path"`
}func main() {
httpCtx := HTTPContext{
Status: 200,
Method: "GET",
Path: "/",
}
attrs, err := otelattr.MarshalOtelAttributes(httpCtx)
if err != nil {
panic(err)
}
enc := json.NewEncoder(os.Stdout)
for _, attr := range attrs {
if err := enc.Encode(attr); err != nil {
panic(err)
}
}
// Output:
//{"Key":"http.status_code","Value":{"Type":"INT64","Value":200}}
//{"Key":"http.method","Value":{"Type":"STRING","Value":"GET"}}
//{"Key":"http.path","Value":{"Type":"STRING","Value":"/"}}
}
```LICENSE: MIT