Skip to content

Conversation

@technicallyty
Copy link
Contributor

@technicallyty technicallyty commented Nov 26, 2025

Description

adds otel tracers to the RPC package.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

@technicallyty technicallyty changed the title feat: open telemetry feat(rpc): add OpenTelemetry tracing Nov 27, 2025
Copy link
Member

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

Big! Left comments


import "go.opentelemetry.io/otel"

var tracer = otel.Tracer("evm/rpc/backend")
Copy link
Member

Choose a reason for hiding this comment

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

let's drop this file and move this to backend.go

func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (hexutil.Bytes, error) {
blockNum, err := b.BlockNumberFromComet(blockNrOrHash)
func (b *Backend) GetCode(ctx context.Context, address common.Address, blockNrOrHash rpctypes.BlockNumberOrHash) (bz hexutil.Bytes, err error) {
ctx, span := tracer.Start(ctx, "GetCode", trace.WithAttributes(attribute.String("address", address.String()), attribute.String("blockNorHash", unwrapBlockNOrHash(blockNrOrHash))))
Copy link
Member

@swift1337 swift1337 Nov 28, 2025

Choose a reason for hiding this comment

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

I see a lot of repeated code that can be simplified with a small wrapper. Consider the following:

Creating span for existing ctx:

// wrapper would be located here:
// import https://github.com/cosmos/evm/trace

// func Start(ctx context.Context, name string, attr... Attribute)
//   trace.Str supports string or Stringable
//   trace.Block automatically parses block or hash
//   ... other cosmos/evm specific attrs

ctx, span := trace.Start(ctx, "GetCode", trace.Str("address", address), trace.Block("block", blockNrOrHash))

// regular span end
defer span.End()

//  captures err if not nil
defer span.EndErr(err)

Copy link
Member

@swift1337 swift1337 Nov 28, 2025

Choose a reason for hiding this comment

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

Creating span for new ctx:

ctx, span := trace.StartNew("GetCode", attrs...)
defer span.End()

"github.com/cosmos/cosmos-sdk/server"
)

var tracer = otel.Tracer("evm/rpc/namespaces/ethereum/debug")
Copy link
Member

Choose a reason for hiding this comment

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

same approach:

// import github.com/cosmos/evm/trace
var tracer = trace.New("evm/rpc/namespaces/ethereum/debug")

@swift1337
Copy link
Member

Curious, where do we configure tracing sampling rate here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants