Skip to content

Commit

Permalink
split core.go (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored and rghetia committed Jul 1, 2019
1 parent 56fe193 commit dc4a44c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 56 deletions.
62 changes: 6 additions & 56 deletions api/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
73 changes: 73 additions & 0 deletions api/core/span_context.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit dc4a44c

Please sign in to comment.