Skip to content

add emitMetric global fn#231

Merged
karen-stepanyan merged 4 commits into
capabilities-developmentfrom
DF-23782
Apr 30, 2026
Merged

add emitMetric global fn#231
karen-stepanyan merged 4 commits into
capabilities-developmentfrom
DF-23782

Conversation

@karen-stepanyan
Copy link
Copy Markdown

@karen-stepanyan karen-stepanyan commented Apr 13, 2026

https://smartcontract-it.atlassian.net/browse/DF-23782

Add emitMetric host function and runtime.emitMetric(...) SDK API
Javy plugin

  • Declared env::emit_metric import and registered a global emitMetric(bytes) -> i32 via extend_wasm_exports in lib.rs.
  • Rebuilt the deterministic plugin WASM (dist/javy-chainlink-sdk.plugin.wasm).

TypeScript SDK

  • Generated TS types for workflows.v2.WorkflowUserMetric by adding the proto to buf.gen.yaml.
  • Added emitMetric to the host-bindings Zod schema and to globalThis type declarations.
  • Added emitMetric(payload: Uint8Array): boolean to the internal RuntimeHelpers interface and implemented it for both the WASM runtime (hostBindings.emitMetric) and the test runtime (captures payloads on TestWriter).
  • Exposed a public API on BaseRuntime: runtime.emitMetric(name, value, 'counter' | 'gauge', labels?)

@karen-stepanyan karen-stepanyan changed the base branch from main to capabilities-development April 20, 2026 09:02
@karen-stepanyan karen-stepanyan changed the base branch from capabilities-development to main April 23, 2026 09:50
@karen-stepanyan karen-stepanyan changed the base branch from main to capabilities-development April 23, 2026 12:56
@karen-stepanyan karen-stepanyan marked this pull request as ready for review April 23, 2026 12:56
@karen-stepanyan karen-stepanyan requested review from a team as code owners April 23, 2026 12:56
@karen-stepanyan karen-stepanyan changed the base branch from capabilities-development to main April 28, 2026 09:33
@karen-stepanyan karen-stepanyan changed the base branch from main to capabilities-development April 28, 2026 09:34
}

emitMetric(payload: Uint8Array): boolean {
return hostBindings.emitMetric(payload) >= 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to instead have the host return an error message we can throw? The magnitude of the negative number usually indicates how long that message is.

That said, metrics are usually async. When do we expect this to return false? Should we instead just make it void?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the host returns negative on validation or rate limit errors
https://github.com/smartcontractkit/chainlink-common/blob/b1fd6cbfea8000121d85902f59fff4bfe0cef26f/pkg/workflows/wasm/host/execution.go#L188
and since all the errors are -1 I just converted this to boolean

@karen-stepanyan karen-stepanyan merged commit eed181d into capabilities-development Apr 30, 2026
3 checks passed
@karen-stepanyan karen-stepanyan deleted the DF-23782 branch April 30, 2026 08:43
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.

2 participants