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

First design for OpenTelemtry #82

Merged
merged 2 commits into from
Feb 13, 2024
Merged

First design for OpenTelemtry #82

merged 2 commits into from
Feb 13, 2024

Conversation

youben11
Copy link
Member

@youben11 youben11 commented Feb 12, 2024

  • We extend the EVMEnvironment with a method to get the EVM context using in Otel (returning nil means it's disabled)
  • As ops are executed sequentially in the EVM, we create a span per op based on the fetched context from the EVM implementation
  • The fetched context is considered the root context, and if a span was already created, then all spans created here will be child spans to that one

This is an initial design that doesn't have to make a lot of changes to the codebase, we can extend it later with more events that are needed for observability.

Note: This is a breaking change as it introduce a new method to the EVMEnvironment interface. We should update the docs to take this into account and explain how someone could use Otel with fhevm-go.

Copy link
Collaborator

@david-zk david-zk left a comment

Choose a reason for hiding this comment

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

Looks good, left comment about possible improvements in the future

@@ -176,19 +177,37 @@ func FheLibRun(environment EVMEnvironment, caller common.Address, addr common.Ad
logger.Error("fheLib precompile error", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelCtx := environment.OtelContext()
tracer := otel.Tracer("fhevm")
// first 4 bytes are for the function signature
signature := binary.BigEndian.Uint32(input[0:4])
switch signature {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm the author of the initial switch statement (looked good idea at the time for me) and maybe in the future we can replace this with a map of small abstraction, like structs of all the fhevm functions which contain, say

type fhevmPrecompileMethod {
  name string
  implementation <function signature which implements current switch block>
}

And have a generated map of these for first 4 bytes of method signature

map[[]byte]fhevmPrecompileMethod

Then we could just do one lookup to the map, and do one trace using name of the method not to repeat ourselves.

Also, in future bwCompatBytes logic could be just moved inside implementation method, say fheAddRun.
This was needed before when we supported separate precompile smart contracts instead of one, we no longer need that now

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this seems a nice refactor, I will do that just after we merge this (probably today)

@youben11 youben11 merged commit 144ba98 into main Feb 13, 2024
2 checks passed
@youben11 youben11 deleted the feature/tracing branch February 13, 2024 14:34
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