Skip to content

Commit dc4a44c

Browse files
thinkerourghetia
authored andcommitted
split core.go (#39)
1 parent 56fe193 commit dc4a44c

File tree

2 files changed

+79
-56
lines changed

2 files changed

+79
-56
lines changed

api/core/core.go

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ import (
2323
"github.com/open-telemetry/opentelemetry-go/api/unit"
2424
)
2525

26-
type ScopeID struct {
27-
EventID
28-
SpanContext
29-
}
30-
31-
type SpanContext struct {
32-
TraceIDHigh uint64
33-
TraceIDLow uint64
34-
SpanID uint64
35-
}
36-
37-
type EventID uint64
38-
3926
type BaseMeasure interface {
4027
Name() string
4128
Description() string
@@ -51,14 +38,6 @@ type Measure interface {
5138
V(float64) KeyValue
5239
}
5340

54-
type Measurement struct {
55-
// NOTE: If we add a ScopeID field this can carry
56-
// pre-aggregated measures via the stats.Record API.
57-
Measure Measure
58-
Value float64
59-
ScopeID ScopeID
60-
}
61-
6241
type Key interface {
6342
BaseMeasure
6443

@@ -132,31 +111,6 @@ const (
132111
DELETE
133112
)
134113

135-
var (
136-
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
137-
// conditions.
138-
INVALID_SPAN_CONTEXT = SpanContext{}
139-
)
140-
141-
func (sc SpanContext) HasTraceID() bool {
142-
return sc.TraceIDHigh != 0 || sc.TraceIDLow != 0
143-
}
144-
145-
func (sc SpanContext) HasSpanID() bool {
146-
return sc.SpanID != 0
147-
}
148-
149-
func (sc SpanContext) SpanIDString() string {
150-
p := fmt.Sprintf("%.16x", sc.SpanID)
151-
return p[0:3] + ".." + p[13:16]
152-
}
153-
154-
func (sc SpanContext) TraceIDString() string {
155-
p1 := fmt.Sprintf("%.16x", sc.TraceIDHigh)
156-
p2 := fmt.Sprintf("%.16x", sc.TraceIDLow)
157-
return p1[0:3] + ".." + p2[13:16]
158-
}
159-
160114
// TODO make this a lazy one-time conversion.
161115
func (v Value) Emit() string {
162116
switch v.Type {
@@ -181,16 +135,12 @@ func (m Mutator) WithMaxHops(hops int) Mutator {
181135
return m
182136
}
183137

184-
func (e EventID) Scope() ScopeID {
185-
return ScopeID{
186-
EventID: e,
187-
}
188-
}
189-
190-
func (s SpanContext) Scope() ScopeID {
191-
return ScopeID{
192-
SpanContext: s,
193-
}
138+
type Measurement struct {
139+
// NOTE: If we add a ScopeID field this can carry
140+
// pre-aggregated measures via the stats.Record API.
141+
Measure Measure
142+
Value float64
143+
ScopeID ScopeID
194144
}
195145

196146
func (m Measurement) With(id ScopeID) Measurement {

api/core/span_context.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package core
16+
17+
import (
18+
"fmt"
19+
)
20+
21+
type EventID uint64
22+
23+
type TraceID struct {
24+
IDHigh uint64
25+
IDLow uint64
26+
}
27+
28+
type SpanContext struct {
29+
TraceID
30+
SpanID uint64
31+
}
32+
33+
type ScopeID struct {
34+
EventID
35+
SpanContext
36+
}
37+
38+
func (e EventID) Scope() ScopeID {
39+
return ScopeID{
40+
EventID: e,
41+
}
42+
}
43+
44+
var (
45+
// INVALID_SPAN_CONTEXT is meant for internal use to return invalid span context during error
46+
// conditions.
47+
INVALID_SPAN_CONTEXT = SpanContext{}
48+
)
49+
50+
func (sc SpanContext) HasTraceID() bool {
51+
return sc.TraceIDHigh != 0 || sc.TraceIDLow != 0
52+
}
53+
54+
func (sc SpanContext) HasSpanID() bool {
55+
return sc.SpanID != 0
56+
}
57+
58+
func (sc SpanContext) SpanIDString() string {
59+
p := fmt.Sprintf("%.16x", sc.SpanID)
60+
return p[0:3] + ".." + p[13:16]
61+
}
62+
63+
func (sc SpanContext) TraceIDString() string {
64+
p1 := fmt.Sprintf("%.16x", sc.TraceIDHigh)
65+
p2 := fmt.Sprintf("%.16x", sc.TraceIDLow)
66+
return p1[0:3] + ".." + p2[13:16]
67+
}
68+
69+
func (s SpanContext) Scope() ScopeID {
70+
return ScopeID{
71+
SpanContext: s,
72+
}
73+
}

0 commit comments

Comments
 (0)