Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to OpenTelemetry tracing library #1824

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.cap
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
github.com/onflow/cadence ()

github.com/davecgh/go-spew/spew (file)
github.com/onflow/cadence/runtime/interpreter ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess no entry is equivalent to ()? @fxamacker do you maybe know?

github.com/onflow/cadence/runtime/parser (file)
github.com/onflow/cadence/runtime/pretty (runtime)
github.com/opentracing/opentracing-go (network)
github.com/stretchr/testify/assert (runtime, file, network)
github.com/zeebo/blake3/internal/consts (file)
github.com/klauspost/cpuid/v2 (runtime, file)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ require (
github.com/leanovate/gopter v0.2.9
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
github.com/onflow/atree v0.4.0
github.com/opentracing/opentracing-go v1.2.0
github.com/rivo/uniseg v0.2.1-0.20211004051800-57c86be7915a
github.com/schollz/progressbar/v3 v3.8.3
github.com/stretchr/testify v1.7.3
github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d
go.opentelemetry.io/otel v1.8.0
go.uber.org/goleak v1.1.10
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/text v0.3.7
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ek
github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.14 h1:QRqdp6bb9M9S5yyKeYteXKuoKE4p0tGlra81fKOpWH8=
Expand Down Expand Up @@ -46,8 +47,6 @@ github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2Em
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/onflow/atree v0.4.0 h1:+TbNisavAkukAKhgQ4plWnvR9o5+SkwPIsi3jaeAqKs=
github.com/onflow/atree v0.4.0/go.mod h1:7Qe1xaW0YewvouLXrugzMFUYXNoRQ8MT/UsVAWx1Ndo=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -75,6 +74,8 @@ github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
go.opentelemetry.io/otel v1.8.0 h1:zcvBFizPbpa1q7FehvFiHbQwGzmPILebO0tyqIR5Djg=
go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
7 changes: 3 additions & 4 deletions runtime/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ package runtime
import (
"time"

opentracing "github.com/opentracing/opentracing-go"

"github.com/onflow/atree"
"go.opentelemetry.io/otel/attribute"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime/common"
Expand Down Expand Up @@ -137,8 +136,8 @@ type Interface interface {
ValidatePublicKey(key *PublicKey) error
// GetAccountContractNames returns the names of all contracts deployed in an account.
GetAccountContractNames(address Address) ([]string, error)
// RecordTrace records a opentracing trace
RecordTrace(operation string, location common.Location, duration time.Duration, logs []opentracing.LogRecord)
// RecordTrace records a opentelemetry trace.
RecordTrace(operation string, location common.Location, duration time.Duration, attrs []attribute.KeyValue)
// BLSVerifyPOP verifies a proof of possession (PoP) for the receiver public key.
BLSVerifyPOP(pk *PublicKey, s []byte) (bool, error)
// BLSAggregateSignatures aggregate multiple BLS signatures into one.
Expand Down
4 changes: 2 additions & 2 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/fxamacker/cbor/v2"
"github.com/onflow/atree"
"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel/attribute"

"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
Expand Down Expand Up @@ -121,7 +121,7 @@ type OnRecordTraceFunc func(
inter *Interpreter,
operationName string,
duration time.Duration,
logs []opentracing.LogRecord,
attrs []attribute.KeyValue,
)

// OnResourceOwnerChangeFunc is a function that is triggered when a resource's owner changes.
Expand Down
73 changes: 31 additions & 42 deletions runtime/interpreter/interpreter_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ package interpreter
import (
"time"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
"go.opentelemetry.io/otel/attribute"
)

const (
Expand Down Expand Up @@ -56,103 +55,93 @@ func (interpreter *Interpreter) reportImportTrace(importPath string, duration ti
interpreter.onRecordTrace(interpreter, tracingImportPrefix+importPath, duration, nil)
}

func prepareArrayAndMapValueTraceLogs(typeInfo string, count int) []opentracing.LogRecord {
return []opentracing.LogRecord{
{
Timestamp: time.Now(),
Fields: []log.Field{
log.Int("count", count),
log.String("type", typeInfo),
},
},
func prepareArrayAndMapValueTraceAttrs(typeInfo string, count int) []attribute.KeyValue {
return []attribute.KeyValue{
attribute.Int("count", count),
attribute.String("type", typeInfo),
}
}

func (interpreter *Interpreter) reportArrayValueConstructTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingConstructPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingConstructPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportArrayValueDeepRemoveTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingDeepRemovePostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingDeepRemovePostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportArrayValueDestroyTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingDestroyPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingDestroyPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportArrayValueTransferTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingTransferPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingTransferPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportArrayValueConformsToStaticTypeTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingConformsToStaticTypePostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingArrayPrefix+tracingConformsToStaticTypePostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueConstructTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingConstructPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingConstructPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueDeepRemoveTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingDeepRemovePostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingDeepRemovePostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueDestroyTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingDestroyPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingDestroyPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueTransferTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingTransferPostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingTransferPostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueConformsToStaticTypeTrace(typeInfo string, count int, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingConformsToStaticTypePostfix, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingConformsToStaticTypePostfix, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func (interpreter *Interpreter) reportDictionaryValueGetMemberTrace(typeInfo string, count int, name string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingGetMemberPrefix+name, duration, prepareArrayAndMapValueTraceLogs(typeInfo, count))
}

func prepareCompositeValueTraceLogs(owner, typeID, kind string) []opentracing.LogRecord {
return []opentracing.LogRecord{
{
Timestamp: time.Now(),
Fields: []log.Field{
log.String("owner", owner),
log.String("typeID", typeID),
log.String("kind", kind),
},
},
interpreter.onRecordTrace(interpreter, tracingDictionaryPrefix+tracingGetMemberPrefix+name, duration, prepareArrayAndMapValueTraceAttrs(typeInfo, count))
}

func prepareCompositeValueTraceAttrs(owner, typeID, kind string) []attribute.KeyValue {
return []attribute.KeyValue{
attribute.String("owner", owner),
attribute.String("typeID", typeID),
attribute.String("kind", kind),
}
}

func (interpreter *Interpreter) reportCompositeValueConstructTrace(owner, typeID, kind string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingConstructPostfix, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingConstructPostfix, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueDeepRemoveTrace(owner, typeID, kind string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingDeepRemovePostfix, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingDeepRemovePostfix, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueDestroyTrace(owner, typeID, kind string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingDestroyPostfix, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingDestroyPostfix, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueTransferTrace(owner, typeID, kind string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingTransferPostfix, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingTransferPostfix, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueConformsToStaticTypeTrace(owner, typeID, kind string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingConformsToStaticTypePostfix, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingConformsToStaticTypePostfix, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueGetMemberTrace(owner, typeID, kind, name string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingGetMemberPrefix+name, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingGetMemberPrefix+name, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueSetMemberTrace(owner, typeID, kind, name string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingSetMemberPrefix+name, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingSetMemberPrefix+name, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}

func (interpreter *Interpreter) reportCompositeValueRemoveMemberTrace(owner, typeID, kind, name string, duration time.Duration) {
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingRemoveMemberPrefix+name, duration, prepareCompositeValueTraceLogs(owner, typeID, kind))
interpreter.onRecordTrace(interpreter, tracingCompositePrefix+tracingRemoveMemberPrefix+name, duration, prepareCompositeValueTraceAttrs(owner, typeID, kind))
}
4 changes: 2 additions & 2 deletions runtime/interpreter/interpreter_tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"testing"
"time"

"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
Expand All @@ -43,7 +43,7 @@ func setupInterpreterWithTracingCallBack(
func(inter *interpreter.Interpreter,
operationName string,
duration time.Duration,
logs []opentracing.LogRecord) {
attrs []attribute.KeyValue) {
tracingCallback(operationName)
},
),
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"
"unsafe"

opentracing "github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/crypto/sha3"

"github.com/onflow/cadence"
Expand Down Expand Up @@ -1434,9 +1434,9 @@ func (r *interpreterRuntime) newInterpreter(
interpreter *interpreter.Interpreter,
functionName string,
duration time.Duration,
logs []opentracing.LogRecord,
attrs []attribute.KeyValue,
) {
context.Interface.RecordTrace(functionName, interpreter.Location, duration, logs)
context.Interface.RecordTrace(functionName, interpreter.Location, duration, attrs)
},
),
interpreter.WithTracingEnabled(r.tracingEnabled),
Expand Down
8 changes: 4 additions & 4 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"time"

"github.com/onflow/atree"
"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel/attribute"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -186,7 +186,7 @@ type testRuntimeInterface struct {
blsAggregateSignatures func(sigs [][]byte) ([]byte, error)
blsAggregatePublicKeys func(keys []*PublicKey) (*PublicKey, error)
getAccountContractNames func(address Address) ([]string, error)
recordTrace func(operation string, location common.Location, duration time.Duration, logs []opentracing.LogRecord)
recordTrace func(operation string, location common.Location, duration time.Duration, attrs []attribute.KeyValue)
meterMemory func(usage common.MemoryUsage) error
}

Expand Down Expand Up @@ -539,11 +539,11 @@ func (i *testRuntimeInterface) GetAccountContractNames(address Address) ([]strin
return i.getAccountContractNames(address)
}

func (i *testRuntimeInterface) RecordTrace(operation string, location common.Location, duration time.Duration, logs []opentracing.LogRecord) {
func (i *testRuntimeInterface) RecordTrace(operation string, location common.Location, duration time.Duration, attrs []attribute.KeyValue) {
if i.recordTrace == nil {
return
}
i.recordTrace(operation, location, duration, logs)
i.recordTrace(operation, location, duration, attrs)
}

func (i *testRuntimeInterface) MeterMemory(usage common.MemoryUsage) error {
Expand Down
4 changes: 2 additions & 2 deletions runtime/tests/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"time"

"github.com/onflow/atree"
"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"

"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
Expand Down Expand Up @@ -138,7 +138,7 @@ func parseCheckAndInterpretWithOptionsAndMemoryMetering(
_ *interpreter.Interpreter,
_ string,
_ time.Duration,
_ []opentracing.LogRecord,
_ []attribute.KeyValue,
) {
// NO-OP
},
Expand Down