You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-15 01:04:25 +02:00
Golang opentelemetry-go draft API (incomplete) (#9)
* Work in progress from https://github.com/lightstep/opentelemetry-golang-prototype * Renames * Rename * Finish rename * Rename packages * README
This commit is contained in:
committed by
rghetia
parent
1429272864
commit
e17f4468a6
67
api/scope/scope.go
Normal file
67
api/scope/scope.go
Normal file
@ -0,0 +1,67 @@
|
||||
package scope
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/open-telemetry/opentelemetry-go/api/core"
|
||||
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
|
||||
)
|
||||
|
||||
type (
|
||||
Scope interface {
|
||||
ScopeID() core.ScopeID
|
||||
}
|
||||
|
||||
Mutable interface {
|
||||
Scope
|
||||
|
||||
SetAttribute(core.KeyValue)
|
||||
SetAttributes(...core.KeyValue)
|
||||
|
||||
ModifyAttribute(core.Mutator)
|
||||
ModifyAttributes(...core.Mutator)
|
||||
}
|
||||
|
||||
scopeIdent struct {
|
||||
id core.ScopeID
|
||||
}
|
||||
|
||||
scopeKeyType struct{}
|
||||
)
|
||||
|
||||
var (
|
||||
scopeKey = &scopeKeyType{}
|
||||
emptyScope = &scopeIdent{}
|
||||
)
|
||||
|
||||
func SetActive(ctx context.Context, scope Scope) context.Context {
|
||||
return context.WithValue(ctx, scopeKey, scope)
|
||||
}
|
||||
|
||||
func Active(ctx context.Context) Scope {
|
||||
if scope, has := ctx.Value(scopeKey).(Scope); has {
|
||||
return scope
|
||||
}
|
||||
return emptyScope
|
||||
}
|
||||
|
||||
func (s *scopeIdent) ScopeID() core.ScopeID {
|
||||
if s == nil {
|
||||
return core.ScopeID{}
|
||||
}
|
||||
return s.id
|
||||
}
|
||||
|
||||
func New(parent core.ScopeID, attributes ...core.KeyValue) Scope {
|
||||
eventID := observer.Record(observer.Event{
|
||||
Type: observer.NEW_SCOPE,
|
||||
Scope: parent,
|
||||
Attributes: attributes,
|
||||
})
|
||||
return &scopeIdent{
|
||||
id: core.ScopeID{
|
||||
EventID: eventID,
|
||||
SpanContext: parent.SpanContext,
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user