1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-01 13:07:51 +02:00

split core.go (#39)

This commit is contained in:
thinkerou 2019-07-02 03:17:50 +08:00 committed by rghetia
parent 56fe193518
commit dc4a44ca4e
2 changed files with 79 additions and 56 deletions

View File

@ -23,19 +23,6 @@ import (
"github.com/open-telemetry/opentelemetry-go/api/unit"
)
type ScopeID struct {
EventID
SpanContext
}
type SpanContext struct {
TraceIDHigh uint64
TraceIDLow uint64
SpanID uint64
}
type EventID uint64
type BaseMeasure interface {
Name() string
Description() string
@ -51,14 +38,6 @@ type Measure interface {
V(float64) KeyValue
}
type Measurement struct {
// NOTE: If we add a ScopeID field this can carry
// pre-aggregated measures via the stats.Record API.
Measure Measure
Value float64
ScopeID ScopeID
}
type Key interface {
BaseMeasure
@ -132,31 +111,6 @@ const (
DELETE
)
var (
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
// conditions.
INVALID_SPAN_CONTEXT = SpanContext{}
)
func (sc SpanContext) HasTraceID() bool {
return sc.TraceIDHigh != 0 || sc.TraceIDLow != 0
}
func (sc SpanContext) HasSpanID() bool {
return sc.SpanID != 0
}
func (sc SpanContext) SpanIDString() string {
p := fmt.Sprintf("%.16x", sc.SpanID)
return p[0:3] + ".." + p[13:16]
}
func (sc SpanContext) TraceIDString() string {
p1 := fmt.Sprintf("%.16x", sc.TraceIDHigh)
p2 := fmt.Sprintf("%.16x", sc.TraceIDLow)
return p1[0:3] + ".." + p2[13:16]
}
// TODO make this a lazy one-time conversion.
func (v Value) Emit() string {
switch v.Type {
@ -181,16 +135,12 @@ func (m Mutator) WithMaxHops(hops int) Mutator {
return m
}
func (e EventID) Scope() ScopeID {
return ScopeID{
EventID: e,
}
}
func (s SpanContext) Scope() ScopeID {
return ScopeID{
SpanContext: s,
}
type Measurement struct {
// NOTE: If we add a ScopeID field this can carry
// pre-aggregated measures via the stats.Record API.
Measure Measure
Value float64
ScopeID ScopeID
}
func (m Measurement) With(id ScopeID) Measurement {

73
api/core/span_context.go Normal file
View File

@ -0,0 +1,73 @@
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package core
import (
"fmt"
)
type EventID uint64
type TraceID struct {
IDHigh uint64
IDLow uint64
}
type SpanContext struct {
TraceID
SpanID uint64
}
type ScopeID struct {
EventID
SpanContext
}
func (e EventID) Scope() ScopeID {
return ScopeID{
EventID: e,
}
}
var (
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
// conditions.
INVALID_SPAN_CONTEXT = SpanContext{}
)
func (sc SpanContext) HasTraceID() bool {
return sc.TraceIDHigh != 0 || sc.TraceIDLow != 0
}
func (sc SpanContext) HasSpanID() bool {
return sc.SpanID != 0
}
func (sc SpanContext) SpanIDString() string {
p := fmt.Sprintf("%.16x", sc.SpanID)
return p[0:3] + ".." + p[13:16]
}
func (sc SpanContext) TraceIDString() string {
p1 := fmt.Sprintf("%.16x", sc.TraceIDHigh)
p2 := fmt.Sprintf("%.16x", sc.TraceIDLow)
return p1[0:3] + ".." + p2[13:16]
}
func (s SpanContext) Scope() ScopeID {
return ScopeID{
SpanContext: s,
}
}