Skip to content

mashiike/otelattr

Repository files navigation

otelattr

Usage

package main

import (
	"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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages