cmd
docs
pkg
api
cmds
datastore
internal
oas_cfg_gen.go
oas_client_gen.go
oas_handlers_gen.go
oas_json_gen.go
oas_labeler_gen.go
oas_middleware_gen.go
oas_operations_gen.go
oas_parameters_gen.go
oas_request_decoders_gen.go
oas_request_encoders_gen.go
oas_response_decoders_gen.go
oas_response_encoders_gen.go
oas_router_gen.go
oas_schemas_gen.go
oas_server_gen.go
oas_unimplemented_gen.go
oas_validators_gen.go
model
service
service_internal
validation
web
.drone.yml
.gitignore
Cargo.lock
Cargo.toml
Containerfile
LICENSE
Makefile
README.md
compose.yaml
generate.go
go.mod
go.sum
openapi-internal.yaml
openapi.yaml
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
)
|
|
|
|
// Labeler is used to allow adding custom attributes to the server request metrics.
|
|
type Labeler struct {
|
|
attrs []attribute.KeyValue
|
|
}
|
|
|
|
// Add attributes to the Labeler.
|
|
func (l *Labeler) Add(attrs ...attribute.KeyValue) {
|
|
l.attrs = append(l.attrs, attrs...)
|
|
}
|
|
|
|
// AttributeSet returns the attributes added to the Labeler as an attribute.Set.
|
|
func (l *Labeler) AttributeSet() attribute.Set {
|
|
return attribute.NewSet(l.attrs...)
|
|
}
|
|
|
|
type labelerContextKey struct{}
|
|
|
|
// LabelerFromContext retrieves the Labeler from the provided context, if present.
|
|
//
|
|
// If no Labeler was found in the provided context a new, empty Labeler is returned and the second
|
|
// return value is false. In this case it is safe to use the Labeler but any attributes added to
|
|
// it will not be used.
|
|
func LabelerFromContext(ctx context.Context) (*Labeler, bool) {
|
|
if l, ok := ctx.Value(labelerContextKey{}).(*Labeler); ok {
|
|
return l, true
|
|
}
|
|
return &Labeler{}, false
|
|
}
|
|
|
|
func contextWithLabeler(ctx context.Context, l *Labeler) context.Context {
|
|
return context.WithValue(ctx, labelerContextKey{}, l)
|
|
}
|